use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteKeyRequest in project ozone by apache.
the class OMKeyDeleteRequest method preExecute.
@Override
public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
DeleteKeyRequest deleteKeyRequest = getOmRequest().getDeleteKeyRequest();
Preconditions.checkNotNull(deleteKeyRequest);
OzoneManagerProtocolProtos.KeyArgs keyArgs = deleteKeyRequest.getKeyArgs();
String keyPath = keyArgs.getKeyName();
keyPath = validateAndNormalizeKey(ozoneManager.getEnableFileSystemPaths(), keyPath, getBucketLayout());
OzoneManagerProtocolProtos.KeyArgs.Builder newKeyArgs = keyArgs.toBuilder().setModificationTime(Time.now()).setKeyName(keyPath);
return getOmRequest().toBuilder().setDeleteKeyRequest(deleteKeyRequest.toBuilder().setKeyArgs(newKeyArgs)).setUserInfo(getUserIfNotExists(ozoneManager)).build();
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteKeyRequest in project ozone by apache.
the class OMKeyDeleteRequest method validateAndUpdateCache.
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper, BucketLayout bucketLayout) {
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;
OmBucketInfo omBucketInfo = OmBucketInfo.newBuilder().setVolumeName(volumeName).setBucketName(bucketName).setCreationTime(Time.now()).setBucketLayout(bucketLayout).build();
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);
String objectKey = omMetadataManager.getOzoneKey(volumeName, bucketName, keyName);
acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
// Validate bucket and volume exists or not.
validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
OmKeyInfo omKeyInfo = omMetadataManager.getKeyTable(bucketLayout).get(objectKey);
if (omKeyInfo == null) {
throw new OMException("Key not found", KEY_NOT_FOUND);
}
// Set the UpdateID to current transactionLogIndex
omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
// Update table cache.
omMetadataManager.getKeyTable(getBucketLayout()).addCacheEntry(new CacheKey<>(omMetadataManager.getOzoneKey(volumeName, bucketName, keyName)), new CacheValue<>(Optional.absent(), trxnLogIndex));
omBucketInfo = getBucketInfo(omMetadataManager, volumeName, bucketName);
long quotaReleased = sumBlockLengths(omKeyInfo);
omBucketInfo.incrUsedBytes(-quotaReleased);
omBucketInfo.incrUsedNamespace(-1L);
// 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 OMKeyDeleteResponse(omResponse.setDeleteKeyResponse(DeleteKeyResponse.newBuilder()).build(), omKeyInfo, ozoneManager.isRatisEnabled(), omBucketInfo.copyObject());
result = Result.SUCCESS;
} catch (IOException ex) {
result = Result.FAILURE;
exception = ex;
omClientResponse = new OMKeyDeleteResponse(createErrorOMResponse(omResponse, exception), getBucketLayout());
} 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;
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteKeyRequest in project ozone by apache.
the class TestOMKeyDeleteRequest method createDeleteKeyRequest.
/**
* Create OMRequest which encapsulates DeleteKeyRequest.
* @return OMRequest
*/
private OMRequest createDeleteKeyRequest() {
KeyArgs keyArgs = KeyArgs.newBuilder().setBucketName(bucketName).setVolumeName(volumeName).setKeyName(keyName).build();
DeleteKeyRequest deleteKeyRequest = DeleteKeyRequest.newBuilder().setKeyArgs(keyArgs).build();
return OMRequest.newBuilder().setDeleteKeyRequest(deleteKeyRequest).setCmdType(OzoneManagerProtocolProtos.Type.DeleteKey).setClientId(UUID.randomUUID().toString()).build();
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DeleteKeyRequest in project ozone by apache.
the class OMKeyDeleteRequestWithFSO method validateAndUpdateCache.
@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();
boolean recursive = keyArgs.getRecursive();
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;
OmBucketInfo omBucketInfo = null;
try {
keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
volumeName = keyArgs.getVolumeName();
bucketName = keyArgs.getBucketName();
checkACLsWithFSO(ozoneManager, volumeName, bucketName, keyName, IAccessAuthorizer.ACLType.DELETE);
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:" + keyName, KEY_NOT_FOUND);
}
OmKeyInfo omKeyInfo = keyStatus.getKeyInfo();
// New key format for the fileTable & dirTable.
// For example, the user given key path is '/a/b/c/d/e/file1', then in DB
// keyName field stores only the leaf node name, which is 'file1'.
String fileName = OzoneFSUtils.getFileName(keyName);
omKeyInfo.setKeyName(fileName);
// Set the UpdateID to current transactionLogIndex
omKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
String ozonePathKey = omMetadataManager.getOzonePathKey(omKeyInfo.getParentObjectID(), omKeyInfo.getFileName());
if (keyStatus.isDirectory()) {
// Check if there are any sub path exists under the user requested path
if (!recursive && OMFileRequest.hasChildren(omKeyInfo, omMetadataManager)) {
throw new OMException("Directory is not empty. Key:" + keyName, DIRECTORY_NOT_EMPTY);
}
// Update dir cache.
omMetadataManager.getDirectoryTable().addCacheEntry(new CacheKey<>(ozonePathKey), new CacheValue<>(Optional.absent(), trxnLogIndex));
} else {
// Update table cache.
omMetadataManager.getKeyTable(getBucketLayout()).addCacheEntry(new CacheKey<>(ozonePathKey), new CacheValue<>(Optional.absent(), trxnLogIndex));
}
omBucketInfo = getBucketInfo(omMetadataManager, volumeName, bucketName);
// TODO: HDDS-4565: consider all the sub-paths if the path is a dir.
long quotaReleased = sumBlockLengths(omKeyInfo);
omBucketInfo.incrUsedBytes(-quotaReleased);
omBucketInfo.incrUsedNamespace(-1L);
// 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 OMKeyDeleteResponseWithFSO(omResponse.setDeleteKeyResponse(DeleteKeyResponse.newBuilder()).build(), keyName, omKeyInfo, ozoneManager.isRatisEnabled(), omBucketInfo.copyObject(), keyStatus.isDirectory());
result = Result.SUCCESS;
} catch (IOException ex) {
result = Result.FAILURE;
exception = ex;
omClientResponse = new OMKeyDeleteResponseWithFSO(createErrorOMResponse(omResponse, exception), getBucketLayout());
} 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;
}
Aggregations