-
Notifications
You must be signed in to change notification settings - Fork 626
HDDS-4358: Delete : make delete an atomic operation #1607
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
215c834
HDDS-4358: Delete : make delete an atomic operation
rakeshadr 70b8155
Fixed code review comments - recursive delete, exception handling etc
rakeshadr 7a1bcf4
Fixed checkstyle warnings
rakeshadr 2ce728f
Fixed review comments. Added DeleteRequest and DeleteResponse
rakeshadr 13fb63c
Fixed checkstyle warnings
rakeshadr 8fb5954
Fixed checkstyle warning - hides a field
rakeshadr 20f7aea
Removed unused import
rakeshadr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
...ne-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyDeleteRequestV1.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| /** | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.hadoop.ozone.om.request.key; | ||
|
|
||
| import com.google.common.base.Optional; | ||
| import org.apache.hadoop.hdds.utils.db.cache.CacheKey; | ||
| import org.apache.hadoop.hdds.utils.db.cache.CacheValue; | ||
| import org.apache.hadoop.ozone.audit.AuditLogger; | ||
| import org.apache.hadoop.ozone.audit.OMAction; | ||
| import org.apache.hadoop.ozone.om.OMMetadataManager; | ||
| import org.apache.hadoop.ozone.om.OMMetrics; | ||
| import org.apache.hadoop.ozone.om.OzoneManager; | ||
| import org.apache.hadoop.ozone.om.exceptions.OMException; | ||
| import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs; | ||
| import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus; | ||
| import org.apache.hadoop.ozone.om.ratis.utils.OzoneManagerDoubleBufferHelper; | ||
| import org.apache.hadoop.ozone.om.request.file.OMFileRequest; | ||
| import org.apache.hadoop.ozone.om.request.util.OmResponseUtil; | ||
| import org.apache.hadoop.ozone.om.response.OMClientResponse; | ||
| import org.apache.hadoop.ozone.om.response.key.OMKeyDeleteResponseV1; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteKeyRequest; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteKeyResponse; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse; | ||
| import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer; | ||
| import org.apache.hadoop.ozone.security.acl.OzoneObj; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND; | ||
| import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.BUCKET_LOCK; | ||
|
|
||
| /** | ||
| * Handles DeleteKey request layout version V1. | ||
| */ | ||
| public class OMKeyDeleteRequestV1 extends OMKeyDeleteRequest { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(OMKeyDeleteRequestV1.class); | ||
|
|
||
| public OMKeyDeleteRequestV1(OMRequest omRequest) { | ||
| super(omRequest); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("methodlength") | ||
| public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, | ||
| long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) { | ||
| DeleteKeyRequest deleteKeyRequest = getOmRequest().getDeleteKeyRequest(); | ||
|
|
||
| OzoneManagerProtocolProtos.KeyArgs keyArgs = | ||
| deleteKeyRequest.getKeyArgs(); | ||
| Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs); | ||
|
|
||
| String volumeName = keyArgs.getVolumeName(); | ||
| String bucketName = keyArgs.getBucketName(); | ||
| String keyName = keyArgs.getKeyName(); | ||
|
|
||
| OMMetrics omMetrics = ozoneManager.getMetrics(); | ||
| omMetrics.incNumKeyDeletes(); | ||
|
|
||
| AuditLogger auditLogger = ozoneManager.getAuditLogger(); | ||
| OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo(); | ||
|
|
||
| OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder( | ||
| getOmRequest()); | ||
| OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager(); | ||
| IOException exception = null; | ||
| boolean acquiredLock = false; | ||
| OMClientResponse omClientResponse = null; | ||
| Result result = null; | ||
| OmVolumeArgs omVolumeArgs = null; | ||
| OmBucketInfo omBucketInfo = null; | ||
| try { | ||
| keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap); | ||
| volumeName = keyArgs.getVolumeName(); | ||
| bucketName = keyArgs.getBucketName(); | ||
|
|
||
| // check Acl | ||
| checkKeyAcls(ozoneManager, volumeName, bucketName, keyName, | ||
| IAccessAuthorizer.ACLType.DELETE, OzoneObj.ResourceType.KEY); | ||
|
|
||
| acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, | ||
| volumeName, bucketName); | ||
|
|
||
| // Validate bucket and volume exists or not. | ||
| validateBucketAndVolume(omMetadataManager, volumeName, bucketName); | ||
|
|
||
| OzoneFileStatus keyStatus = | ||
| OMFileRequest.getOMKeyInfoIfExists(omMetadataManager, volumeName, | ||
| bucketName, keyName, 0); | ||
|
|
||
| if (keyStatus == null) { | ||
| throw new OMException("Key not found", KEY_NOT_FOUND); | ||
|
rakeshadr marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| OmKeyInfo omKeyInfo = keyStatus.getKeyInfo(); | ||
|
|
||
| // Set the UpdateID to current transactionLogIndex | ||
| omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled()); | ||
|
|
||
| String ozonePathKey = omMetadataManager.getOzonePathKey( | ||
| omKeyInfo.getParentObjectID(), omKeyInfo.getFileName()); | ||
|
|
||
| if (keyStatus.isDirectory()) { | ||
| // Update dir cache. | ||
| omMetadataManager.getDirectoryTable().addCacheEntry( | ||
| new CacheKey<>(ozonePathKey), | ||
| new CacheValue<>(Optional.absent(), trxnLogIndex)); | ||
| } else { | ||
| // Update table cache. | ||
| omMetadataManager.getKeyTable().addCacheEntry( | ||
| new CacheKey<>(ozonePathKey), | ||
| new CacheValue<>(Optional.absent(), trxnLogIndex)); | ||
| } | ||
|
|
||
| omVolumeArgs = getVolumeInfo(omMetadataManager, volumeName); | ||
| omBucketInfo = getBucketInfo(omMetadataManager, volumeName, bucketName); | ||
|
|
||
| long quotaReleased = sumBlockLengths(omKeyInfo); | ||
|
rakeshadr marked this conversation as resolved.
|
||
| // update usedBytes atomically. | ||
| omVolumeArgs.getUsedBytes().add(-quotaReleased); | ||
| omBucketInfo.getUsedBytes().add(-quotaReleased); | ||
|
|
||
| // No need to add cache entries to delete table. As delete table will | ||
| // be used by DeleteKeyService only, not used for any client response | ||
| // validation, so we don't need to add to cache. | ||
| // TODO: Revisit if we need it later. | ||
|
|
||
| omClientResponse = new OMKeyDeleteResponseV1(omResponse | ||
| .setDeleteKeyResponse(DeleteKeyResponse.newBuilder()).build(), | ||
| omKeyInfo, ozoneManager.isRatisEnabled(), omVolumeArgs, | ||
| omBucketInfo, keyStatus.isDirectory()); | ||
|
|
||
| result = Result.SUCCESS; | ||
| } catch (IOException ex) { | ||
| result = Result.FAILURE; | ||
| exception = ex; | ||
| omClientResponse = new OMKeyDeleteResponseV1( | ||
| createErrorOMResponse(omResponse, exception)); | ||
| } finally { | ||
| addResponseToDoubleBuffer(trxnLogIndex, omClientResponse, | ||
| omDoubleBufferHelper); | ||
| if (acquiredLock) { | ||
| omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, | ||
| bucketName); | ||
| } | ||
| } | ||
|
|
||
| // Performing audit logging outside of the lock. | ||
| auditLog(auditLogger, buildAuditMessage(OMAction.DELETE_KEY, auditMap, | ||
| exception, userInfo)); | ||
|
|
||
|
|
||
| switch (result) { | ||
| case SUCCESS: | ||
| omMetrics.decNumKeys(); | ||
| LOG.debug("Key deleted. Volume:{}, Bucket:{}, Key:{}", volumeName, | ||
| bucketName, keyName); | ||
| break; | ||
| case FAILURE: | ||
| omMetrics.incNumKeyDeleteFails(); | ||
| LOG.error("Key delete failed. Volume:{}, Bucket:{}, Key:{}.", | ||
| volumeName, bucketName, keyName, exception); | ||
| break; | ||
| default: | ||
| LOG.error("Unrecognized Result for OMKeyDeleteRequest: {}", | ||
| deleteKeyRequest); | ||
| } | ||
|
|
||
| return omClientResponse; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.