You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by li...@apache.org on 2019/11/21 11:00:37 UTC
[incubator-iotdb] 01/03: fix(*): update AtomicLong when StatMonitor
is enabled
This is an automated email from the ASF dual-hosted git repository.
liurui pushed a commit to branch monitor
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 5ff75da3e0d5605da070e5b72c482a6f83a72941
Author: liuruiyiyang <24...@qq.com>
AuthorDate: Thu Nov 21 13:05:28 2019 +0800
fix(*): update AtomicLong when StatMonitor is enabled
---
.../org/apache/iotdb/db/engine/StorageEngine.java | 26 ++++++++++++++-----
.../iotdb/db/monitor/collector/FileSize.java | 2 +-
.../org/apache/iotdb/db/service/TSServiceImpl.java | 30 +++++++++++++---------
3 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
index 62074bd..6600d4d 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
@@ -244,15 +244,15 @@ public class StorageEngine implements IService, IStatistic {
} catch (StorageEngineException e) {
logger.warn("get StorageGroupProcessor of device {} failed, because {}",
insertPlan.getDeviceId(), e.getMessage(), e);
- failPoint.addAndGet(insertPlan.getMeasurements().length);
+ addFailPoint(insertPlan.getMeasurements().length);
throw new StorageEngineException(e);
}
try {
storageGroupProcessor.insert(insertPlan);
- okPoint.addAndGet(insertPlan.getMeasurements().length);
+ addOkPoint(insertPlan.getMeasurements().length);
} catch (QueryProcessException e) {
- failPoint.addAndGet(insertPlan.getMeasurements().length);
+ addFailPoint(insertPlan.getMeasurements().length);
throw new QueryProcessException(e);
}
}
@@ -272,16 +272,16 @@ public class StorageEngine implements IService, IStatistic {
logger.warn("get StorageGroupProcessor of device {} failed, because {}",
batchInsertPlan.getDeviceId(),
e.getMessage(), e);
- failPoint.addAndGet(pointsNumber);
+ addFailPoint(pointsNumber);
throw new StorageEngineException(e);
}
try {
Integer[] result = storageGroupProcessor.insertBatch(batchInsertPlan);
- okPoint.addAndGet(pointsNumber);
+ addOkPoint(pointsNumber);
return result;
} catch (QueryProcessException e) {
- failPoint.addAndGet(pointsNumber);
+ addFailPoint(pointsNumber);
throw new StorageEngineException(e);
}
}
@@ -509,9 +509,21 @@ public class StorageEngine implements IService, IStatistic {
okPoint.set(0);
failPoint.set(0);
Map<String, Object> statParamsMap = new HashMap<>();
- for (StorageEngineMetrics kind : MonitorConstants.StorageEngineMetrics.values()) {
+ for (StorageEngineMetrics kind: MonitorConstants.StorageEngineMetrics.values()) {
statParamsMap.put(kind.name(), new AtomicLong(fileSizeMap.get(kind)));
}
return statParamsMap;
}
+
+ private void addOkPoint(long count) {
+ if (config.isEnableStatMonitor()) {
+ okPoint.addAndGet(count);
+ }
+ }
+
+ private void addFailPoint(long count) {
+ if (config.isEnableStatMonitor()) {
+ failPoint.addAndGet(count);
+ }
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/monitor/collector/FileSize.java b/server/src/main/java/org/apache/iotdb/db/monitor/collector/FileSize.java
index c3f52f3..e57de4a 100644
--- a/server/src/main/java/org/apache/iotdb/db/monitor/collector/FileSize.java
+++ b/server/src/main/java/org/apache/iotdb/db/monitor/collector/FileSize.java
@@ -121,7 +121,7 @@ public class FileSize implements IStatistic {
*
* @return a map[FileSizeMetrics, Long] with the dir type and the dir size in byte
*/
- private Map<FileSizeMetrics, Long> getFileSizesInByte() {
+ Map<FileSizeMetrics, Long> getFileSizesInByte() {
EnumMap<FileSizeMetrics, Long> fileSizes = new EnumMap<>(FileSizeMetrics.class);
for (FileSizeMetrics kinds : FileSizeMetrics.values()) {
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 2478e15..2533e8c 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -539,7 +539,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
@Override
public TSExecuteBatchStatementResp executeBatchStatement(TSExecuteBatchStatementReq req) {
long t1 = System.currentTimeMillis();
- requestNum.incrementAndGet();
+ addRequestNum();
List<Integer> result = new ArrayList<>();
try {
if (!checkLogin()) {
@@ -612,7 +612,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
@Override
public TSExecuteStatementResp executeStatement(TSExecuteStatementReq req) {
long startTime = System.currentTimeMillis();
- requestNum.incrementAndGet();
+ addRequestNum();
TSExecuteStatementResp resp;
SqlArgument sqlArgument;
try {
@@ -703,7 +703,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
return getTSExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
String statement = req.getStatement();
PhysicalPlan physicalPlan;
try {
@@ -1013,7 +1013,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
return getTSExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
String statement = req.getStatement();
return executeUpdateStatement(statement);
} catch (Exception e) {
@@ -1169,7 +1169,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
return getTSExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
long stmtId = req.getStmtId();
InsertPlan plan = (InsertPlan) operationStatus.get()
.computeIfAbsent(stmtId, k -> new InsertPlan());
@@ -1204,7 +1204,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
return new TSStatus(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
InsertPlan plan = new InsertPlan();
plan.setDeviceId(req.getDeviceId());
plan.setTime(req.getTimestamp());
@@ -1225,7 +1225,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
return new TSStatus(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
DeletePlan plan = new DeletePlan();
plan.setDeleteTime(req.getTimestamp());
List<Path> paths = new ArrayList<>();
@@ -1250,7 +1250,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
return getTSBatchExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR), null);
}
- requestNum.incrementAndGet();
+ addRequestNum();
BatchInsertPlan batchInsertPlan = new BatchInsertPlan(req.deviceId, req.measurements);
batchInsertPlan.setTimes(QueryDataSetUtils.readTimesFromBuffer(req.timestamps, req.size));
batchInsertPlan.setColumns(QueryDataSetUtils
@@ -1299,7 +1299,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
return new TSStatus(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
SetStorageGroupPlan plan = new SetStorageGroupPlan(new Path(storageGroup));
TSStatus status = checkAuthority(plan);
if (status != null) {
@@ -1314,7 +1314,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
return new TSStatus(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
List<Path> storageGroupList = new ArrayList<>();
for (String storageGroup : storageGroups) {
storageGroupList.add(new Path(storageGroup));
@@ -1333,7 +1333,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
return new TSStatus(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
CreateTimeSeriesPlan plan = new CreateTimeSeriesPlan(new Path(req.getPath()),
TSDataType.values()[req.getDataType()], TSEncoding.values()[req.getEncoding()],
CompressionType.values()[req.compressor], new HashMap<>());
@@ -1350,7 +1350,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
return new TSStatus(getStatus(TSStatusCode.NOT_LOGIN_ERROR));
}
- requestNum.incrementAndGet();
+ addRequestNum();
List<Path> pathList = new ArrayList<>();
for (String path : paths) {
pathList.add(new Path(path));
@@ -1445,5 +1445,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext, IStatisti
queryIdGenerator.set(queryId + 1);
return queryId;
}
+
+ private void addRequestNum() {
+ if (config.isEnableStatMonitor()) {
+ requestNum.incrementAndGet();
+ }
+ }
}