use of org.apache.hadoop.ozone.audit.AuditLogger in project ozone by apache.
the class OMKeyRenameRequestWithFSO method validateAndUpdateCache.
@Override
@SuppressWarnings("methodlength")
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
RenameKeyRequest renameKeyRequest = getOmRequest().getRenameKeyRequest();
KeyArgs keyArgs = renameKeyRequest.getKeyArgs();
Map<String, String> auditMap = buildAuditMap(keyArgs, renameKeyRequest);
String volumeName = keyArgs.getVolumeName();
String bucketName = keyArgs.getBucketName();
String fromKeyName = keyArgs.getKeyName();
String toKeyName = renameKeyRequest.getToKeyName();
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumKeyRenames();
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
boolean acquiredLock = false;
OMClientResponse omClientResponse = null;
IOException exception = null;
OmKeyInfo fromKeyValue;
Result result;
try {
if (toKeyName.length() == 0 || fromKeyName.length() == 0) {
throw new OMException("Key name is empty", OMException.ResultCodes.INVALID_KEY_NAME);
}
keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
volumeName = keyArgs.getVolumeName();
bucketName = keyArgs.getBucketName();
// check Acls to see if user has access to perform delete operation on
// old key and create operation on new key
// check Acl fromKeyName
checkACLsWithFSO(ozoneManager, volumeName, bucketName, fromKeyName, IAccessAuthorizer.ACLType.DELETE);
// check Acl toKeyName
checkKeyAcls(ozoneManager, volumeName, bucketName, toKeyName, IAccessAuthorizer.ACLType.CREATE, OzoneObj.ResourceType.KEY);
acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
// Validate bucket and volume exists or not.
validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
// Check if fromKey exists
OzoneFileStatus fromKeyFileStatus = OMFileRequest.getOMKeyInfoIfExists(omMetadataManager, volumeName, bucketName, fromKeyName, 0);
// case-1) fromKeyName should exist, otw throws exception
if (fromKeyFileStatus == null) {
// TODO: Add support for renaming open key
throw new OMException("Key not found " + fromKeyName, KEY_NOT_FOUND);
}
// source existed
fromKeyValue = fromKeyFileStatus.getKeyInfo();
boolean isRenameDirectory = fromKeyFileStatus.isDirectory();
// case-2) Cannot rename a directory to its own subdirectory
OMFileRequest.verifyToDirIsASubDirOfFromDirectory(fromKeyName, toKeyName, fromKeyFileStatus.isDirectory());
OzoneFileStatus toKeyFileStatus = OMFileRequest.getOMKeyInfoIfExists(omMetadataManager, volumeName, bucketName, toKeyName, 0);
// Check if toKey exists.
if (toKeyFileStatus != null) {
// Destination exists and following are different cases:
OmKeyInfo toKeyValue = toKeyFileStatus.getKeyInfo();
if (fromKeyValue.getKeyName().equals(toKeyValue.getKeyName())) {
// TODO: Discuss do we need to throw exception for file as well.
if (toKeyFileStatus.isFile()) {
result = Result.SUCCESS;
} else {
throw new OMException("Key already exists " + toKeyName, OMException.ResultCodes.KEY_ALREADY_EXISTS);
}
} else if (toKeyFileStatus.isDirectory()) {
// case-4) If dst is a directory then rename source as sub-path of it
// For example: rename /source to /dst will lead to /dst/source
String fromFileName = OzoneFSUtils.getFileName(fromKeyName);
String newToKeyName = OzoneFSUtils.appendFileNameToKeyPath(toKeyName, fromFileName);
OzoneFileStatus newToOzoneFileStatus = OMFileRequest.getOMKeyInfoIfExists(omMetadataManager, volumeName, bucketName, newToKeyName, 0);
if (newToOzoneFileStatus != null) {
// case-5) If new destin '/dst/source' exists then throws exception
throw new OMException(String.format("Failed to rename %s to %s, file already exists or not " + "empty!", fromKeyName, newToKeyName), OMException.ResultCodes.KEY_ALREADY_EXISTS);
}
omClientResponse = renameKey(toKeyValue.getObjectID(), trxnLogIndex, fromKeyValue, isRenameDirectory, newToKeyName, keyArgs.getModificationTime(), omResponse, ozoneManager);
result = Result.SUCCESS;
} else {
// key already exists exception.
throw new OMException("Failed to rename, key already exists " + toKeyName, OMException.ResultCodes.KEY_ALREADY_EXISTS);
}
} else {
// Destination doesn't exist and the cases are:
// case-7) Check whether dst parent dir exists or not. If parent
// doesn't exist then throw exception, otw the source can be renamed to
// destination path.
long toKeyParentId = OMFileRequest.getToKeyNameParentId(volumeName, bucketName, toKeyName, fromKeyName, omMetadataManager);
omClientResponse = renameKey(toKeyParentId, trxnLogIndex, fromKeyValue, isRenameDirectory, toKeyName, keyArgs.getModificationTime(), omResponse, ozoneManager);
result = Result.SUCCESS;
}
} catch (IOException ex) {
result = Result.FAILURE;
exception = ex;
omClientResponse = new OMKeyRenameResponseWithFSO(createErrorOMResponse(omResponse, exception), getBucketLayout());
} finally {
addResponseToDoubleBuffer(trxnLogIndex, omClientResponse, omDoubleBufferHelper);
if (acquiredLock) {
omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, bucketName);
}
}
auditLog(auditLogger, buildAuditMessage(OMAction.RENAME_KEY, auditMap, exception, getOmRequest().getUserInfo()));
switch(result) {
case SUCCESS:
LOG.debug("Rename Key is successfully completed for volume:{} bucket:{}" + " fromKey:{} toKey:{}. ", volumeName, bucketName, fromKeyName, toKeyName);
break;
case FAILURE:
ozoneManager.getMetrics().incNumKeyRenameFails();
LOG.error("Rename key failed for volume:{} bucket:{} fromKey:{} " + "toKey:{}. Key: {} not found.", volumeName, bucketName, fromKeyName, toKeyName, fromKeyName);
break;
default:
LOG.error("Unrecognized Result for OMKeyRenameRequest: {}", renameKeyRequest);
}
return omClientResponse;
}
use of org.apache.hadoop.ozone.audit.AuditLogger in project ozone by apache.
the class OMDirectoryCreateRequestWithFSO method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
CreateDirectoryRequest createDirectoryRequest = getOmRequest().getCreateDirectoryRequest();
KeyArgs keyArgs = createDirectoryRequest.getKeyArgs();
String volumeName = keyArgs.getVolumeName();
String bucketName = keyArgs.getBucketName();
String keyName = keyArgs.getKeyName();
int numKeysCreated = 0;
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
omResponse.setCreateDirectoryResponse(CreateDirectoryResponse.newBuilder());
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumCreateDirectory();
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
boolean acquiredLock = false;
IOException exception = null;
OMClientResponse omClientResponse = null;
Result result = Result.FAILURE;
List<OmDirectoryInfo> missingParentInfos;
try {
keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
volumeName = keyArgs.getVolumeName();
bucketName = keyArgs.getBucketName();
// check Acl
checkKeyAcls(ozoneManager, volumeName, bucketName, keyName, IAccessAuthorizer.ACLType.CREATE, OzoneObj.ResourceType.KEY);
// Check if this is the root of the filesystem.
if (keyName.length() == 0) {
throw new OMException("Directory create failed. Cannot create " + "directory at root of the filesystem", OMException.ResultCodes.CANNOT_CREATE_DIRECTORY_AT_ROOT);
}
// acquire lock
acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
Path keyPath = Paths.get(keyName);
// Need to check if any files exist in the given path, if they exist we
// cannot create a directory with the given key.
// Verify the path against directory table
OMFileRequest.OMPathInfoWithFSO omPathInfo = OMFileRequest.verifyDirectoryKeysInPath(omMetadataManager, volumeName, bucketName, keyName, keyPath);
OMFileRequest.OMDirectoryResult omDirectoryResult = omPathInfo.getDirectoryResult();
if (omDirectoryResult == FILE_EXISTS || omDirectoryResult == FILE_EXISTS_IN_GIVENPATH) {
throw new OMException("Unable to create directory: " + keyName + " in volume/bucket: " + volumeName + "/" + bucketName + " as " + "file:" + omPathInfo.getFileExistsInPath() + " already exists", FILE_ALREADY_EXISTS);
} else if (omDirectoryResult == DIRECTORY_EXISTS_IN_GIVENPATH || omDirectoryResult == NONE) {
// prepare all missing parents
missingParentInfos = OMDirectoryCreateRequestWithFSO.getAllMissingParentDirInfo(ozoneManager, keyArgs, omPathInfo, trxnLogIndex);
// prepare leafNode dir
OmDirectoryInfo dirInfo = createDirectoryInfoWithACL(omPathInfo.getLeafNodeName(), keyArgs, omPathInfo.getLeafNodeObjectId(), omPathInfo.getLastKnownParentId(), trxnLogIndex, OzoneAclUtil.fromProtobuf(keyArgs.getAclsList()));
OMFileRequest.addDirectoryTableCacheEntries(omMetadataManager, Optional.of(dirInfo), Optional.of(missingParentInfos), trxnLogIndex);
// total number of keys created.
numKeysCreated = missingParentInfos.size() + 1;
result = OMDirectoryCreateRequest.Result.SUCCESS;
omClientResponse = new OMDirectoryCreateResponseWithFSO(omResponse.build(), dirInfo, missingParentInfos, result, getBucketLayout());
} else {
result = Result.DIRECTORY_ALREADY_EXISTS;
omResponse.setStatus(Status.DIRECTORY_ALREADY_EXISTS);
omClientResponse = new OMDirectoryCreateResponseWithFSO(omResponse.build(), result);
}
} catch (IOException ex) {
exception = ex;
omClientResponse = new OMDirectoryCreateResponseWithFSO(createErrorOMResponse(omResponse, exception), result);
} finally {
addResponseToDoubleBuffer(trxnLogIndex, omClientResponse, omDoubleBufferHelper);
if (acquiredLock) {
omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, bucketName);
}
}
auditLog(auditLogger, buildAuditMessage(OMAction.CREATE_DIRECTORY, auditMap, exception, userInfo));
logResult(createDirectoryRequest, keyArgs, omMetrics, numKeysCreated, result, exception);
return omClientResponse;
}
use of org.apache.hadoop.ozone.audit.AuditLogger in project ozone by apache.
the class OMAllocateBlockRequestWithFSO method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
AllocateBlockRequest allocateBlockRequest = getOmRequest().getAllocateBlockRequest();
KeyArgs keyArgs = allocateBlockRequest.getKeyArgs();
OzoneManagerProtocolProtos.KeyLocation blockLocation = allocateBlockRequest.getKeyLocation();
Preconditions.checkNotNull(blockLocation);
String volumeName = keyArgs.getVolumeName();
String bucketName = keyArgs.getBucketName();
String keyName = keyArgs.getKeyName();
long clientID = allocateBlockRequest.getClientID();
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumBlockAllocateCalls();
AuditLogger auditLogger = ozoneManager.getAuditLogger();
Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs);
auditMap.put(OzoneConsts.CLIENT_ID, String.valueOf(clientID));
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
String openKeyName = null;
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
OMClientResponse omClientResponse = null;
OmKeyInfo openKeyInfo = null;
IOException exception = null;
OmBucketInfo omBucketInfo = null;
boolean acquiredLock = false;
try {
keyArgs = resolveBucketLink(ozoneManager, keyArgs, auditMap);
volumeName = keyArgs.getVolumeName();
bucketName = keyArgs.getBucketName();
// check Acl
checkKeyAclsInOpenKeyTable(ozoneManager, volumeName, bucketName, keyName, IAccessAuthorizer.ACLType.WRITE, allocateBlockRequest.getClientID());
validateBucketAndVolume(omMetadataManager, volumeName, bucketName);
// Here we don't acquire bucket/volume lock because for a single client
// allocateBlock is called in serial fashion. With this approach, it
// won't make 'fail-fast' during race condition case on delete/rename op,
// assuming that later it will fail at the key commit operation.
openKeyName = getOpenKeyName(volumeName, bucketName, keyName, clientID, ozoneManager);
openKeyInfo = getOpenKeyInfo(omMetadataManager, openKeyName, keyName);
if (openKeyInfo == null) {
throw new OMException("Open Key not found " + openKeyName, KEY_NOT_FOUND);
}
List<OmKeyLocationInfo> newLocationList = Collections.singletonList(OmKeyLocationInfo.getFromProtobuf(blockLocation));
acquiredLock = omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK, volumeName, bucketName);
omBucketInfo = getBucketInfo(omMetadataManager, volumeName, bucketName);
// check bucket and volume quota
long preAllocatedSpace = newLocationList.size() * ozoneManager.getScmBlockSize() * openKeyInfo.getReplicationConfig().getRequiredNodes();
checkBucketQuotaInBytes(omBucketInfo, preAllocatedSpace);
// Append new block
openKeyInfo.appendNewBlocks(newLocationList, false);
// Set modification time.
openKeyInfo.setModificationTime(keyArgs.getModificationTime());
// Set the UpdateID to current transactionLogIndex
openKeyInfo.setUpdateID(trxnLogIndex, ozoneManager.isRatisEnabled());
// Add to cache.
addOpenTableCacheEntry(trxnLogIndex, omMetadataManager, openKeyName, openKeyInfo);
omBucketInfo.incrUsedBytes(preAllocatedSpace);
omResponse.setAllocateBlockResponse(AllocateBlockResponse.newBuilder().setKeyLocation(blockLocation).build());
omClientResponse = getOmClientResponse(clientID, omResponse, openKeyInfo, omBucketInfo.copyObject());
LOG.debug("Allocated block for Volume:{}, Bucket:{}, OpenKey:{}", volumeName, bucketName, openKeyName);
} catch (IOException ex) {
omMetrics.incNumBlockAllocateCallFails();
exception = ex;
omClientResponse = new OMAllocateBlockResponseWithFSO(createErrorOMResponse(omResponse, exception), getBucketLayout());
LOG.error("Allocate Block failed. Volume:{}, Bucket:{}, OpenKey:{}. " + "Exception:{}", volumeName, bucketName, openKeyName, exception);
} finally {
addResponseToDoubleBuffer(trxnLogIndex, omClientResponse, omDoubleBufferHelper);
if (acquiredLock) {
omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName, bucketName);
}
}
auditLog(auditLogger, buildAuditMessage(OMAction.ALLOCATE_BLOCK, auditMap, exception, getOmRequest().getUserInfo()));
return omClientResponse;
}
use of org.apache.hadoop.ozone.audit.AuditLogger in project ozone by apache.
the class OMVolumeSetQuotaRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
SetVolumePropertyRequest setVolumePropertyRequest = getOmRequest().getSetVolumePropertyRequest();
Preconditions.checkNotNull(setVolumePropertyRequest);
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
// when we have quota in bytes is set in setVolumePropertyRequest.
if (!setVolumePropertyRequest.hasQuotaInBytes()) {
omResponse.setStatus(OzoneManagerProtocolProtos.Status.INVALID_REQUEST).setSuccess(false);
return new OMVolumeSetQuotaResponse(omResponse.build());
}
String volume = setVolumePropertyRequest.getVolumeName();
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumVolumeUpdates();
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
Map<String, String> auditMap = buildVolumeAuditMap(volume);
auditMap.put(OzoneConsts.QUOTA_IN_BYTES, String.valueOf(setVolumePropertyRequest.getQuotaInBytes()));
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
IOException exception = null;
boolean acquireVolumeLock = false;
OMClientResponse omClientResponse = null;
try {
// check Acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE, volume, null, null);
}
acquireVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
OmVolumeArgs omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
if (checkQuotaBytesValid(omMetadataManager, setVolumePropertyRequest.getQuotaInBytes(), volume)) {
omVolumeArgs.setQuotaInBytes(setVolumePropertyRequest.getQuotaInBytes());
} else {
omVolumeArgs.setQuotaInBytes(omVolumeArgs.getQuotaInBytes());
}
if (checkQuotaNamespaceValid(setVolumePropertyRequest.getQuotaInNamespace())) {
omVolumeArgs.setQuotaInNamespace(setVolumePropertyRequest.getQuotaInNamespace());
} else {
omVolumeArgs.setQuotaInNamespace(omVolumeArgs.getQuotaInNamespace());
}
omVolumeArgs.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
omVolumeArgs.setModificationTime(setVolumePropertyRequest.getModificationTime());
// update cache.
omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volume)), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().build());
omClientResponse = new OMVolumeSetQuotaResponse(omResponse.build(), omVolumeArgs);
} catch (IOException ex) {
exception = ex;
omClientResponse = new OMVolumeSetQuotaResponse(createErrorOMResponse(omResponse, exception));
} finally {
addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
if (acquireVolumeLock) {
omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
}
}
// Performing audit logging outside of the lock.
auditLog(auditLogger, buildAuditMessage(OMAction.SET_QUOTA, auditMap, exception, userInfo));
// return response after releasing lock.
if (exception == null) {
LOG.debug("Changing volume quota is successfully completed for volume: " + "{} quota:{}", volume, setVolumePropertyRequest.getQuotaInBytes());
} else {
omMetrics.incNumVolumeUpdateFails();
LOG.error("Changing volume quota failed for volume:{} quota:{}", volume, setVolumePropertyRequest.getQuotaInBytes(), exception);
}
return omClientResponse;
}
use of org.apache.hadoop.ozone.audit.AuditLogger in project ozone by apache.
the class OMVolumeSetOwnerRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
SetVolumePropertyRequest setVolumePropertyRequest = getOmRequest().getSetVolumePropertyRequest();
Preconditions.checkNotNull(setVolumePropertyRequest);
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
// when we have ownerName in setVolumePropertyRequest.
if (!setVolumePropertyRequest.hasOwnerName()) {
omResponse.setStatus(OzoneManagerProtocolProtos.Status.INVALID_REQUEST).setSuccess(false);
return new OMVolumeSetOwnerResponse(omResponse.build());
}
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumVolumeUpdates();
String volume = setVolumePropertyRequest.getVolumeName();
String newOwner = setVolumePropertyRequest.getOwnerName();
AuditLogger auditLogger = ozoneManager.getAuditLogger();
OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
Map<String, String> auditMap = buildVolumeAuditMap(volume);
auditMap.put(OzoneConsts.OWNER, newOwner);
boolean acquiredUserLocks = false;
boolean acquiredVolumeLock = false;
IOException exception = null;
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
String oldOwner = null;
OMClientResponse omClientResponse = null;
try {
// check Acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volume, null, null);
}
long maxUserVolumeCount = ozoneManager.getMaxUserVolumeCount();
OzoneManagerStorageProtos.PersistedUserVolumeInfo oldOwnerVolumeList;
OzoneManagerStorageProtos.PersistedUserVolumeInfo newOwnerVolumeList;
OmVolumeArgs omVolumeArgs = null;
acquiredVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
oldOwner = omVolumeArgs.getOwnerName();
// Return OK immediately if newOwner is the same as oldOwner.
if (oldOwner.equals(newOwner)) {
LOG.warn("Volume '{}' owner is already user '{}'.", volume, oldOwner);
omResponse.setStatus(OzoneManagerProtocolProtos.Status.OK).setMessage("Volume '" + volume + "' owner is already '" + newOwner + "'.").setSuccess(false);
omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().setResponse(false).build());
omClientResponse = new OMVolumeSetOwnerResponse(omResponse.build());
// Note: addResponseToDoubleBuffer would be executed in finally block.
return omClientResponse;
}
acquiredUserLocks = omMetadataManager.getLock().acquireMultiUserLock(newOwner, oldOwner);
oldOwnerVolumeList = omMetadataManager.getUserTable().get(oldOwner);
oldOwnerVolumeList = delVolumeFromOwnerList(oldOwnerVolumeList, volume, oldOwner, transactionLogIndex);
newOwnerVolumeList = omMetadataManager.getUserTable().get(newOwner);
newOwnerVolumeList = addVolumeToOwnerList(newOwnerVolumeList, volume, newOwner, maxUserVolumeCount, transactionLogIndex);
// Set owner with new owner name.
omVolumeArgs.setOwnerName(newOwner);
omVolumeArgs.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
// Update modificationTime.
omVolumeArgs.setModificationTime(setVolumePropertyRequest.getModificationTime());
// Update cache.
omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(omMetadataManager.getUserKey(newOwner)), new CacheValue<>(Optional.of(newOwnerVolumeList), transactionLogIndex));
omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(omMetadataManager.getUserKey(oldOwner)), new CacheValue<>(Optional.of(oldOwnerVolumeList), transactionLogIndex));
omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volume)), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().setResponse(true).build());
omClientResponse = new OMVolumeSetOwnerResponse(omResponse.build(), oldOwner, oldOwnerVolumeList, newOwnerVolumeList, omVolumeArgs);
} catch (IOException ex) {
exception = ex;
omClientResponse = new OMVolumeSetOwnerResponse(createErrorOMResponse(omResponse, exception));
} finally {
addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
if (acquiredUserLocks) {
omMetadataManager.getLock().releaseMultiUserLock(newOwner, oldOwner);
}
if (acquiredVolumeLock) {
omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
}
}
// Performing audit logging outside of the lock.
auditLog(auditLogger, buildAuditMessage(OMAction.SET_OWNER, auditMap, exception, userInfo));
// return response after releasing lock.
if (exception == null) {
LOG.debug("Successfully changed Owner of Volume {} from {} -> {}", volume, oldOwner, newOwner);
} else {
LOG.error("Changing volume ownership failed for user:{} volume:{}", newOwner, volume, exception);
omMetrics.incNumVolumeUpdateFails();
}
return omClientResponse;
}
Aggregations