Copilot commented on code in PR #12029:
URL: https://github.com/apache/ozone/pull/12029#discussion_r4548700867


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/bucket/OMBucketDeleteResponse.java:
##########
@@ -82,6 +82,7 @@ public void addToDBBatch(OMMetadataManager omMetadataManager,
     } catch (IOException ex) {
       // Do nothing if there is no lifecycle attached.
     }
+    
omMetadataManager.getLifecycleScanStateTable().deleteWithBatch(batchOperation, 
dbBucketKey);

Review Comment:
   The lifecycle configuration delete is guarded with a catch block to tolerate 
missing lifecycle tables (eg older schema / feature not enabled). The newly 
added scan-state delete is unguarded, so bucket deletion could now fail in the 
same scenario. Consider moving the scan-state deletion into the same guarded 
block (or applying the same tolerance logic) so bucket deletes remain 
backward-compatible when lifecycle tables are unavailable.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/lifecycle/OMLifecycleSaveScanStateRequest.java:
##########
@@ -64,8 +67,17 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager, Execut
     OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(
         getOmRequest());
 
+    OMMetadataManager metadataManager = ozoneManager.getMetadataManager();
+    try {
+      if (!isScanStateValid(metadataManager, state)) {
+        throw new OMException("Bucket or Lifecycle Configuration no longer 
exists", LIFECYCLE_CONFIGURATION_NOT_FOUND);
+      }
+    } catch (IOException e) {
+      return new 
OMLifecycleSaveScanStateResponse(createErrorOMResponse(omResponse, e), null);
+    }

Review Comment:
   The new OMException message is quite generic for diagnosing race conditions. 
Consider including at least the bucketKey and the expected vs actual IDs 
(bucketObjID / lifecycleConfigurationUpdateID) in the message so operators can 
correlate which scan task was rejected and why.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyLifecycleService.java:
##########
@@ -1233,7 +1233,7 @@ void testCacheOnlyKeyNotSavedAsLastScannedKey() throws 
Exception {
       Table<String, OmLifecycleScanState> spyTable = spy(originalTable);
       tableField.set(metadataManager, spyTable);
       try {
-        runSingleLifecycleScan(volumeName, bucketName);
+        runSingleLifecycleScan(volumeName, bucketName, false);

Review Comment:
   The boolean flag makes call sites like `runSingleLifecycleScan(..., false)` 
hard to interpret in tests. Consider replacing it with a more self-describing 
helper (eg two explicit methods like 
`runSingleLifecycleScanDeletingPolicy(...)` vs 
`runSingleLifecycleScanKeepingPolicy(...)`) or using an enum to make the intent 
unambiguous.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyLifecycleService.java:
##########
@@ -3629,14 +3629,25 @@ private void cleanUpService() throws Exception {
   // later and deletes the objects the caller expects to remain.
   private void runSingleLifecycleScan(String volume, String bucket)
       throws IOException, TimeoutException, InterruptedException {
+    runSingleLifecycleScan(volume, bucket, true);
+  }
+
+  /**
+   * @param deletePolicy delete the policy once the task starts, so the bucket 
is not scanned again. Scan state is
+   *     not saved after the policy is deleted, so tests checking the saved 
scan state keep the policy instead.
+   */
+  private void runSingleLifecycleScan(String volume, String bucket, boolean 
deletePolicy)
+      throws IOException, TimeoutException, InterruptedException {

Review Comment:
   The boolean flag makes call sites like `runSingleLifecycleScan(..., false)` 
hard to interpret in tests. Consider replacing it with a more self-describing 
helper (eg two explicit methods like 
`runSingleLifecycleScanDeletingPolicy(...)` vs 
`runSingleLifecycleScanKeepingPolicy(...)`) or using an enum to make the intent 
unambiguous.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyLifecycleService.java:
##########
@@ -3629,14 +3629,25 @@ private void cleanUpService() throws Exception {
   // later and deletes the objects the caller expects to remain.
   private void runSingleLifecycleScan(String volume, String bucket)
       throws IOException, TimeoutException, InterruptedException {
+    runSingleLifecycleScan(volume, bucket, true);
+  }
+
+  /**
+   * @param deletePolicy delete the policy once the task starts, so the bucket 
is not scanned again. Scan state is
+   *     not saved after the policy is deleted, so tests checking the saved 
scan state keep the policy instead.
+   */
+  private void runSingleLifecycleScan(String volume, String bucket, boolean 
deletePolicy)
+      throws IOException, TimeoutException, InterruptedException {
     FaultInjectorImpl taskStart = new FaultInjectorImpl();
     FaultInjectorImpl firstDelete = new FaultInjectorImpl();
     // The third injector is only read for an injected exception, but the scan 
expects it to exist
     installInjectors(taskStart, firstDelete, new FaultInjectorImpl());
     keyLifecycleService.resume();
     // The in-flight list is filled at schedule time, so wait for the task to 
reach the injector
     taskStart.awaitPaused(10000);
-    deleteLifecyclePolicy(volume, bucket);
+    if (deletePolicy) {
+      deleteLifecyclePolicy(volume, bucket);
+    }

Review Comment:
   The boolean flag makes call sites like `runSingleLifecycleScan(..., false)` 
hard to interpret in tests. Consider replacing it with a more self-describing 
helper (eg two explicit methods like 
`runSingleLifecycleScanDeletingPolicy(...)` vs 
`runSingleLifecycleScanKeepingPolicy(...)`) or using an enum to make the intent 
unambiguous.



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