use of org.apache.hadoop.ozone.om.response.volume.OMVolumeSetQuotaResponse 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;
}
Aggregations