Skip to content

Commit 828ce59

Browse files
guojn1githubgxll
authored andcommitted
[fix][dingo-executor] Add data validation to the system view of information_schema
1 parent edcec6c commit 828ce59

File tree

12 files changed

+133
-57
lines changed

12 files changed

+133
-57
lines changed

dingo-calcite/src/main/java/io/dingodb/calcite/DingoDdlExecutor.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@
186186
import java.util.Objects;
187187
import java.util.Properties;
188188
import java.util.concurrent.atomic.AtomicInteger;
189-
import java.util.regex.Pattern;
190189
import java.util.stream.Collectors;
191190
import java.util.stream.IntStream;
192191

@@ -279,7 +278,15 @@ public void execute(SqlDropSchema schema, CalcitePrepare.Context context) {
279278
SchemaInfo schemaInfo = subSchema.getSchemaInfo(schemaName);
280279
schemaId = schemaInfo.getSchemaId();
281280
DdlService ddlService = DdlService.root();
282-
ddlService.dropSchema(schemaInfo, connId);
281+
try {
282+
ddlService.dropSchema(schemaInfo, connId);
283+
} catch (DingoSqlException e) {
284+
if (e.getSqlCode() == 1008 && schema.ifExists) {
285+
return;
286+
} else {
287+
throw e;
288+
}
289+
}
283290
} else {
284291
throw new RuntimeException("Schema not empty.");
285292
}
@@ -568,7 +575,8 @@ public void execute(SqlDropTable drop, CalcitePrepare.Context context) throws Ex
568575
if (schema == null) {
569576
return;
570577
}
571-
final String tableName = getTableName(drop.name);
578+
String tableName = getTableName(drop.name);
579+
tableName = convertName(tableName);
572580
SchemaInfo schemaInfo = schema.getSchemaInfo(schema.getSchemaName());
573581
if (schemaInfo == null) {
574582
throw DINGO_RESOURCE.unknownSchema(schema.getSchemaName()).ex();

dingo-calcite/src/main/java/io/dingodb/calcite/DingoParser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,10 @@ protected static boolean ddlTxn(SqlNode sqlNode) {
555555
}
556556

557557
public long getGcLifeTime() {
558-
if (DdlUtil.gcLifeTimeTso > 0) {
559-
return DdlUtil.gcLifeTimeTso;
558+
long globalSafePointTs = Long.parseLong(InfoSchemaService.root().getGlobalVariables()
559+
.getOrDefault("safepoint_ts", "0"));
560+
if (globalSafePointTs > 0) {
561+
return globalSafePointTs;
560562
} else {
561563
long currentTime = System.currentTimeMillis();
562564
String gcLifeTimeStr = InfoSchemaService.root().getGlobalVariables().get("txn_history_duration");

dingo-calcite/src/main/java/io/dingodb/calcite/visitor/DingoJobVisitor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public class DingoJobVisitor implements DingoRelVisitor<Collection<Vertex>> {
158158

159159
private DingoJobVisitor(Job job, IdGenerator idGenerator, Location currentLocation, ITransaction transaction,
160160
SqlKind kind, ExecuteVariables executeVariables, long pointTs, boolean forUpdate,
161-
boolean replaceInto, boolean isIgnore, long updateLimit) {
161+
boolean replaceInto, boolean isIgnore, long updateLimit, String user, String host) {
162162
this.job = job;
163163
this.idGenerator = idGenerator;
164164
this.currentLocation = currentLocation;
@@ -170,30 +170,34 @@ private DingoJobVisitor(Job job, IdGenerator idGenerator, Location currentLocati
170170
this.replaceInto = replaceInto;
171171
this.isIgnore = isIgnore;
172172
this.updateLimit = updateLimit;
173+
this.user = user;
174+
this.host = host;
173175
}
174176

175177
public static void renderJob(JobManager jobManager, Job job, RelNode input, Location currentLocation) {
178+
String user = "root";
179+
String host = "%";
176180
renderJob(jobManager, job, input, currentLocation, false, null, null,
177-
new ExecuteVariables());
181+
new ExecuteVariables(), user, host);
178182
}
179183

180184
public static void renderJob(JobManager jobManager, Job job, RelNode input, Location currentLocation,
181185
boolean checkRoot, ITransaction transaction, SqlKind kind,
182-
ExecuteVariables executeVariables) {
186+
ExecuteVariables executeVariables, String user, String host) {
183187
renderJob(jobManager, job, input, currentLocation, checkRoot, transaction, kind,
184-
executeVariables, 0, false, false, false, -1);
188+
executeVariables, 0, false, false, false, -1, user, host);
185189
}
186190

187191
public static void renderJob(JobManager jobManager, Job job, RelNode input, Location currentLocation,
188192
boolean checkRoot, ITransaction transaction, SqlKind kind,
189193
ExecuteVariables executeVariables, long pointTs, boolean forUpdate,
190-
boolean replaceInto, boolean isIgnore, long updateLimit) {
194+
boolean replaceInto, boolean isIgnore, long updateLimit, String user, String host) {
191195
try {
192196
IdGenerator idGenerator = new IdGeneratorImpl(job.getJobId().seq);
193197
DingoJobVisitor visitor = new DingoJobVisitor(
194198
job, idGenerator, currentLocation, transaction, kind,
195199
executeVariables, pointTs, forUpdate, replaceInto, isIgnore,
196-
updateLimit
200+
updateLimit, user, host
197201
);
198202
Collection<Vertex> outputs = dingo(input).accept(visitor);
199203
if (checkRoot && !outputs.isEmpty()) {

dingo-calcite/src/main/java/io/dingodb/calcite/visitor/function/DingoInfoSchemaScanVisitFun.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ public static List<Vertex> visit(
5858
} else {
5959
tableName = td.getName();
6060
}
61+
String user = visitor.getUser();
62+
String host = visitor.getHost();
6163
InfoSchemaScanParam param = new InfoSchemaScanParam(
6264
td.tupleType(),
6365
td.version,
6466
filter,
6567
rel.getSelection(),
66-
tableName
68+
tableName,
69+
user,
70+
host
6771
);
6872

6973
Task task = job.getOrCreate(currentLocation, idGenerator);

dingo-common/src/main/java/io/dingodb/common/metrics/DingoMetrics.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ protected Integer loadValue() {
105105
metricRegistry.register("activeSessionCount", new CachedGauge<Integer>(1, TimeUnit.MINUTES) {
106106
@Override
107107
protected Integer loadValue() {
108-
return SessionUtil.INSTANCE.getSessionPool().getNumActive();
108+
if (SessionUtil.INSTANCE.getSessionPool() != null) {
109+
return SessionUtil.INSTANCE.getSessionPool().getNumActive();
110+
} else {
111+
return 0;
112+
}
109113
}
110114
});
111115
metricRegistry.register("select-latency", new CachedGauge<Double>(5, TimeUnit.MINUTES) {

dingo-driver/host/src/main/java/io/dingodb/driver/DingoDriverParser.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public Meta.Signature parseQuery(
511511
if (pessimisticTxn && transaction.getPrimaryKeyLock() == null && explain == null) {
512512
runPessimisticPrimaryKeyJob(jobSeqId, jobManager, transaction, sqlNode, relNode,
513513
currentLocation, DefinitionMapper.mapToDingoType(parasType),
514-
new ExecuteVariables(isJoinConcurrency(), getConcurrencyLevel(), isInsertCheckInplace()));
514+
new ExecuteVariables(isJoinConcurrency(), getConcurrencyLevel(), isInsertCheckInplace()), user, host);
515515
jobSeqId = transaction.getForUpdateTs();
516516
}
517517
String maxExecutionTimeStr = connection.getClientInfo("max_execution_time");
@@ -534,7 +534,9 @@ public Meta.Signature parseQuery(
534534
forUpdate,
535535
getReplaceInto(sqlNode),
536536
getIgnore(sqlNode),
537-
getUpdateLimit(sqlNode)
537+
getUpdateLimit(sqlNode),
538+
user,
539+
host
538540
);
539541
if (explain != null) {
540542
statementType = Meta.StatementType.CALL;
@@ -766,7 +768,7 @@ public Meta.Signature retryQuery(
766768
LogUtils.info(log, "retryQuery startTs:{}", startTs);
767769
runPessimisticPrimaryKeyJob(jobSeqId, jobManager, transaction, sqlNode, relNode,
768770
currentLocation, DefinitionMapper.mapToDingoType(parasType),
769-
new ExecuteVariables(isJoinConcurrency(), getConcurrencyLevel(), isInsertCheckInplace()));
771+
new ExecuteVariables(isJoinConcurrency(), getConcurrencyLevel(), isInsertCheckInplace()), user, host);
770772
jobSeqId = transaction.getForUpdateTs();
771773
}
772774
String maxExecutionTimeStr = connection.getClientInfo("max_execution_time");
@@ -784,7 +786,8 @@ public Meta.Signature retryQuery(
784786
true,
785787
transaction.getType() == NONE ? null : connection.getTransaction(),
786788
sqlNode.getKind(),
787-
new ExecuteVariables(isJoinConcurrency(), getConcurrencyLevel(), isInsertCheckInplace())
789+
new ExecuteVariables(isJoinConcurrency(), getConcurrencyLevel(), isInsertCheckInplace()),
790+
user, host
788791
);
789792
return new DingoSignature(
790793
visitColumns,
@@ -811,7 +814,9 @@ private static void runPessimisticPrimaryKeyJob(
811814
RelNode relNode,
812815
Location currentLocation,
813816
DingoType dingoType,
814-
ExecuteVariables executeVariables
817+
ExecuteVariables executeVariables,
818+
String user,
819+
String host
815820
) {
816821
Integer retry = Optional.mapOrGet(DingoConfiguration.instance().find("retry", int.class), __ -> __, () -> 30);
817822
boolean forUpdate = forUpdate(sqlNode);
@@ -820,7 +825,7 @@ private static void runPessimisticPrimaryKeyJob(
820825
DingoJobVisitor.renderJob(
821826
jobManager, job, relNode, currentLocation, true,
822827
transaction, sqlNode.getKind(), executeVariables, 0,
823-
forUpdate, getReplaceInto(sqlNode), getIgnore(sqlNode), getUpdateLimit(sqlNode)
828+
forUpdate, getReplaceInto(sqlNode), getIgnore(sqlNode), getUpdateLimit(sqlNode), user, host
824829
);
825830
try {
826831
Iterator<Object[]> iterator = jobManager.createIterator(job, null);

0 commit comments

Comments
 (0)