diff --git a/warehouse/src/main/java/com/usthe/warehouse/store/HistoryIotDbDataStorage.java b/warehouse/src/main/java/com/usthe/warehouse/store/HistoryIotDbDataStorage.java index 9e0f04c197d..3035ab81da8 100644 --- a/warehouse/src/main/java/com/usthe/warehouse/store/HistoryIotDbDataStorage.java +++ b/warehouse/src/main/java/com/usthe/warehouse/store/HistoryIotDbDataStorage.java @@ -56,6 +56,8 @@ public class HistoryIotDbDataStorage extends AbstractHistoryDataStorage { private static final String SHOW_DEVICES = "SHOW DEVICES %s"; + private static final String SHOW_STORAGE_GROUP = "show storage group"; + private static final String QUERY_HISTORY_SQL = "SELECT %s FROM %s WHERE Time >= now() - %s order by Time desc"; private static final String QUERY_HISTORY_INTERVAL_WITH_INSTANCE_SQL @@ -63,8 +65,8 @@ public class HistoryIotDbDataStorage extends AbstractHistoryDataStorage { private SessionPool sessionPool; - // Session有这两个字段的set方法,sessionPool暂未发现,目前存储在此类中 /** + * Session有这两个字段的set方法,sessionPool暂未发现,目前存储在此类中 * version: ioTDb version *
用来区分不同版本的ioTDb
*/ @@ -104,9 +106,22 @@ private boolean initIotDbSession(WarehouseProperties.StoreProperties.IotDbProper } this.queryTimeoutInMs = properties.getQueryTimeoutInMs(); this.sessionPool = builder.build(); - this.initTtl(properties.getExpireTime()); - log.info("IotDB session pool init success"); - return true; + boolean available = checkConnection(); + if (available) { + this.initTtl(properties.getExpireTime()); + log.info("IotDB session pool init success"); + } + return available; + } + + private boolean checkConnection() { + try { + this.sessionPool.executeNonQueryStatement(SHOW_STORAGE_GROUP); + return true; + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } } private void initTtl(String expireTime) { @@ -124,7 +139,7 @@ private void initTtl(String expireTime) { } } catch (IoTDBConnectionException | StatementExecutionException e) { // 失败不影响主业务 - log.error("IoTDB init ttl error, expireTime: {}", expireTime); + log.error("IoTDB init ttl error, expireTime: {}, error: {}", expireTime, e.getMessage()); } } @@ -194,6 +209,9 @@ void saveData(CollectRep.MetricsData metricsData) { public Map