Search in sources :

Example 1 with OMOpenKeysDeleteResponse

use of org.apache.hadoop.ozone.om.response.key.OMOpenKeysDeleteResponse in project ozone by apache.

the class OMOpenKeysDeleteRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long trxnLogIndex, OzoneManagerDoubleBufferHelper omDoubleBufferHelper) {
    OMMetrics omMetrics = ozoneManager.getMetrics();
    omMetrics.incNumOpenKeyDeleteRequests();
    OzoneManagerProtocolProtos.DeleteOpenKeysRequest deleteOpenKeysRequest = getOmRequest().getDeleteOpenKeysRequest();
    List<OpenKeyBucket> submittedOpenKeyBuckets = deleteOpenKeysRequest.getOpenKeysPerBucketList();
    long numSubmittedOpenKeys = 0;
    for (OpenKeyBucket keyBucket : submittedOpenKeyBuckets) {
        numSubmittedOpenKeys += keyBucket.getKeysCount();
    }
    LOG.debug("{} open keys submitted for deletion.", numSubmittedOpenKeys);
    omMetrics.incNumOpenKeysSubmittedForDeletion(numSubmittedOpenKeys);
    OzoneManagerProtocolProtos.OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
    IOException exception = null;
    OMClientResponse omClientResponse = null;
    Result result = null;
    Map<String, OmKeyInfo> deletedOpenKeys = new HashMap<>();
    try {
        for (OpenKeyBucket openKeyBucket : submittedOpenKeyBuckets) {
            // For each bucket where keys will be deleted from,
            // get its bucket lock and update the cache accordingly.
            Map<String, OmKeyInfo> deleted = updateOpenKeyTableCache(ozoneManager, trxnLogIndex, openKeyBucket);
            deletedOpenKeys.putAll(deleted);
        }
        omClientResponse = new OMOpenKeysDeleteResponse(omResponse.build(), deletedOpenKeys, ozoneManager.isRatisEnabled());
        result = Result.SUCCESS;
    } catch (IOException ex) {
        result = Result.FAILURE;
        exception = ex;
        omClientResponse = new OMOpenKeysDeleteResponse(createErrorOMResponse(omResponse, exception), getBucketLayout());
    } finally {
        addResponseToDoubleBuffer(trxnLogIndex, omClientResponse, omDoubleBufferHelper);
    }
    processResults(omMetrics, numSubmittedOpenKeys, deletedOpenKeys.size(), deleteOpenKeysRequest, result);
    return omClientResponse;
}
Also used : OMOpenKeysDeleteResponse(org.apache.hadoop.ozone.om.response.key.OMOpenKeysDeleteResponse) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) HashMap(java.util.HashMap) IOException(java.io.IOException) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) OpenKeyBucket(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKeyBucket)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)1 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)1 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)1 OMOpenKeysDeleteResponse (org.apache.hadoop.ozone.om.response.key.OMOpenKeysDeleteResponse)1 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)1 OpenKeyBucket (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OpenKeyBucket)1