Skip to content

Commit a18c780

Browse files
authored
Fix the status code of fetching schema when memory is not enough
1 parent c030c64 commit a18c780

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/schema/SchemaFetchScanOperator.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,17 @@ private void prepareSchemaNodeIteratorForSerialize() {
222222
schemaNodeIteratorForSerialize = schemaTree.getIteratorForSerialize();
223223
baos = new PublicBAOS(DEFAULT_MAX_TSBLOCK_SIZE_IN_BYTES + EXTRA_SIZE_TO_AVOID_GROW);
224224
if (operatorContext != null) {
225-
schemaTreeMemCost = schemaTree.ramBytesUsed();
225+
long ramBytesUsed = schemaTree.ramBytesUsed();
226226
operatorContext
227227
.getInstanceContext()
228228
.getMemoryReservationContext()
229-
.reserveMemoryCumulatively(schemaTreeMemCost);
229+
.reserveMemoryCumulatively(ramBytesUsed);
230+
// For temporary and independently counted memory, we need process it immediately
231+
operatorContext
232+
.getInstanceContext()
233+
.getMemoryReservationContext()
234+
.reserveMemoryImmediately();
235+
this.schemaTreeMemCost = ramBytesUsed;
230236
}
231237
} catch (MetadataException e) {
232238
throw new SchemaExecutionException(e);

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analyzer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ public Analysis analyze(Statement statement) {
4545
long startTime = System.nanoTime();
4646
AnalyzeVisitor visitor = new AnalyzeVisitor(partitionFetcher, schemaFetcher);
4747
Analysis analysis = null;
48-
context.setReserveMemoryForSchemaTreeFunc(context::reserveMemoryForFrontEnd);
48+
context.setReserveMemoryForSchemaTreeFunc(
49+
mem -> {
50+
context.reserveMemoryForFrontEnd(mem);
51+
// For temporary and independently counted memory, we need process it immediately
52+
context.reserveMemoryForFrontEndImmediately();
53+
});
4954
try {
5055
analysis = visitor.process(statement, context);
5156
} finally {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/ClusterSchemaFetchExecutor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.iotdb.db.protocol.session.SessionManager;
3232
import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
3333
import org.apache.iotdb.db.queryengine.common.schematree.ClusterSchemaTree;
34+
import org.apache.iotdb.db.queryengine.exception.MemoryNotEnoughException;
3435
import org.apache.iotdb.db.queryengine.plan.Coordinator;
3536
import org.apache.iotdb.db.queryengine.plan.analyze.ClusterPartitionFetcher;
3637
import org.apache.iotdb.db.queryengine.plan.execution.ExecutionResult;
@@ -326,6 +327,8 @@ private void parseFetchedData(
326327
throw new RuntimeException(
327328
new MetadataException("Failed to fetch schema because of unrecognized data"));
328329
}
330+
} catch (MemoryNotEnoughException e) {
331+
throw e;
329332
} catch (Exception e) {
330333
throw new RuntimeException(e);
331334
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ErrorHandlingUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ private static TSStatus tryCatchQueryException(Exception e) {
163163
TSStatusCode.QUERY_NOT_ALLOWED, INFO_NOT_ALLOWED_IN_BATCH_ERROR + rootCause.getMessage());
164164
} else if (t instanceof RootFIPlacementException
165165
|| t instanceof ReplicaSetUnreachableException
166-
|| t instanceof QuerySchemaFetchFailedException) {
166+
|| (t instanceof QuerySchemaFetchFailedException
167+
&& ((QuerySchemaFetchFailedException) t).getErrorCode()
168+
!= TSStatusCode.QUERY_EXECUTION_MEMORY_NOT_ENOUGH.getStatusCode())) {
167169
return RpcUtils.getStatus(TSStatusCode.PLAN_FAILED_NETWORK_PARTITION, rootCause.getMessage());
168170
} else if (t instanceof IoTDBException) {
169171
return Objects.nonNull(((IoTDBException) t).getStatus())

0 commit comments

Comments
 (0)