Search in sources :

Example 1 with PrepareStatusResponse

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse in project ozone by apache.

the class PrepareSubCommand method call.

@Override
public Void call() throws Exception {
    OzoneManagerProtocol client = parent.createOmClient(omServiceId);
    long prepareTxnId = client.prepareOzoneManager(txnApplyWaitTimeSeconds, txnApplyCheckIntervalSeconds);
    System.out.println("Ozone Manager Prepare Request successfully returned " + "with Transaction Id : [" + prepareTxnId + "].");
    Map<String, Boolean> omPreparedStatusMap = new HashMap<>();
    Set<String> omHosts = getOmHostsFromConfig(parent.getParent().getOzoneConf(), omServiceId);
    omHosts.forEach(h -> omPreparedStatusMap.put(h, false));
    Duration pTimeout = Duration.of(prepareTimeOut, ChronoUnit.SECONDS);
    Duration pInterval = Duration.of(prepareCheckInterval, ChronoUnit.SECONDS);
    System.out.println();
    System.out.println("Checking individual OM instances for prepare request " + "completion...");
    long endTime = System.currentTimeMillis() + pTimeout.toMillis();
    int expectedNumPreparedOms = omPreparedStatusMap.size();
    int currentNumPreparedOms = 0;
    while (System.currentTimeMillis() < endTime && currentNumPreparedOms < expectedNumPreparedOms) {
        for (Map.Entry<String, Boolean> e : omPreparedStatusMap.entrySet()) {
            if (!e.getValue()) {
                String omHost = e.getKey();
                try (OzoneManagerProtocol singleOmClient = parent.createOmClient(omServiceId, omHost, false)) {
                    PrepareStatusResponse response = singleOmClient.getOzoneManagerPrepareStatus(prepareTxnId);
                    PrepareStatus status = response.getStatus();
                    System.out.println("OM : [" + omHost + "], Prepare " + "Status : [" + status.name() + "], Current Transaction Id : [" + response.getCurrentTxnIndex() + "]");
                    if (status.equals(PREPARE_COMPLETED)) {
                        e.setValue(true);
                        currentNumPreparedOms++;
                    }
                } catch (IOException ioEx) {
                    System.out.println("Exception while checking preparation " + "completeness for [" + omHost + "], Error : [" + ioEx.getMessage() + "]");
                }
            }
        }
        if (currentNumPreparedOms < expectedNumPreparedOms) {
            System.out.println("Waiting for " + prepareCheckInterval + " seconds before retrying...");
            Thread.sleep(pInterval.toMillis());
        }
    }
    if (currentNumPreparedOms < (expectedNumPreparedOms + 1) / 2) {
        throw new Exception("OM Preparation failed since a majority OMs are not" + " prepared yet.");
    } else {
        System.out.println();
        System.out.println("OM Preparation successful! ");
        if (currentNumPreparedOms == expectedNumPreparedOms) {
            System.out.println("All OMs are prepared");
        } else {
            System.out.println("A majority of OMs are prepared. OMs that are not " + "prepared : " + omPreparedStatusMap.entrySet().stream().filter(e -> !e.getValue()).map(e -> e.getKey()).collect(Collectors.joining()));
        }
        System.out.println("No new write requests will be allowed until " + "preparation is cancelled or upgrade/downgrade is done.");
    }
    return null;
}
Also used : HddsVersionProvider(org.apache.hadoop.hdds.cli.HddsVersionProvider) OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol) Set(java.util.Set) OmUtils.getOmHostsFromConfig(org.apache.hadoop.ozone.OmUtils.getOmHostsFromConfig) IOException(java.io.IOException) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Collectors(java.util.stream.Collectors) ChronoUnit(java.time.temporal.ChronoUnit) PREPARE_COMPLETED(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_COMPLETED) Duration(java.time.Duration) Map(java.util.Map) PrepareStatusResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse) PrepareStatus(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus) CommandLine(picocli.CommandLine) OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol) HashMap(java.util.HashMap) Duration(java.time.Duration) IOException(java.io.IOException) IOException(java.io.IOException) PrepareStatus(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus) HashMap(java.util.HashMap) Map(java.util.Map) PrepareStatusResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse)

