weimingdiit commented on code in PR #9663:
URL: https://github.com/apache/ozone/pull/9663#discussion_r2739494695


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/CompactionService.java:
##########
@@ -134,6 +135,83 @@ private boolean shouldRun() {
     return !suspended.get();
   }
 
+  /**
+   * Compact a specific table asynchronously. This method returns immediately
+   * with a CompletableFuture that completes when the compaction finishes.
+   * This is useful for on-demand compaction requests (e.g., via admin RPC)
+   * where the caller doesn't need to wait for completion.
+   *
+   * @param tableName the name of the table to compact
+   * @return CompletableFuture that completes when compaction finishes
+   */
+  public CompletableFuture<Void> compactTableAsync(String tableName) {
+    return CompletableFuture.supplyAsync(() -> {
+      try {
+        compactFully(tableName);
+        return null;
+      } catch (Exception e) {
+        LOG.warn("Failed to compact column family: {}", tableName, e);
+      }
+      return null;
+    });
+  }
+
+  /**
+   * Compact a specific table on-demand without requiring the table
+   * to be in the configured compaction list. This is useful for
+   * ad-hoc compaction requests (e.g., via admin RPC).
+   *
+   * @param ozoneManager the OzoneManager instance
+   * @param tableName the name of the table to compact
+   * @throws IOException if compaction fails or table is not found
+   */
+  public static void compactTableOnDemand(OzoneManager ozoneManager, String 
tableName)
+      throws IOException {
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    long startTime = Time.monotonicNow();
+    LOG.info("Compacting column family on-demand: {}", tableName);
+    try (ManagedCompactRangeOptions options = new 
ManagedCompactRangeOptions()) {
+      
options.setBottommostLevelCompaction(ManagedCompactRangeOptions.BottommostLevelCompaction.kForce);
+      options.setExclusiveManualCompaction(true);
+      RocksDatabase rocksDatabase = ((RDBStore) 
omMetadataManager.getStore()).getDb();
+
+      try {
+        // Find CF Handler
+        RocksDatabase.ColumnFamily columnFamily = 
rocksDatabase.getColumnFamily(tableName);

Review Comment:
   @sadanand48  Thanks, I will update the 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.

To unsubscribe, e-mail: [email protected]

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