Merge "Merge branch 'gerrit/trinity' into 'master'"
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NcLifecycleCoordinator.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NcLifecycleCoordinator.java
index 11a85ba..5d0901d 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NcLifecycleCoordinator.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/NcLifecycleCoordinator.java
@@ -223,7 +223,7 @@
         tasks.add(new UpdateNodeStatusTask(NodeStatus.BOOTING, nodeActivePartitions));
         int metadataPartitionId = clusterManager.getMetadataPartition().getPartitionId();
         // Add any cloud-related tasks
-        addCloudTasks(tasks, nodeActivePartitions, metadataNode, metadataPartitionId);
+        addCloudTasks(tasks, nodeActivePartitions, metadataNode, metadataPartitionId, state == SystemState.CORRUPTED);
         tasks.add(new LocalStorageCleanupTask(metadataPartitionId));
         if (state == SystemState.CORRUPTED) {
             // need to perform local recovery for node active partitions
@@ -257,7 +257,7 @@
     }
 
     protected void addCloudTasks(List<INCLifecycleTask> tasks, Set<Integer> computePartitions, boolean metadataNode,
-            int metadataPartitionId) {
+            int metadataPartitionId, boolean cleanup) {
         IApplicationContext appCtx = (IApplicationContext) serviceContext.getApplicationContext();
         if (!appCtx.isCloudDeployment()) {
             return;
@@ -266,7 +266,7 @@
         StorageComputePartitionsMap map = clusterManager.getStorageComputeMap();
         map = map == null ? StorageComputePartitionsMap.computePartitionsMap(clusterManager) : map;
         Set<Integer> storagePartitions = map.getStoragePartitions(computePartitions);
-        tasks.add(new CloudToLocalStorageCachingTask(storagePartitions, metadataNode, metadataPartitionId, false));
+        tasks.add(new CloudToLocalStorageCachingTask(storagePartitions, metadataNode, metadataPartitionId, cleanup));
     }
 
     private synchronized void process(MetadataNodeResponseMessage response) throws HyracksDataException {