Skip to content

Commit 9493f7d

Browse files
authored
Enable tolerating any exceptions and not block cluster initialization during schema region recover
1 parent 16f71c8 commit 9493f7d

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
2323
import org.apache.iotdb.commons.consensus.SchemaRegionId;
24-
import org.apache.iotdb.commons.exception.IllegalPathException;
2524
import org.apache.iotdb.commons.exception.MetadataException;
2625
import org.apache.iotdb.commons.file.SystemFileFactory;
2726
import org.apache.iotdb.commons.path.MeasurementPath;
@@ -211,7 +210,8 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
211210
private DeviceAttributeCacheUpdater deviceAttributeCacheUpdater;
212211

213212
// region Interfaces and Implementation of initialization、snapshot、recover and clear
214-
public SchemaRegionMemoryImpl(ISchemaRegionParams schemaRegionParams) throws MetadataException {
213+
public SchemaRegionMemoryImpl(final ISchemaRegionParams schemaRegionParams)
214+
throws MetadataException {
215215

216216
storageGroupFullPath = schemaRegionParams.getDatabase().getFullPath();
217217
this.schemaRegionId = schemaRegionParams.getSchemaRegionId();
@@ -242,7 +242,7 @@ public synchronized void init() throws MetadataException {
242242
}
243243

244244
if (config.getSchemaRegionConsensusProtocolClass().equals(ConsensusFactory.RATIS_CONSENSUS)) {
245-
long memCost = config.getSchemaRatisConsensusLogAppenderBufferSizeMax();
245+
final long memCost = config.getSchemaRatisConsensusLogAppenderBufferSizeMax();
246246
if (!SystemInfo.getInstance().addDirectBufferMemoryCost(memCost)) {
247247
throw new MetadataException(
248248
"Total allocated memory for direct buffer will be "
@@ -281,7 +281,7 @@ public synchronized void init() throws MetadataException {
281281
}
282282

283283
isRecovering = false;
284-
} catch (IOException e) {
284+
} catch (final IOException e) {
285285
logger.error(
286286
"Cannot recover all schema info from {}, we try to recover as possible as we can",
287287
schemaRegionDirPath,
@@ -291,7 +291,7 @@ public synchronized void init() throws MetadataException {
291291
}
292292

293293
private void initDir() throws SchemaDirCreationFailureException {
294-
File sgSchemaFolder = SystemFileFactory.INSTANCE.getFile(storageGroupDirPath);
294+
final File sgSchemaFolder = SystemFileFactory.INSTANCE.getFile(storageGroupDirPath);
295295
if (!sgSchemaFolder.exists()) {
296296
if (sgSchemaFolder.mkdirs()) {
297297
logger.info("create database schema folder {}", storageGroupDirPath);
@@ -303,7 +303,7 @@ private void initDir() throws SchemaDirCreationFailureException {
303303
}
304304
}
305305

306-
File schemaRegionFolder = SystemFileFactory.INSTANCE.getFile(schemaRegionDirPath);
306+
final File schemaRegionFolder = SystemFileFactory.INSTANCE.getFile(schemaRegionDirPath);
307307
if (!schemaRegionFolder.exists()) {
308308
if (schemaRegionFolder.mkdirs()) {
309309
logger.info("create schema region folder {}", schemaRegionDirPath);
@@ -344,11 +344,11 @@ public void forceMlog() {
344344
}
345345
if (usingMLog) {
346346
try {
347-
SchemaLogWriter<ISchemaRegionPlan> logWriter = this.logWriter;
347+
final SchemaLogWriter<ISchemaRegionPlan> logWriter = this.logWriter;
348348
if (logWriter != null) {
349349
logWriter.force();
350350
}
351-
} catch (IOException e) {
351+
} catch (final IOException e) {
352352
logger.error("Cannot force {} mlog to the schema region", schemaRegionId, e);
353353
}
354354
}
@@ -371,14 +371,14 @@ public ISchemaRegionMetric getSchemaRegionMetric() {
371371
*/
372372
@SuppressWarnings("squid:S3776")
373373
private int initFromLog() throws IOException {
374-
File logFile =
374+
final File logFile =
375375
SystemFileFactory.INSTANCE.getFile(
376376
schemaRegionDirPath + File.separator + SchemaConstant.METADATA_LOG);
377377

378-
long time = System.currentTimeMillis();
378+
final long time = System.currentTimeMillis();
379379
// init the metadata from the operation log
380380
if (logFile.exists()) {
381-
int idx;
381+
final int idx;
382382
try (SchemaLogReader<ISchemaRegionPlan> mLogReader =
383383
new SchemaLogReader<>(
384384
schemaRegionDirPath,
@@ -390,7 +390,7 @@ private int initFromLog() throws IOException {
390390
System.currentTimeMillis() - time,
391391
storageGroupFullPath);
392392
return idx;
393-
} catch (Exception e) {
393+
} catch (final Exception e) {
394394
e.printStackTrace();
395395
throw new IOException("Failed to parse " + storageGroupFullPath + " mlog.bin for err:" + e);
396396
}
@@ -626,7 +626,7 @@ public void loadSnapshot(final File latestSnapshotRootDir) {
626626
schemaRegionId,
627627
System.currentTimeMillis() - startTime);
628628
logger.info("Successfully load snapshot of schemaRegion {}", schemaRegionId);
629-
} catch (final IOException | IllegalPathException e) {
629+
} catch (final Exception e) {
630630
logger.error(
631631
"Failed to load snapshot for schemaRegion {} due to {}. Use empty schemaRegion",
632632
schemaRegionId,
@@ -636,11 +636,9 @@ public void loadSnapshot(final File latestSnapshotRootDir) {
636636
initialized = false;
637637
isRecovering = true;
638638
init();
639-
} catch (final MetadataException metadataException) {
639+
} catch (final Exception exception) {
640640
logger.error(
641-
"Error occurred during initializing schemaRegion {}",
642-
schemaRegionId,
643-
metadataException);
641+
"Error occurred during initializing schemaRegion {}", schemaRegionId, exception);
644642
}
645643
}
646644
}

0 commit comments

Comments
 (0)