adoroszlai commented on code in PR #8945:
URL: https://github.com/apache/ozone/pull/8945#discussion_r2277053633


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTask.java:
##########
@@ -189,14 +189,13 @@ public TaskResult process(
   @Override
   public TaskResult reprocess(OMMetadataManager omMetadataManager) {
     // Unified control for all NSS tree rebuild operations
-    RebuildState currentState = REBUILD_STATE.get();
-    if (currentState == RebuildState.RUNNING) {
-      LOG.info("NSSummary tree rebuild is already in progress, skipping 
duplicate request.");
-      return buildTaskResult(false);
-    }
+    // Use a single atomic operation to prevent race conditions
+    RebuildState previousState = REBUILD_STATE.getAndSet(RebuildState.RUNNING);
     
-    if (!REBUILD_STATE.compareAndSet(currentState, RebuildState.RUNNING)) {
-      LOG.info("Failed to acquire rebuild lock, another thread may have 
started rebuild.");
+    if (previousState == RebuildState.RUNNING) {
+      LOG.info("NSSummary tree rebuild is already in progress, skipping 
duplicate request.");
+      // Restore the previous state since we didn't actually start
+      REBUILD_STATE.set(RebuildState.RUNNING);

Review Comment:
   ```java
   1. RebuildState previousState = 
REBUILD_STATE.getAndSet(RebuildState.RUNNING);
   2. if (previousState == RebuildState.RUNNING) {
   3.   REBUILD_STATE.set(RebuildState.RUNNING);
   ```
   
   This doesn't look right: line (1) sets state to `RUNNING`, so line (3) is 
no-op.



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