Example 2 with PrepareStatusResponse

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse in project ozone by apache.

the class OzoneManagerProtocolClientSideTranslatorPB method getOzoneManagerPrepareStatus.

@Override
public PrepareStatusResponse getOzoneManagerPrepareStatus(long txnId) throws IOException {
    PrepareStatusRequest prepareStatusRequest = PrepareStatusRequest.newBuilder().setTxnID(txnId).build();
    OMRequest omRequest = createOMRequest(Type.PrepareStatus).setPrepareStatusRequest(prepareStatusRequest).build();
    PrepareStatusResponse prepareStatusResponse = handleError(submitRequest(omRequest)).getPrepareStatusResponse();
    return prepareStatusResponse;
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) PrepareStatusRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusRequest) PrepareStatusResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse)

Example 3 with PrepareStatusResponse

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse in project ozone by apache.

the class OzoneManagerRequestHandler method handleReadRequest.

// TODO simplify it to make it shorter
@SuppressWarnings("methodlength")
@Override
public OMResponse handleReadRequest(OMRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Received OMRequest: {}, ", request);
    }
    Type cmdType = request.getCmdType();
    OMResponse.Builder responseBuilder = OmResponseUtil.getOMResponseBuilder(request);
    try {
        switch(cmdType) {
            case CheckVolumeAccess:
                CheckVolumeAccessResponse checkVolumeAccessResponse = checkVolumeAccess(request.getCheckVolumeAccessRequest());
                responseBuilder.setCheckVolumeAccessResponse(checkVolumeAccessResponse);
                break;
            case InfoVolume:
                InfoVolumeResponse infoVolumeResponse = infoVolume(request.getInfoVolumeRequest());
                responseBuilder.setInfoVolumeResponse(infoVolumeResponse);
                break;
            case ListVolume:
                ListVolumeResponse listVolumeResponse = listVolumes(request.getListVolumeRequest());
                responseBuilder.setListVolumeResponse(listVolumeResponse);
                break;
            case InfoBucket:
                InfoBucketResponse infoBucketResponse = infoBucket(request.getInfoBucketRequest());
                responseBuilder.setInfoBucketResponse(infoBucketResponse);
                break;
            case ListBuckets:
                ListBucketsResponse listBucketsResponse = listBuckets(request.getListBucketsRequest());
                responseBuilder.setListBucketsResponse(listBucketsResponse);
                break;
            case LookupKey:
                LookupKeyResponse lookupKeyResponse = lookupKey(request.getLookupKeyRequest(), request.getVersion());
                responseBuilder.setLookupKeyResponse(lookupKeyResponse);
                break;
            case ListKeys:
                ListKeysResponse listKeysResponse = listKeys(request.getListKeysRequest(), request.getVersion());
                responseBuilder.setListKeysResponse(listKeysResponse);
                break;
            case ListTrash:
                ListTrashResponse listTrashResponse = listTrash(request.getListTrashRequest(), request.getVersion());
                responseBuilder.setListTrashResponse(listTrashResponse);
                break;
            case ListMultiPartUploadParts:
                MultipartUploadListPartsResponse listPartsResponse = listParts(request.getListMultipartUploadPartsRequest());
                responseBuilder.setListMultipartUploadPartsResponse(listPartsResponse);
                break;
            case ListMultipartUploads:
                ListMultipartUploadsResponse response = listMultipartUploads(request.getListMultipartUploadsRequest());
                responseBuilder.setListMultipartUploadsResponse(response);
                break;
            case ServiceList:
                ServiceListResponse serviceListResponse = getServiceList(request.getServiceListRequest());
                responseBuilder.setServiceListResponse(serviceListResponse);
                break;
            case DBUpdates:
                DBUpdatesResponse dbUpdatesResponse = getOMDBUpdates(request.getDbUpdatesRequest());
                responseBuilder.setDbUpdatesResponse(dbUpdatesResponse);
                break;
            case GetFileStatus:
                GetFileStatusResponse getFileStatusResponse = getOzoneFileStatus(request.getGetFileStatusRequest(), request.getVersion());
                responseBuilder.setGetFileStatusResponse(getFileStatusResponse);
                break;
            case LookupFile:
                LookupFileResponse lookupFileResponse = lookupFile(request.getLookupFileRequest(), request.getVersion());
                responseBuilder.setLookupFileResponse(lookupFileResponse);
                break;
            case ListStatus:
                ListStatusResponse listStatusResponse = listStatus(request.getListStatusRequest(), request.getVersion());
                responseBuilder.setListStatusResponse(listStatusResponse);
                break;
            case GetAcl:
                GetAclResponse getAclResponse = getAcl(request.getGetAclRequest());
                responseBuilder.setGetAclResponse(getAclResponse);
                break;
            case FinalizeUpgradeProgress:
                FinalizeUpgradeProgressResponse upgradeProgressResponse = reportUpgradeProgress(request.getFinalizeUpgradeProgressRequest());
                responseBuilder.setFinalizeUpgradeProgressResponse(upgradeProgressResponse);
                break;
            case PrepareStatus:
                PrepareStatusResponse prepareStatusResponse = getPrepareStatus();
                responseBuilder.setPrepareStatusResponse(prepareStatusResponse);
                break;
            default:
                responseBuilder.setSuccess(false);
                responseBuilder.setMessage("Unrecognized Command Type: " + cmdType);
                break;
        }
        responseBuilder.setSuccess(true);
    } catch (IOException ex) {
        responseBuilder.setSuccess(false);
        responseBuilder.setStatus(exceptionToResponseStatus(ex));
        if (ex.getMessage() != null) {
            responseBuilder.setMessage(ex.getMessage());
        }
    }
    return responseBuilder.build();
}
Also used : FinalizeUpgradeProgressResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.FinalizeUpgradeProgressResponse) InfoBucketResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.InfoBucketResponse) LookupKeyResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.LookupKeyResponse) DBUpdatesResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DBUpdatesResponse) ServiceListResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ServiceListResponse) CheckVolumeAccessResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CheckVolumeAccessResponse) ListKeysResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListKeysResponse) IOException(java.io.IOException) GetAclResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetAclResponse) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) ListMultipartUploadsResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListMultipartUploadsResponse) ListBucketsResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListBucketsResponse) Type(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type) ListVolumeResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListVolumeResponse) ListTrashResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListTrashResponse) ListStatusResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListStatusResponse) MultipartUploadListPartsResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.MultipartUploadListPartsResponse) GetFileStatusResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetFileStatusResponse) InfoVolumeResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.InfoVolumeResponse) PrepareStatusResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse) LookupFileResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.LookupFileResponse)

Aggregations

PrepareStatusResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse)3 IOException (java.io.IOException)2 Duration (java.time.Duration)1 ChronoUnit (java.time.temporal.ChronoUnit)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 HddsVersionProvider (org.apache.hadoop.hdds.cli.HddsVersionProvider)1 OmUtils.getOmHostsFromConfig (org.apache.hadoop.ozone.OmUtils.getOmHostsFromConfig)1 OzoneManagerProtocol (org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol)1 CheckVolumeAccessResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CheckVolumeAccessResponse)1 DBUpdatesResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.DBUpdatesResponse)1 FinalizeUpgradeProgressResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.FinalizeUpgradeProgressResponse)1 GetAclResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetAclResponse)1 GetFileStatusResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetFileStatusResponse)1 InfoBucketResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.InfoBucketResponse)1 InfoVolumeResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.InfoVolumeResponse)1 ListBucketsResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListBucketsResponse)1