Skip to content

Commit a0f52f6

Browse files
authored
[To dev/1.3] Avoid NPE while stop DN (#15940)
1 parent 06a6aad commit a0f52f6

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void forceMlog() {
242242
}
243243
}
244244

245-
public void clear() {
245+
public synchronized void clear() {
246246
schemaRegionLoader.clear();
247247

248248
// clearSchemaResource will shut down release and flush task in PBTree mode, which must be
@@ -260,6 +260,7 @@ public void clear() {
260260
}
261261
schemaRegionMap.clear();
262262
schemaRegionMap = null;
263+
logger.info("clear schema region map.");
263264
}
264265
// SchemaMetric should be cleared lastly
265266
if (schemaMetricManager != null) {
@@ -282,7 +283,10 @@ public List<SchemaRegionId> getAllSchemaRegionIds() {
282283

283284
public synchronized void createSchemaRegion(
284285
PartialPath storageGroup, SchemaRegionId schemaRegionId) throws MetadataException {
285-
ISchemaRegion schemaRegion = schemaRegionMap.get(schemaRegionId);
286+
if (this.schemaRegionMap == null) {
287+
throw new MetadataException("Peer is shutting down now.");
288+
}
289+
final ISchemaRegion schemaRegion = this.schemaRegionMap.get(schemaRegionId);
286290
if (schemaRegion != null) {
287291
if (schemaRegion.getDatabaseFullPath().equals(storageGroup.getFullPath())) {
288292
return;
@@ -294,7 +298,7 @@ public synchronized void createSchemaRegion(
294298
schemaRegionId, schemaRegion.getDatabaseFullPath(), storageGroup.getFullPath()));
295299
}
296300
}
297-
schemaRegionMap.put(
301+
this.schemaRegionMap.put(
298302
schemaRegionId, createSchemaRegionWithoutExistenceCheck(storageGroup, schemaRegionId));
299303
}
300304

0 commit comments

Comments
 (0)