[NO ISSUE][STO] Delete Resource File Before Checkpoints

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- To avoid a case where the index checkpoints can be deleted but
  a failure happens before the resource file is deleted, we delete
  the resource file first.

Change-Id: Ia3351e9375007c0dbc415f5418458314233268d4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2812
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
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 93d9414..f9718c4 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
@@ -237,13 +237,13 @@
             if (isReplicationEnabled) {
                 createReplicationJob(ReplicationOperation.DELETE, resourceFile);
             }
-            // delete all checkpoints
             final LocalResource localResource = readLocalResource(resourceFile.getFile());
-            indexCheckpointManagerProvider.get(DatasetResourceReference.of(localResource)).delete();
             // Invalidate before deleting the file just in case file deletion throws some exception.
             // Since it's just a cache invalidation, it should not affect correctness.
             resourceCache.invalidate(relativePath);
             IoUtil.delete(resourceFile);
+            // delete all checkpoints
+            indexCheckpointManagerProvider.get(DatasetResourceReference.of(localResource)).delete();
         } else {
             throw HyracksDataException.create(org.apache.hyracks.api.exceptions.ErrorCode.RESOURCE_DOES_NOT_EXIST,
                     relativePath);