use of org.apache.hadoop.ozone.om.response.volume.OMVolumeDeleteResponse in project ozone by apache.
the class OMVolumeDeleteRequest method validateAndUpdateCache.
@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
DeleteVolumeRequest deleteVolumeRequest = getOmRequest().getDeleteVolumeRequest();
Preconditions.checkNotNull(deleteVolumeRequest);
String volume = deleteVolumeRequest.getVolumeName();
OMMetrics omMetrics = ozoneManager.getMetrics();
omMetrics.incNumVolumeDeletes();
OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
boolean acquiredUserLock = false;
boolean acquiredVolumeLock = false;
IOException exception = null;
String owner = null;
OMClientResponse omClientResponse = null;
try {
// check Acl
if (ozoneManager.getAclsEnabled()) {
checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.DELETE, volume, null, null);
}
acquiredVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
OmVolumeArgs omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
// Check reference count
final long volRefCount = omVolumeArgs.getRefCount();
if (volRefCount != 0L) {
LOG.debug("volume: {} has a non-zero ref count. won't delete", volume);
throw new OMException("Volume reference count is not zero (" + volRefCount + "). Ozone features are enabled on this volume. " + "Try `ozone tenant delete <tenantId>` first.", OMException.ResultCodes.VOLUME_IS_REFERENCED);
}
owner = omVolumeArgs.getOwnerName();
acquiredUserLock = omMetadataManager.getLock().acquireWriteLock(USER_LOCK, owner);
String dbUserKey = omMetadataManager.getUserKey(owner);
String dbVolumeKey = omMetadataManager.getVolumeKey(volume);
if (!omMetadataManager.isVolumeEmpty(volume)) {
LOG.debug("volume:{} is not empty", volume);
throw new OMException(OMException.ResultCodes.VOLUME_NOT_EMPTY);
}
OzoneManagerStorageProtos.PersistedUserVolumeInfo newVolumeList = omMetadataManager.getUserTable().get(owner);
// delete the volume from the owner list
// as well as delete the volume entry
newVolumeList = delVolumeFromOwnerList(newVolumeList, volume, owner, transactionLogIndex);
omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(dbUserKey), new CacheValue<>(Optional.of(newVolumeList), transactionLogIndex));
omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(dbVolumeKey), new CacheValue<>(Optional.absent(), transactionLogIndex));
omResponse.setDeleteVolumeResponse(DeleteVolumeResponse.newBuilder().build());
omClientResponse = new OMVolumeDeleteResponse(omResponse.build(), volume, owner, newVolumeList);
} catch (IOException ex) {
exception = ex;
omClientResponse = new OMVolumeDeleteResponse(createErrorOMResponse(omResponse, exception));
} finally {
addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
if (acquiredUserLock) {
omMetadataManager.getLock().releaseWriteLock(USER_LOCK, owner);
}
if (acquiredVolumeLock) {
omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
}
}
// Performing audit logging outside of the lock.
auditLog(ozoneManager.getAuditLogger(), buildAuditMessage(OMAction.DELETE_VOLUME, buildVolumeAuditMap(volume), exception, getOmRequest().getUserInfo()));
// return response after releasing lock.
if (exception == null) {
LOG.debug("Volume deleted for user:{} volume:{}", owner, volume);
omMetrics.decNumVolumes();
} else {
LOG.error("Volume deletion failed for user:{} volume:{}", owner, volume, exception);
omMetrics.incNumVolumeDeleteFails();
}
return omClientResponse;
}
Aggregations