>From Wail Alkowaileet <[email protected]>:

Wail Alkowaileet has uploaded this change for review. ( 
https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17630 )


Change subject: [WIP] Support bulk deletes of files
......................................................................

[WIP] Support bulk deletes of files

Change-Id: Ic53a45ef4cc0911ee2b07c73c267d492600bc69f
---
M 
asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
M 
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOManager.java
A 
hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/bulk/DeleteBulkOperation.java
M 
hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
M 
asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/ICloudClient.java
M 
asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
A 
hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/bulk/AbstractBulkOperation.java
A 
asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/bulk/DeleteBulkCloudOperation.java
A 
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOBulkOperation.java
M 
asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/AbstractCloudIOManager.java
10 files changed, 257 insertions(+), 24 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/30/17630/1

diff --git 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/AbstractCloudIOManager.java
 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/AbstractCloudIOManager.java
index 1c06919..4bb83cc 100644
--- 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/AbstractCloudIOManager.java
+++ 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/AbstractCloudIOManager.java
@@ -30,6 +30,7 @@
 import java.util.List;
 import java.util.Set;

+import org.apache.asterix.cloud.bulk.DeleteBulkCloudOperation;
 import org.apache.asterix.cloud.clients.CloudClientProvider;
 import org.apache.asterix.cloud.clients.ICloudClient;
 import org.apache.asterix.cloud.util.CloudFileUtil;
@@ -40,6 +41,7 @@
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.api.io.FileReference;
 import org.apache.hyracks.api.io.IFileHandle;
+import org.apache.hyracks.api.io.IIOBulkOperation;
 import org.apache.hyracks.api.util.IoUtil;
 import org.apache.hyracks.control.nc.io.IOManager;
 import org.apache.hyracks.util.file.FileUtil;
@@ -209,6 +211,11 @@
     }

     @Override
