Search in sources :

Example 1 with OMVolumeSetQuotaResponse

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;
}
Also used : AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) OMVolumeSetQuotaResponse(org.apache.hadoop.ozone.om.response.volume.OMVolumeSetQuotaResponse) SetVolumePropertyRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyRequest) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager)

Aggregations

IOException (java.io.IOException)1 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)1 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMVolumeSetQuotaResponse (org.apache.hadoop.ozone.om.response.volume.OMVolumeSetQuotaResponse)1 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)1 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)1 SetVolumePropertyRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyRequest)1