HTHou commented on code in PR #13068:
URL: https://github.com/apache/iotdb/pull/13068#discussion_r1730997723


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/HashLastFlushTimeMap.java:
##########
@@ -94,10 +79,52 @@ public void updateMultiDeviceFlushedTime(
         timePartitionId, (k1, v1) -> v1 == null ? finalMemIncr : v1 + 
finalMemIncr);
   }
 
+  // For recover only
+  @Override
+  public void upgradeAndUpdateMultiDeviceFlushedTime(
+      long timePartitionId, Map<IDeviceID, Long> flushedTimeMap) {
+    ILastFlushTime flushTimeMapForPartition =
+        partitionLatestFlushedTime.computeIfAbsent(
+            timePartitionId, id -> new DeviceLastFlushTime());
+    // upgrade
+    if (flushTimeMapForPartition instanceof PartitionLastFlushTime) {
+      long maxFlushTime = flushTimeMapForPartition.getLastFlushTime(null);
+      ILastFlushTime newDeviceLastFlushTime = new DeviceLastFlushTime();
+      long memIncr = 0;
+      for (Map.Entry<IDeviceID, Long> entry : flushedTimeMap.entrySet()) {
+        memIncr += HASHMAP_NODE_BASIC_SIZE + entry.getKey().ramBytesUsed();
+        newDeviceLastFlushTime.updateLastFlushTime(entry.getKey(), 
entry.getValue());
+        maxFlushTime = Math.max(maxFlushTime, entry.getValue());
+      }
+      long finalMemIncr = memIncr;
+      memCostForEachPartition.compute(
+          timePartitionId, (k1, v1) -> v1 == null ? finalMemIncr : v1 + 
finalMemIncr);
+    } else {
+      // should not go here
+      long memIncr = 0;
+      for (Map.Entry<IDeviceID, Long> entry : flushedTimeMap.entrySet()) {
+        if (flushTimeMapForPartition.getLastFlushTime(entry.getKey()) == 
Long.MIN_VALUE) {
+          memIncr += HASHMAP_NODE_BASIC_SIZE + entry.getKey().ramBytesUsed();
+        }
+        flushTimeMapForPartition.updateLastFlushTime(entry.getKey(), 
entry.getValue());
+      }
+      long finalMemIncr = memIncr;
+      memCostForEachPartition.compute(
+          timePartitionId, (k1, v1) -> v1 == null ? finalMemIncr : v1 + 
finalMemIncr);
+    }
+  }
+
+  // For recover
   @Override
-  public void updateOneDeviceGlobalFlushedTime(IDeviceID path, long time) {
-    globalLatestFlushedTimeForEachDevice.compute(
-        path, (k, v) -> v == null ? time : Math.max(v, time));
+  public void updatePartitionFlushedTime(long timePartitionId, long 
maxFlushedTime) {
+    ILastFlushTime flushTimeMapForPartition =
+        partitionLatestFlushedTime.computeIfAbsent(
+            timePartitionId, id -> new PartitionLastFlushTime(maxFlushedTime));
+
+    // todo
+    long memIncr = Long.BYTES;
+    flushTimeMapForPartition.updateLastFlushTime(null, maxFlushedTime);
+    memCostForEachPartition.putIfAbsent(timePartitionId, memIncr);

Review Comment:
   There is some missing code, added.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to