szetszwo commented on a change in pull request #317:
URL: https://github.com/apache/incubator-ratis/pull/317#discussion_r535879874



##########
File path: 
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java
##########
@@ -390,8 +414,21 @@ int getLoadingTimes() {
     return loadingTimes.get();
   }
 
-  synchronized void evictCache() {
+  void evictCache() {
     entryCache.clear();
+    totalCacheSize.set(0);
+  }
+
+  void putEntryCache(TermIndex key, LogEntryProto value, Op op) {
+    entryCache.put(key, value);
+    totalCacheSize.getAndAdd(getEntrySize(value, op));

Review comment:
       We should check previous.
   ```
       final LogEntryProto previous = entryCache.put(key, value);
       long previousSize = 0;
       if (previous != null) {
         previousSize = getEntrySize(value, Op.REMOVE_CACHE);
       }
       totalCacheSize.getAndAdd(getEntrySize(value, op) - previousSize);
   ```
   Or 
   ```
       Preconditions.assertNull(previous, "previous");
   ```
   

##########
File path: 
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogCache.java
##########
@@ -167,8 +165,27 @@ int size() {
       }
     }
 
-    long sizeInBytes() {
-      return sizeInBytes;
+    long getTotalFileSize() {
+      try(AutoCloseableLock readLock = readLock()) {
+        long size = 0;
+        // TODO(runzhiwang): If there is performance problem, we do not need 
to re-calculate it every time
+        // because it is only for metric
+        for (LogSegment seg : segments) {
+           size += seg.getTotalFileSize();
+        }
+        return size;
+      }
+    }

Review comment:
       We cannot control how often the metric call this method.  We should 
cache it or use the original code.  Let's do it separately.
   
   




----------------------------------------------------------------
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:
[email protected]


Reply via email to