This is an automated email from the ASF dual-hosted git repository.

mhubail pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git

commit 6a369d1395af9c61ccb8d887bf32fec41bc70110
Author: Michael Blow <[email protected]>
AuthorDate: Sun Feb 23 19:48:05 2025 -0500

    [NO ISSUE][*DB][CLOUD] Cancel running GCS ops on interrupt
    
    Ext-ref: MB-65432
    Change-Id: I840f300f11a5bc2676cd4b542bda40cfb78e64e4
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19468
    Reviewed-by: Ali Alsuliman <[email protected]>
    Tested-by: Michael Blow <[email protected]>
---
 .../cloud/clients/google/gcs/GCSCloudClient.java   | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/google/gcs/GCSCloudClient.java
 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/google/gcs/GCSCloudClient.java
index 99cda9e76f..16fb27836c 100644
--- 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/google/gcs/GCSCloudClient.java
+++ 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/google/gcs/GCSCloudClient.java
@@ -31,8 +31,10 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
 import java.util.function.Supplier;
 
 import org.apache.asterix.cloud.IWriteBufferProvider;
@@ -348,12 +350,30 @@ public class GCSCloudClient implements ICloudClient {
     }
 
     private <T> T runOpInterruptibly(Supplier<T> operation) throws 
HyracksDataException {
+        Future<T> opTask = executor.submit(operation::get);
         try {
-            return executor.submit(operation::get).get();
+            return opTask.get();
         } catch (InterruptedException e) {
+            cancelAndUnwind(opTask);
             throw HyracksDataException.create(e);
         } catch (ExecutionException e) {
             throw HyracksDataException.create(e.getCause());
         }
     }
+
+    private static <T> void cancelAndUnwind(Future<T> opTask) {
+        opTask.cancel(true);
+        while (true) {
+            try {
+                opTask.get();
+            } catch (InterruptedException e1) {
+                continue;
+            } catch (CancellationException e1) {
+                LOGGER.debug("ignoring exception after cancel of op", e1);
+            } catch (ExecutionException e1) {
+                LOGGER.debug("ignoring exception after cancel of op", 
e1.getCause());
+            }
+            return;
+        }
+    }
 }

Reply via email to