[NO ISSUE][STO] Ignore resource doesn't exist on dataset drop
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- When attempting to drop a dataset, do not fail the operation
due to not finding the index on an NC.
- Ignore resource doesn't exist error code when attempting to
drop a dataset.
- Always invalidate the resource on a delete attempt from the
PersistentLocalResourceRepository cache.
- Start a new metadata transaction before attempting to execute
the drop dataset compensating operations.
Change-Id: I591b009f0ffdf348bcfe989424f47a20fff44a1b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/11644
Reviewed-by: Michael Blow <mblow@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 754e2b6..7ddf877 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -1704,7 +1704,7 @@
validateDatasetState(metadataProvider, ds, sourceLoc);
ds.drop(metadataProvider, mdTxnCtx, jobsToExecute, bActiveTxn, progress, hcc, dropCorrespondingNodeGroup,
- sourceLoc, Collections.emptySet(), requestParameters.isForceDropDataset());
+ sourceLoc, EnumSet.of(DropOption.IF_EXISTS), requestParameters.isForceDropDataset());
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue());
return true;
@@ -1720,6 +1720,10 @@
try {
if (ds != null) {
jobsToExecute.clear();
+ // start another txn for the compensating operations
+ mdTxnCtx.setValue(MetadataManager.INSTANCE.beginTransaction());
+ bActiveTxn.setValue(true);
+ metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue());
ds.drop(metadataProvider, mdTxnCtx, jobsToExecute, bActiveTxn, progress, hcc,
dropCorrespondingNodeGroup, sourceLoc, EnumSet.of(DropOption.IF_EXISTS),
requestParameters.isForceDropDataset());
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 508eb76..29dedf7 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
@@ -230,20 +230,21 @@
@Override
public synchronized void delete(String relativePath) throws HyracksDataException {
FileReference resourceFile = getLocalResourceFileByName(ioManager, relativePath);
- if (resourceFile.getFile().exists()) {
- if (isReplicationEnabled) {
- createReplicationJob(ReplicationOperation.DELETE, resourceFile);
+ try {
+ if (resourceFile.getFile().exists()) {
+ if (isReplicationEnabled) {
+ createReplicationJob(ReplicationOperation.DELETE, resourceFile);
+ }
+ final LocalResource localResource = readLocalResource(resourceFile.getFile());
+ 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);
}
- final LocalResource localResource = readLocalResource(resourceFile.getFile());
- // 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.
+ } finally {
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);
}
}
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDropOperatorNodePushable.java b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDropOperatorNodePushable.java
index e48db2b..3b6669e 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDropOperatorNodePushable.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/dataflow/IndexDropOperatorNodePushable.java
@@ -21,6 +21,7 @@
import static org.apache.hyracks.api.exceptions.ErrorCode.CANNOT_DROP_IN_USE_INDEX;
import static org.apache.hyracks.api.exceptions.ErrorCode.INDEX_DOES_NOT_EXIST;
+import static org.apache.hyracks.api.exceptions.ErrorCode.RESOURCE_DOES_NOT_EXIST;
import static org.apache.hyracks.storage.am.common.dataflow.IndexDropOperatorDescriptor.DropOption.IF_EXISTS;
import static org.apache.hyracks.storage.am.common.dataflow.IndexDropOperatorDescriptor.DropOption.WAIT_ON_IN_USE;
@@ -96,7 +97,7 @@
}
private boolean isIgnorable(HyracksDataException e) {
- return e.matches(INDEX_DOES_NOT_EXIST) && options.contains(IF_EXISTS);
+ return (e.matches(INDEX_DOES_NOT_EXIST) || e.matches(RESOURCE_DOES_NOT_EXIST)) && options.contains(IF_EXISTS);
}
private boolean canRetry(HyracksDataException e) throws HyracksDataException {