Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11238. Converge redundant getBucket calls for FileSystem client delete #6991

Merged
merged 8 commits into from
Jul 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OFS_URI_SCHEME;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_EMPTY;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_EMPTY;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_FOUND;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;

/**
* The minimal Rooted Ozone Filesystem implementation.
Expand Down Expand Up @@ -768,13 +770,25 @@ private boolean deleteInSpan(Path f, boolean recursive) throws IOException {

private boolean deleteBucket(Path f, boolean recursive, OFSPath ofsPath)
throws IOException {
OzoneBucket bucket;
try {
bucket = adapterImpl.getBucket(ofsPath, false);
} catch (OMException ex) {
if (ex.getResult() != BUCKET_NOT_FOUND && ex.getResult() != VOLUME_NOT_FOUND) {
LOG.error("OMException while getting bucket information, considered it as false", ex);
}
return false;
} catch (Exception ex) {
ArafatKhan2198 marked this conversation as resolved.
Show resolved Hide resolved
LOG.error("Exception while getting bucket information, considered it as false", ex);
return false;
}
// check status of normal bucket
try {
getFileStatus(f);
} catch (FileNotFoundException ex) {
// remove orphan link bucket directly
if (isLinkBucket(f, ofsPath)) {
deleteBucketFromVolume(f, ofsPath);
if (bucket.isLink()) {
deleteBucketFromVolume(f, bucket);
return true;
}
LOG.warn("delete: Path does not exist: {}", f);
Expand All @@ -787,8 +801,8 @@ private boolean deleteBucket(Path f, boolean recursive, OFSPath ofsPath)
boolean handleTrailingSlash = f.toString().endsWith(OZONE_URI_DELIMITER);
// remove link bucket directly if link and
// rm path does not have trailing slash
if (isLinkBucket(f, ofsPath) && !handleTrailingSlash) {
deleteBucketFromVolume(f, ofsPath);
if (bucket.isLink() && !handleTrailingSlash) {
deleteBucketFromVolume(f, bucket);
return true;
}

Expand All @@ -799,31 +813,17 @@ private boolean deleteBucket(Path f, boolean recursive, OFSPath ofsPath)
// if so, the contents of bucket were deleted and skip delete bucket
// otherwise, Handle delete bucket
if (!handleTrailingSlash) {
deleteBucketFromVolume(f, ofsPath);
deleteBucketFromVolume(f, bucket);
}
return result;
}

private boolean isLinkBucket(Path f, OFSPath ofsPath) {
try {
OzoneBucket bucket = adapterImpl.getBucket(ofsPath, false);
if (bucket.isLink()) {
return true;
}
} catch (Exception ex) {
LOG.error("Exception while getting bucket link information, " +
"considered it as false", ex);
return false;
}
return false;
}

private void deleteBucketFromVolume(Path f, OFSPath ofsPath)
private void deleteBucketFromVolume(Path f, OzoneBucket bucket)
throws IOException {
OzoneVolume volume =
adapterImpl.getObjectStore().getVolume(ofsPath.getVolumeName());
adapterImpl.getObjectStore().getVolume(bucket.getVolumeName());
try {
volume.deleteBucket(ofsPath.getBucketName());
volume.deleteBucket(bucket.getName());
} catch (OMException ex) {
// bucket is not empty
if (ex.getResult() == BUCKET_NOT_EMPTY) {
Expand Down