You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@iotdb.apache.org by "Jialin Qiao (Jira)" <ji...@apache.org> on 2020/04/01 12:28:00 UTC
[jira] [Commented] (IOTDB-573) Construct AbstractIoTDBThread and
catch all Exception
[ https://issues.apache.org/jira/browse/IOTDB-573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17072719#comment-17072719 ]
Jialin Qiao commented on IOTDB-573:
-----------------------------------
For example, In StorageEngine
List<StorageGroupMNode> sgNodes = MManager.getInstance().getAllStorageGroupNodes();
List<Future> futures = new ArrayList<>();
for (StorageGroupMNode storageGroup : sgNodes) {
futures.add(recoveryThreadPool.submit((Callable<Void>) () -> {
StorageGroupProcessor processor = new StorageGroupProcessor(systemDir,
storageGroup.getFullPath(), fileFlushPolicy);
processor.setDataTTL(storageGroup.getDataTTL());
processorMap.put(storageGroup.getFullPath(), processor);
logger.info("Storage Group Processor {} is recovered successfully",
storageGroup.getFullPath());
return null;
}));
}
for (Future future : futures) {
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
throw new StorageEngineFailureException("StorageEngine failed to recover.", e);
}
}
We will get a NullPointerException without knowing the stack information if the constructor StorageGroupProcessor throws a NullPointerException.
> Construct AbstractIoTDBThread and catch all Exception
> ------------------------------------------------------
>
> Key: IOTDB-573
> URL: https://issues.apache.org/jira/browse/IOTDB-573
> Project: Apache IoTDB
> Issue Type: Improvement
> Components: Core/Engine
> Reporter: Jialin Qiao
> Priority: Major
>
> Hi, in current IoTDB codes, threads are created without any constraints. RuntimeExceptions are not caught in the run method. Therefore, we usually miss the stack information and only get a NullPointerException in the parent thread.
>
> Therefore, we need a base thread AbstractIoTDBThread that manages all threads. In the IoTDBThead, all exceptions are caught and logged. Here is an example.
>
> import java.util.concurrent.Callable;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
> public abstract class AbstractIoTDBThread<T> implements Callable<T> {
> protected Logger logger = null;
> public AbstractIoTDBThread() {
> initLogger();
> }
> @Override
> public T call() throws Exception {
> try {
> return internalRun();
> } catch (Exception e) {
> logger.error("Meet error in sub thread", e);
> throw e;
> }
> }
> abstract void initLogger();
> abstract T internalRun();
> }
> class MyThread extends AbstractIoTDBThread<Long> {
> @Override
> void initLogger() {
> logger = LoggerFactory.getLogger(MyThread.class);
> }
> @Override
> Long internalRun() {
> return 0L;
> }
> }
>
> This issue contains two tasks:
> (1) Create and enrich AbstractIoTDBThread
> (2) Make all threads in IoTDB to extend AbstractIoTDBThread.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)