You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/05/18 10:33:49 UTC

[GitHub] [incubator-iotdb] wshao08 opened a new pull request #1221: [IOTDB-653]Separate LAST cache from MTree

wshao08 opened a new pull request #1221:
URL: https://github.com/apache/incubator-iotdb/pull/1221


   JIRA Issue: https://issues.apache.org/jira/browse/IOTDB-653
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #1221: [IOTDB-653]Separate LAST cache from MTree

Posted by GitBox <gi...@apache.org>.
wshao08 commented on a change in pull request #1221:
URL: https://github.com/apache/incubator-iotdb/pull/1221#discussion_r429820030



##########
File path: server/src/main/java/org/apache/iotdb/db/engine/cache/LastCacheManager.java
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.engine.cache;
+
+import java.sql.Time;
+import java.util.HashMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LastCacheManager {
+
+  private HashMap<String, StorageGroupLastCache> storageGroupMap;

Review comment:
       Fixed

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/cache/LastCacheManager.java
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.engine.cache;
+
+import java.sql.Time;
+import java.util.HashMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LastCacheManager {
+
+  private HashMap<String, StorageGroupLastCache> storageGroupMap;
+
+  private LastCacheManager() {
+    storageGroupMap = new HashMap<>();
+  }
+
+  public static LastCacheManager getInstance() {
+    return SingletonClassInstance.instance;
+  }
+
+  public TimeValuePair get(String timeseriesPath) throws MetadataException {
+    String storageGroupName = MManager.getInstance().getStorageGroupName(timeseriesPath);
+    if (storageGroupMap.containsKey(storageGroupName)) {
+      return storageGroupMap.get(storageGroupName).get(timeseriesPath);
+    } else {
+      StorageGroupLastCache newEntry = new StorageGroupLastCache(storageGroupName);
+      storageGroupMap.put(storageGroupName, newEntry);

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] jt2594838 commented on a change in pull request #1221: [IOTDB-653]Separate LAST cache from MTree

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on a change in pull request #1221:
URL: https://github.com/apache/incubator-iotdb/pull/1221#discussion_r429014450



##########
File path: server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByFillIT.java
##########
@@ -316,6 +317,7 @@ public void previousUntilLastTest1() {
     try (Connection connection = DriverManager.
             getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
          Statement statement = connection.createStatement()) {
+      LastCacheManager.getInstance().clear();

Review comment:
       I would suggest moving this into `clearEnv` in `EnvironmentUtils` so that other people will not forget to do the cleaning when they add new tests.

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/cache/LastCacheManager.java
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.engine.cache;
+
+import java.sql.Time;
+import java.util.HashMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LastCacheManager {
+
+  private HashMap<String, StorageGroupLastCache> storageGroupMap;

Review comment:
       It would be better to type a variable using an interface rather than specific classes to introduce more flexibility.

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/cache/LastCacheManager.java
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.engine.cache;
+
+import java.sql.Time;
+import java.util.HashMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LastCacheManager {
+
+  private HashMap<String, StorageGroupLastCache> storageGroupMap;
+
+  private LastCacheManager() {
+    storageGroupMap = new HashMap<>();
+  }
+
+  public static LastCacheManager getInstance() {
+    return SingletonClassInstance.instance;
+  }
+
+  public TimeValuePair get(String timeseriesPath) throws MetadataException {
+    String storageGroupName = MManager.getInstance().getStorageGroupName(timeseriesPath);
+    if (storageGroupMap.containsKey(storageGroupName)) {
+      return storageGroupMap.get(storageGroupName).get(timeseriesPath);
+    } else {
+      StorageGroupLastCache newEntry = new StorageGroupLastCache(storageGroupName);
+      storageGroupMap.put(storageGroupName, newEntry);

Review comment:
       storageGroupMap is not a concurrent one, so I doubt the concurrent safety when multiple storage groups put a cache into it concurrently.

##########
File path: server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
##########
@@ -22,7 +22,10 @@
 
 import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE;
 import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES;
+
+import java.sql.Time;

Review comment:
       Is this used?

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/cache/LastCacheManager.java
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.engine.cache;
+
+import java.sql.Time;
+import java.util.HashMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.tsfile.read.TimeValuePair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LastCacheManager {
+
+  private HashMap<String, StorageGroupLastCache> storageGroupMap;
+
+  private LastCacheManager() {
+    storageGroupMap = new HashMap<>();
+  }
+
+  public static LastCacheManager getInstance() {
+    return SingletonClassInstance.instance;
+  }
+
+  public TimeValuePair get(String timeseriesPath) throws MetadataException {
+    String storageGroupName = MManager.getInstance().getStorageGroupName(timeseriesPath);
+    if (storageGroupMap.containsKey(storageGroupName)) {
+      return storageGroupMap.get(storageGroupName).get(timeseriesPath);
+    } else {
+      StorageGroupLastCache newEntry = new StorageGroupLastCache(storageGroupName);
+      storageGroupMap.put(storageGroupName, newEntry);
+      return newEntry.get(timeseriesPath);
+    }
+  }
+
+  public void put(String timeseriesPath, TimeValuePair timeValuePair, boolean highPriorityUpdate)
+      throws MetadataException {
+    String storageGroupName = MManager.getInstance().getStorageGroupName(timeseriesPath);
+    if (storageGroupMap.containsKey(storageGroupName)) {
+      storageGroupMap.get(storageGroupName).put(timeseriesPath, timeValuePair, highPriorityUpdate);
+    } else {
+      StorageGroupLastCache newEntry = new StorageGroupLastCache(storageGroupName);
+      newEntry.put(timeseriesPath, timeValuePair, highPriorityUpdate);
+      storageGroupMap.put(storageGroupName, newEntry);
+    }
+  }
+
+  public void clearCache(String timeseriesPath) throws MetadataException {

Review comment:
       Add a comment that this method does not only remove the cache of the given timeseries but also its belonging storage group's caches.

##########
File path: server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
##########
@@ -179,7 +177,8 @@ public static TimeValuePair calculateLastPairForOneSeries(
     }
 
     // Update cached last value with low priority
-    node.updateCachedLast(resultPair, false, Long.MIN_VALUE);
+    LastCacheManager.getInstance().put(seriesPath.getFullPath(), resultPair, false);
+    //node.updateCachedLast(resultPair, false, Long.MIN_VALUE);

Review comment:
       Remove the commented code.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] wshao08 commented on a change in pull request #1221: [IOTDB-653]Separate LAST cache from MTree

Posted by GitBox <gi...@apache.org>.
wshao08 commented on a change in pull request #1221:
URL: https://github.com/apache/incubator-iotdb/pull/1221#discussion_r429819878



##########
File path: server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByFillIT.java
##########
@@ -316,6 +317,7 @@ public void previousUntilLastTest1() {
     try (Connection connection = DriverManager.
             getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
          Statement statement = connection.createStatement()) {
+      LastCacheManager.getInstance().clear();

Review comment:
       Fixed

##########
File path: server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
##########
@@ -179,7 +177,8 @@ public static TimeValuePair calculateLastPairForOneSeries(
     }
 
     // Update cached last value with low priority
-    node.updateCachedLast(resultPair, false, Long.MIN_VALUE);
+    LastCacheManager.getInstance().put(seriesPath.getFullPath(), resultPair, false);
+    //node.updateCachedLast(resultPair, false, Long.MIN_VALUE);

Review comment:
       Fixed

##########
File path: server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
##########
@@ -22,7 +22,10 @@
 
 import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE;
 import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES;
+
+import java.sql.Time;

Review comment:
       Removed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] wshao08 closed pull request #1221: [IOTDB-653]Separate LAST cache from MTree

Posted by GitBox <gi...@apache.org>.
wshao08 closed pull request #1221:
URL: https://github.com/apache/incubator-iotdb/pull/1221


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] wshao08 commented on pull request #1221: [IOTDB-653]Separate LAST cache from MTree

Posted by GitBox <gi...@apache.org>.
wshao08 commented on pull request #1221:
URL: https://github.com/apache/incubator-iotdb/pull/1221#issuecomment-688576341


   As the Last implementation in cluster has been change, this PR is no longer needed.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org