xiaoyuyao commented on a change in pull request #943:
URL: https://github.com/apache/hadoop-ozone/pull/943#discussion_r446329661



##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerDoubleBuffer.java
##########
@@ -353,29 +368,62 @@ private void flushTransactions() {
     }
   }
 
-  private void cleanupCache(List<Long> lastRatisTransactionIndex) {
-    // As now only volume and bucket transactions are handled only called
-    // cleanupCache on bucketTable.
-    // TODO: After supporting all write operations we need to call
-    //  cleanupCache on the tables only when buffer has entries for that table.
-    omMetadataManager.getBucketTable().cleanupCache(lastRatisTransactionIndex);
-    omMetadataManager.getVolumeTable().cleanupCache(lastRatisTransactionIndex);
-    omMetadataManager.getUserTable().cleanupCache(lastRatisTransactionIndex);
-
-    //TODO: Optimization we can do here is for key transactions we can only
-    // cleanup cache when it is key commit transaction. In this way all
-    // intermediate transactions for a key will be read from in-memory cache.
-    
omMetadataManager.getOpenKeyTable().cleanupCache(lastRatisTransactionIndex);
-    omMetadataManager.getKeyTable().cleanupCache(lastRatisTransactionIndex);
-    
omMetadataManager.getDeletedTable().cleanupCache(lastRatisTransactionIndex);
-    omMetadataManager.getMultipartInfoTable().cleanupCache(
-        lastRatisTransactionIndex);
-    omMetadataManager.getS3SecretTable().cleanupCache(
-        lastRatisTransactionIndex);
-    omMetadataManager.getDelegationTokenTable().cleanupCache(
-        lastRatisTransactionIndex);
-    omMetadataManager.getPrefixTable().cleanupCache(lastRatisTransactionIndex);
+  /**
+   * Set cleanup epoch for the DoubleBufferEntry.
+   * @param entry
+   * @param cleanupEpochs
+   */
+  private void setCleanupEpoch(DoubleBufferEntry entry, Map<String,
+      List<Long>> cleanupEpochs) {
+    // Add epochs depending on operated tables. In this way
+    // cleanup will be called only when required.
+
+    // As bucket and volume table is full cache add cleanup
+    // epochs only when request is delete to cleanup deleted
+    // entries.
+
+    String opName =
+        entry.getResponse().getOMResponse().getCmdType().name();
+
+    if (opName.toLowerCase().contains(VOLUME) ||
+        opName.toLowerCase().contains(BUCKET)) {
+      if (DeleteBucket.name().equals(opName)
+          || DeleteVolume.name().equals(opName)) {
+        addCleanupEntry(entry, cleanupEpochs);
+      }
+    } else {
+      addCleanupEntry(entry, cleanupEpochs);
+    }
+  }
+
+
+  private void addCleanupEntry(DoubleBufferEntry entry, Map<String,
+      List<Long>> cleanupEpochs) {
+    Class<? extends OMClientResponse> responseClass =
+        entry.getResponse().getClass();
+    CleanupTableInfo cleanupTableInfo =
+        responseClass.getAnnotation(CleanupTableInfo.class);
+    if (cleanupTableInfo != null) {
+      String[] cleanupTables = cleanupTableInfo.cleanupTables();
+      for (String table : cleanupTables) {
+        cleanupEpochs.computeIfAbsent(table, list -> new ArrayList<>())
+            .add(entry.getTrxLogIndex());
+      }
+    } else {
+      // This is to catch early errors, when an new response class missed to
+      // add CleanupTableInfo annotation.
+      throw new RuntimeException("CleanupTableInfo Annotation is missing " +

Review comment:
       Can we add a unit test on response class that misses annotation?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to