+    public IIOBulkOperation createDeleteBulkOperation() {
+        return new DeleteBulkCloudOperation(localIoManager, bucket, 
cloudClient);
+    }
+
+    @Override
     public final void close(IFileHandle fHandle) throws HyracksDataException {
         try {
             CloudFileHandle cloudFileHandle = (CloudFileHandle) fHandle;
diff --git 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/bulk/DeleteBulkCloudOperation.java
 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/bulk/DeleteBulkCloudOperation.java
new file mode 100644
index 0000000..9eec4a0
--- /dev/null
+++ 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/bulk/DeleteBulkCloudOperation.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.asterix.cloud.bulk;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.asterix.cloud.clients.ICloudClient;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.FileReference;
+import org.apache.hyracks.api.io.IIOManager;
+import org.apache.hyracks.control.nc.io.bulk.DeleteBulkOperation;
+
+public class DeleteBulkCloudOperation extends DeleteBulkOperation {
+    private final String bucket;
+    private final ICloudClient cloudClient;
+
+    public DeleteBulkCloudOperation(IIOManager ioManager, String bucket, 
ICloudClient cloudClient) {
+        super(ioManager);
+        this.bucket = bucket;
+        this.cloudClient = cloudClient;
+    }
+
+    @Override
+    public void performOperation() throws HyracksDataException {
+        List<String> paths = 
fileReferences.stream().map(FileReference::getRelativePath).collect(Collectors.toList());
+        cloudClient.deleteObjects(bucket, paths);
+
+        // Bulk delete locally as well
+        super.performOperation();
+    }
+}
diff --git 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/ICloudClient.java
 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/ICloudClient.java
index 4f02df2..aa2282e 100644
--- 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/ICloudClient.java
+++ 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/ICloudClient.java
@@ -21,6 +21,7 @@
 import java.io.FilenameFilter;
 import java.io.InputStream;
 import java.nio.ByteBuffer;
+import java.util.Collection;
 import java.util.Map;
 import java.util.Set;

@@ -36,7 +37,7 @@
      * Creates a cloud buffered writer
      *
      * @param bucket bucket to write to
-     * @param path path to write to
+     * @param path   path to write to
      * @return buffered writer
      */
     ICloudBufferedWriter createBufferedWriter(String bucket, String path);
@@ -45,7 +46,7 @@
      * Lists objects at the specified bucket and path, and applies the file 
name filter on the returned objects
      *
      * @param bucket bucket to list from
-     * @param path path to list from
+     * @param path   path to list from
      * @param filter filter to apply
      * @return file names returned after applying the file name filter
      */
@@ -56,7 +57,7 @@
      * buffer.remaining()
      *
      * @param bucket bucket
-     * @param path path
+     * @param path   path
      * @param offset offset
      * @param buffer buffer
      * @return returns the buffer position
@@ -67,7 +68,7 @@
      * Reads all bytes of an object at the specified bucket and path
      *
      * @param bucket bucket
-     * @param path path
+     * @param path   path
      * @return bytes
      * @throws HyracksDataException HyracksDataException
      */
@@ -77,7 +78,7 @@
      * Returns the {@code InputStream} of an object at the specified bucket 
and path
      *
      * @param bucket bucket
-     * @param path path
+     * @param path   path
      * @return inputstream
      */
     InputStream getObjectStream(String bucket, String path);
@@ -86,16 +87,16 @@
      * Writes the content of the byte array into the bucket at the specified 
path
      *
      * @param bucket bucket
-     * @param path path
-     * @param data data
+     * @param path   path
+     * @param data   data
      */
     void write(String bucket, String path, byte[] data);

     /**
      * Copies an object from the source path to the destination path
      *
-     * @param bucket bucket
-     * @param srcPath source path
+     * @param bucket   bucket
+     * @param srcPath  source path
      * @param destPath destination path
      */
     void copy(String bucket, String srcPath, FileReference destPath);
@@ -104,15 +105,23 @@
      * Deletes an object at the specified bucket and path
      *
      * @param bucket bucket
-     * @param path path
+     * @param path   path
      */
     void deleteObject(String bucket, String path);

     /**
+     * Deletes all objects at the specified bucket and paths
+     *
+     * @param bucket bucket
+     * @param paths  paths of all objects to be deleted
+     */
+    void deleteObjects(String bucket, Collection<String> paths);
+
+    /**
      * Returns the size of the object at the specified path
      *
      * @param bucket bucket
-     * @param path path
+     * @param path   path
      * @return size
      */
     long getObjectSize(String bucket, String path) throws HyracksDataException;
@@ -121,7 +130,7 @@
      * Checks if an object exists at the specified path
      *
      * @param bucket bucket
-     * @param path path
+     * @param path   path
      * @return {@code true} if the object exists, {@code false} otherwise
      */
     boolean exists(String bucket, String path) throws HyracksDataException;
@@ -129,7 +138,7 @@
     /**
      * Syncs files by downloading them from cloud storage to local storage
      *
-     * @param bucket bucket to sync from
+     * @param bucket                   bucket to sync from
      * @param cloudToLocalStoragePaths map of cloud storage partition to local 
storage path
      * @throws HyracksDataException HyracksDataException
      */
diff --git 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
index 0fb9c08..d8dd1ca 100644
--- 
a/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
+++ 
b/asterixdb/asterix-cloud/src/main/java/org/apache/asterix/cloud/clients/aws/s3/S3CloudClient.java
@@ -31,6 +31,7 @@
 import java.nio.ByteBuffer;
 import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -187,14 +188,20 @@
     @Override
     public void deleteObject(String bucket, String path) {
         Set<String> fileList = listObjects(bucket, path, IoUtil.NO_OP_FILTER);
-        if (fileList.isEmpty()) {
+        deleteObjects(bucket, fileList);
+    }
+
+    @Override
+    public void deleteObjects(String bucket, Collection<String> paths) {
+        if (paths.isEmpty()) {
             return;
         }

         List<ObjectIdentifier> objectIdentifiers = new ArrayList<>();
-        for (String file : fileList) {
-            
objectIdentifiers.add(ObjectIdentifier.builder().key(file).build());
+        for (String path : paths) {
+            
objectIdentifiers.add(ObjectIdentifier.builder().key(path).build());
         }
+
         Delete delete = Delete.builder().objects(objectIdentifiers).build();
         DeleteObjectsRequest deleteReq = 
DeleteObjectsRequest.builder().bucket(bucket).delete(delete).build();
         s3Client.deleteObjects(deleteReq);
diff --git 
a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
 
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
index 4e71b1c..dc449a8 100644
--- 
a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
+++ 
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/PersistentLocalResourceRepository.java
@@ -57,6 +57,7 @@
 import org.apache.asterix.common.utils.StoragePathUtil;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.api.io.FileReference;
+import org.apache.hyracks.api.io.IIOBulkOperation;
 import org.apache.hyracks.api.io.IIOManager;
 import org.apache.hyracks.api.io.IODeviceHandle;
 import org.apache.hyracks.api.io.IPersistedResourceRegistry;
@@ -274,6 +275,7 @@
     }

     public synchronized void deleteInvalidIndexes(Predicate<LocalResource> 
filter) throws HyracksDataException {
+        IIOBulkOperation bulkDelete = ioManager.createDeleteBulkOperation();
         for (FileReference root : storageRoots) {
             final Collection<FileReference> files = ioManager.list(root, 
METADATA_FILES_FILTER);
             try {
@@ -282,13 +284,15 @@
                     if (localResource != null && filter.test(localResource)) {
                         FileReference parent = file.getParent();
                         LOGGER.warn("deleting invalid metadata index {}", 
parent);
-                        ioManager.delete(parent);
+                        //                        ioManager.delete(parent);
+                        bulkDelete.add(parent);
                     }
                 }
             } catch (IOException e) {
                 throw HyracksDataException.create(e);
             }
         }
+        ioManager.performBulkOperation(bulkDelete);
         resourceCache.invalidateAll();
     }

@@ -361,9 +365,12 @@
      * Deletes physical files of all data verses.
      */
     public synchronized void deleteStorageData() throws HyracksDataException {
+        IIOBulkOperation bulkDelete = ioManager.createDeleteBulkOperation();
         for (FileReference root : storageRoots) {
-            ioManager.deleteDirectory(root);
+            //            ioManager.deleteDirectory(root);
+            bulkDelete.add(root);
         }
+        ioManager.performBulkOperation(bulkDelete);
         createStorageRoots();
     }

@@ -492,23 +499,30 @@
     }

     public synchronized void deleteCorruptedResources() throws 
HyracksDataException {
+        IIOBulkOperation bulkDelete = ioManager.createDeleteBulkOperation();
         for (FileReference root : storageRoots) {
             final Collection<FileReference> metadataMaskFiles = 
ioManager.list(root, METADATA_MASK_FILES_FILTER);
             for (FileReference metadataMaskFile : metadataMaskFiles) {
                 final FileReference resourceFile = 
metadataMaskFile.getParent().getChild(METADATA_FILE_NAME);
-                ioManager.delete(resourceFile);
-                ioManager.delete(metadataMaskFile);
+                //                ioManager.delete(resourceFile);
+                //                ioManager.delete(metadataMaskFile);
+                bulkDelete.add(resourceFile);
+                bulkDelete.add(metadataMaskFile);
             }
         }
+        ioManager.performBulkOperation(bulkDelete);
     }

     private void deleteIndexMaskedFiles(FileReference index) throws 
IOException {
+        IIOBulkOperation bulkDelete = ioManager.createDeleteBulkOperation();
         Collection<FileReference> masks = ioManager.list(index, 
MASK_FILES_FILTER);
         for (FileReference mask : masks) {
             deleteIndexMaskedFiles(index, mask);
             // delete the mask itself
-            ioManager.delete(mask);
+            //            ioManager.delete(mask);
+            bulkDelete.add(mask);
         }
+        ioManager.performBulkOperation(bulkDelete);
     }

     private boolean isValidIndex(FileReference index) throws IOException {
@@ -524,6 +538,7 @@
         if (indexComponentFiles == null) {
             throw new IOException(index + " doesn't exist or an IO error 
occurred");
         }
+        IIOBulkOperation bulkDelete = ioManager.createDeleteBulkOperation();
         final long validComponentSequence = 
getIndexCheckpointManager(index).getValidComponentSequence();
         for (FileReference componentFileRef : indexComponentFiles) {
             // delete any file with start or end sequence > valid component 
sequence
@@ -532,9 +547,11 @@
             if (fileStart > validComponentSequence || fileEnd > 
validComponentSequence) {
                 LOGGER.warn(() -> "Deleting invalid component file " + 
componentFileRef.getAbsolutePath()
                         + " based on valid sequence " + 
validComponentSequence);
-                ioManager.delete(componentFileRef);
+                //                ioManager.delete(componentFileRef);
+                bulkDelete.add(componentFileRef);
             }
         }
+        ioManager.performBulkOperation(bulkDelete);
     }

     private IIndexCheckpointManager getIndexCheckpointManager(FileReference 
index) throws HyracksDataException {
@@ -556,10 +573,13 @@
             maskedFiles = ioManager.list(index, (dir, name) -> 
name.equals(maskedFileName));
         }
         if (maskedFiles != null) {
+            IIOBulkOperation bulkDelete = 
ioManager.createDeleteBulkOperation();
             for (FileReference maskedFile : maskedFiles) {
                 LOGGER.info(() -> "deleting masked file: " + 
maskedFile.getAbsolutePath());
-                ioManager.delete(maskedFile);
+                //                ioManager.delete(maskedFile);
+                bulkDelete.add(maskedFile);
             }
+            ioManager.performBulkOperation(bulkDelete);
         }
     }

@@ -660,13 +680,16 @@

     public void deletePartition(int partitionId) throws HyracksDataException {
         Collection<FileReference> onDiskPartitions = getOnDiskPartitions();
+        IIOBulkOperation bulkDelete = ioManager.createDeleteBulkOperation();
         for (FileReference onDiskPartition : onDiskPartitions) {
             int partitionNum = 
StoragePathUtil.getPartitionNumFromRelativePath(onDiskPartition.getAbsolutePath());
             if (partitionNum == partitionId) {
                 LOGGER.warn("deleting partition {}", partitionNum);
-                ioManager.delete(onDiskPartition);
+                //                ioManager.delete(onDiskPartition);
+                bulkDelete.add(onDiskPartition);
                 return;
             }
         }
+        ioManager.performBulkOperation(bulkDelete);
     }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOBulkOperation.java
 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOBulkOperation.java
new file mode 100644
index 0000000..c5e84fd
--- /dev/null
+++ 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOBulkOperation.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.api.io;
+
+/**
+ * A descriptor for a bulk operation
+ */
+public interface IIOBulkOperation {
+    /**
+     * Add file reference to perform the required operation (e.g., delete)
+     *
+     * @param fileReference that should be included in this bulk operation
+     * @see IIOManager#performBulkOperation(IIOBulkOperation)
+     * @see IIOManager#createDeleteBulkOperation()
+     */
+    void add(FileReference fileReference);
+}
diff --git 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOManager.java
 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOManager.java
index 95dcb2f..f16c2fe 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOManager.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IIOManager.java
@@ -122,6 +122,8 @@
      */
     void delete(FileReference fileRef) throws HyracksDataException;
 
+    IIOBulkOperation createDeleteBulkOperation();
+
     Set<FileReference> list(FileReference dir) throws HyracksDataException;

     /**
@@ -150,4 +152,6 @@
     boolean makeDirectories(FileReference resourceDir);

     void cleanDirectory(FileReference resourceDir) throws HyracksDataException;
+
+    void performBulkOperation(IIOBulkOperation bulkOperation) throws 
HyracksDataException;
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
index 0e6578f..644112a 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/IOManager.java
@@ -47,11 +47,14 @@
 import org.apache.hyracks.api.io.FileReference;
 import org.apache.hyracks.api.io.IFileDeviceResolver;
 import org.apache.hyracks.api.io.IFileHandle;
+import org.apache.hyracks.api.io.IIOBulkOperation;
 import org.apache.hyracks.api.io.IIOManager;
 import org.apache.hyracks.api.io.IODeviceHandle;
 import org.apache.hyracks.api.util.InvokeUtil;
 import org.apache.hyracks.api.util.IoUtil;
 import org.apache.hyracks.control.nc.io.IoRequest.State;
+import org.apache.hyracks.control.nc.io.bulk.AbstractBulkOperation;
+import org.apache.hyracks.control.nc.io.bulk.DeleteBulkOperation;
 import org.apache.hyracks.util.file.FileUtil;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
@@ -507,6 +510,11 @@
     }

     @Override
+    public IIOBulkOperation createDeleteBulkOperation() {
+        return new DeleteBulkOperation(this);
+    }
+
+    @Override
     public Set<FileReference> list(FileReference dir) throws 
HyracksDataException {
         return list(dir, IoUtil.NO_OP_FILTER);
     }
@@ -592,4 +600,9 @@
             throw HyracksDataException.create(e);
         }
     }
+
+    @Override
+    public void performBulkOperation(IIOBulkOperation bulkOperation) throws 
HyracksDataException {
+        ((AbstractBulkOperation) bulkOperation).performOperation();
+    }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/bulk/AbstractBulkOperation.java
 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/bulk/AbstractBulkOperation.java
new file mode 100644
index 0000000..4ca7b9c
--- /dev/null
+++ 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/bulk/AbstractBulkOperation.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.control.nc.io.bulk;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.FileReference;
+import org.apache.hyracks.api.io.IIOBulkOperation;
+import org.apache.hyracks.api.io.IIOManager;
+
+public abstract class AbstractBulkOperation implements IIOBulkOperation {
+    protected final IIOManager ioManager;
+    protected final List<FileReference> fileReferences;
+
+    AbstractBulkOperation(IIOManager ioManager) {
+        this.ioManager = ioManager;
+        fileReferences = new ArrayList<>();
+    }
+
+    @Override
+    public final void add(FileReference fileReference) {
+        fileReferences.add(fileReference);
+    }
+
+    public abstract void performOperation() throws HyracksDataException;
+}
diff --git 
a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/bulk/DeleteBulkOperation.java
 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/bulk/DeleteBulkOperation.java
new file mode 100644
index 0000000..5ccfdd6
--- /dev/null
+++ 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/io/bulk/DeleteBulkOperation.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.control.nc.io.bulk;
+
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.FileReference;
+import org.apache.hyracks.api.io.IIOManager;
+
+public class DeleteBulkOperation extends AbstractBulkOperation {
+    public DeleteBulkOperation(IIOManager ioManager) {
+        super(ioManager);
+    }
+
+    @Override
+    public void performOperation() throws HyracksDataException {
+        for (FileReference fileReference : fileReferences) {
+            ioManager.delete(fileReference);
+        }
+    }
+}

--
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17630
To unsubscribe, or for help writing mail filters, visit 
https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: Ic53a45ef4cc0911ee2b07c73c267d492600bc69f
Gerrit-Change-Number: 17630
Gerrit-PatchSet: 1
Gerrit-Owner: Wail Alkowaileet <[email protected]>
Gerrit-MessageType: newchange

Reply via email to