This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch rel/0.10
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/rel/0.10 by this push:
new ac11f7d Add a config entry to switch on/off Last cache (#1776)
ac11f7d is described below
commit ac11f7dae6fc6e8612c47bd15497118edf9ef513
Author: wshao08 <[email protected]>
AuthorDate: Mon Sep 28 10:56:07 2020 +0800
Add a config entry to switch on/off Last cache (#1776)
---
.../resources/conf/iotdb-engine.properties | 7 +++++
.../java/org/apache/iotdb/db/conf/IoTDBConfig.java | 13 ++++++++++
.../org/apache/iotdb/db/conf/IoTDBDescriptor.java | 3 +++
.../engine/storagegroup/StorageGroupProcessor.java | 6 +++++
.../iotdb/db/query/executor/LastQueryExecutor.java | 30 +++++++++++++++-------
5 files changed, 50 insertions(+), 9 deletions(-)
diff --git a/server/src/assembly/resources/conf/iotdb-engine.properties
b/server/src/assembly/resources/conf/iotdb-engine.properties
index 89f99e0..a5d8e2c 100644
--- a/server/src/assembly/resources/conf/iotdb-engine.properties
+++ b/server/src/assembly/resources/conf/iotdb-engine.properties
@@ -302,6 +302,13 @@
chunkmeta_chunk_timeseriesmeta_free_memory_proportion=1:1:1:7
metadata_node_cache_size=300000
####################
+### LAST Cache Configuration
+####################
+
+# Whether to enable LAST cache
+enable_last_cache=true
+
+####################
### Statistics Monitor configuration
####################
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index b170bcc..2da037f 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -263,6 +263,11 @@ public class IoTDBConfig {
private long allocateMemoryForChunkCache = allocateMemoryForRead * 5 / 39;
/**
+ * Whether to enable Last cache
+ */
+ private boolean lastCacheEnable = true;
+
+ /**
* The statMonitor writes statistics info into IoTDB every backLoopPeriodSec
secs. The default
* value is 5s.
*/
@@ -1218,6 +1223,14 @@ public class IoTDBConfig {
this.allocateMemoryForChunkCache = allocateMemoryForChunkCache;
}
+ public boolean isLastCacheEnabled() {
+ return lastCacheEnable;
+ }
+
+ public void setEnableLastCache(boolean lastCacheEnable) {
+ this.lastCacheEnable = lastCacheEnable;
+ }
+
public boolean isEnableWatermark() {
return enableWatermark;
}
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
index 0cd7c0b..c5854ea 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
@@ -188,6 +188,9 @@ public class IoTDBDescriptor {
Boolean.parseBoolean(properties.getProperty("meta_data_cache_enable",
Boolean.toString(conf.isMetaDataCacheEnable()))));
+
conf.setEnableLastCache(Boolean.parseBoolean(properties.getProperty("enable_last_cache",
+ Boolean.toString(conf.isLastCacheEnabled()))));
+
initMemoryAllocate(properties);
loadWALProps(properties);
diff --git
a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
index 1f66ae2..70c9064 100755
---
a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
+++
b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
@@ -742,6 +742,9 @@ public class StorageGroupProcessor {
private void tryToUpdateBatchInsertLastCache(InsertTabletPlan plan, Long
latestFlushedTime)
throws WriteProcessException {
+ if (!IoTDBDescriptor.getInstance().getConfig().isLastCacheEnabled()) {
+ return;
+ }
MNode node = plan.getDeviceMNode();
String[] measurementList = plan.getMeasurements();
for (int i = 0; i < measurementList.length; i++) {
@@ -786,6 +789,9 @@ public class StorageGroupProcessor {
private void tryToUpdateInsertLastCache(InsertPlan plan, Long
latestFlushedTime)
throws WriteProcessException {
+ if (!IoTDBDescriptor.getInstance().getConfig().isLastCacheEnabled()) {
+ return;
+ }
MNode node = plan.getDeviceMNode();
String[] measurementList = plan.getMeasurements();
for (int i = 0; i < measurementList.length; i++) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
b/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
index 7b7fb08..d0add60 100644
---
a/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
+++
b/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
@@ -23,6 +23,7 @@ package org.apache.iotdb.db.query.executor;
import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE;
import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES;
import java.util.Set;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
import org.apache.iotdb.db.exception.StorageEngineException;
@@ -53,6 +54,8 @@ import java.util.List;
public class LastQueryExecutor {
private List<Path> selectedSeries;
private List<TSDataType> dataTypes;
+ private static boolean lastCacheEnabled =
+ IoTDBDescriptor.getInstance().getConfig().isLastCacheEnabled();
public LastQueryExecutor(LastQueryPlan lastQueryPlan) {
this.selectedSeries = lastQueryPlan.getDeduplicatedPaths();
@@ -112,16 +115,23 @@ public class LastQueryExecutor {
throws IOException, QueryProcessException, StorageEngineException {
// Retrieve last value from MNode
- LeafMNode node;
- try {
- node = (LeafMNode)
MManager.getInstance().getNodeByPath(seriesPath.toString());
- } catch (MetadataException e) {
- throw new QueryProcessException(e);
- }
- if (node.getCachedLast() != null) {
- return node.getCachedLast();
+ LeafMNode node = null;
+ if (lastCacheEnabled) {
+ try {
+ node = (LeafMNode)
MManager.getInstance().getNodeByPath(seriesPath.toString());
+ } catch (MetadataException e) {
+ throw new QueryProcessException(e);
+ }
+ if (node != null && node.getCachedLast() != null) {
+ return node.getCachedLast();
+ }
}
+ return calculateLastPairByScanningTsFiles(seriesPath, tsDataType, context,
sensors, node);
+ }
+ private static TimeValuePair calculateLastPairByScanningTsFiles(
+ Path seriesPath, TSDataType tsDataType, QueryContext context,
Set<String> sensors,
+ LeafMNode node) throws QueryProcessException, StorageEngineException,
IOException {
QueryDataSource dataSource =
QueryResourceManager.getInstance().getQueryDataSource(seriesPath,
context, null);
@@ -180,7 +190,9 @@ public class LastQueryExecutor {
}
// Update cached last value with low priority
- node.updateCachedLast(resultPair, false, Long.MIN_VALUE);
+ if (lastCacheEnabled && node != null) {
+ node.updateCachedLast(resultPair, false, Long.MIN_VALUE);
+ }
return resultPair;
}