Skip to content

Commit f693475

Browse files
authored
Avoid NPE while stop DN (apache#15939)
1 parent e139623 commit f693475

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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
@@ -221,7 +221,7 @@ public void forceMlog() {
221221
}
222222
}
223223

224-
public void clear() {
224+
public synchronized void clear() {
225225
schemaRegionLoader.clear();
226226

227227
// clearSchemaResource will shut down release and flush task in PBTree mode, which must be
@@ -239,6 +239,7 @@ public void clear() {
239239
}
240240
schemaRegionMap.clear();
241241
schemaRegionMap = null;
242+
logger.info("clear schema region map.");
242243
}
243244
// SchemaMetric should be cleared lastly
244245
if (schemaMetricManager != null) {
@@ -261,7 +262,10 @@ public List<SchemaRegionId> getAllSchemaRegionIds() {
261262

262263
public synchronized void createSchemaRegion(
263264
final String storageGroup, final SchemaRegionId schemaRegionId) throws MetadataException {
264-
final ISchemaRegion schemaRegion = schemaRegionMap.get(schemaRegionId);
265+
if (this.schemaRegionMap == null) {
266+
throw new MetadataException("Peer is shutting down now.");
267+
}
268+
final ISchemaRegion schemaRegion = this.schemaRegionMap.get(schemaRegionId);
265269
if (schemaRegion != null) {
266270
if (schemaRegion.getDatabaseFullPath().equals(storageGroup)) {
267271
return;
@@ -273,7 +277,7 @@ public synchronized void createSchemaRegion(
273277
schemaRegionId, schemaRegion.getDatabaseFullPath(), storageGroup));
274278
}
275279
}
276-
schemaRegionMap.put(
280+
this.schemaRegionMap.put(
277281
schemaRegionId, createSchemaRegionWithoutExistenceCheck(storageGroup, schemaRegionId));
278282
}
279283

0 commit comments

Comments
 (0)