bharatviswa504 commented on a change in pull request #448: HDDS-2870. Handle replay of KeyCreate requests. URL: https://github.com/apache/hadoop-ozone/pull/448#discussion_r370832927
########## File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java ########## @@ -250,91 +249,113 @@ public EncryptedKeyVersion run() throws IOException { * @return OMClientResponse */ @SuppressWarnings("parameternumber") - protected OMClientResponse prepareCreateKeyResponse(@Nonnull KeyArgs keyArgs, + protected OMClientResponse prepareCreateKeyResponse( + @Nonnull OMResponse.Builder omResponse, @Nonnull KeyArgs keyArgs, OmKeyInfo omKeyInfo, @Nonnull List<OmKeyLocationInfo> locations, - FileEncryptionInfo encryptionInfo, @Nullable IOException exception, + FileEncryptionInfo encryptionInfo, long clientID, long transactionLogIndex, @Nonnull String volumeName, @Nonnull String bucketName, @Nonnull String keyName, @Nonnull OzoneManager ozoneManager, @Nonnull OMAction omAction, @Nonnull PrefixManager prefixManager, @Nullable OmBucketInfo omBucketInfo) { - OMResponse.Builder omResponse = OMResponse.newBuilder() - .setStatus(OzoneManagerProtocolProtos.Status.OK); OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager(); - - Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs); - OMClientResponse omClientResponse = null; - if (exception == null) { - if (omKeyInfo == null) { - // the key does not exist, create a new object, the new blocks are the - // version 0 - omKeyInfo = createKeyInfo(keyArgs, locations, keyArgs.getFactor(), - keyArgs.getType(), keyArgs.getDataSize(), encryptionInfo, - prefixManager, omBucketInfo, transactionLogIndex); - } + IOException exception = null; - long openVersion = omKeyInfo.getLatestVersionLocations().getVersion(); + Map<String, String> auditMap = buildKeyArgsAuditMap(keyArgs); - // Append blocks - try { - omKeyInfo.appendNewBlocks(keyArgs.getKeyLocationsList().stream() - .map(OmKeyLocationInfo::getFromProtobuf) - .collect(Collectors.toList()), false); + if (omKeyInfo == null) { + // the key does not exist, create a new object, the new blocks are the + // version 0 + omKeyInfo = createKeyInfo(keyArgs, locations, keyArgs.getFactor(), + keyArgs.getType(), keyArgs.getDataSize(), encryptionInfo, + prefixManager, omBucketInfo, transactionLogIndex); + } - } catch (IOException ex) { - exception = ex; - } + long openVersion = omKeyInfo.getLatestVersionLocations().getVersion(); - if (exception != null) { - LOG.error("{} failed for Key: {} in volume/bucket:{}/{}", - omAction.getAction(), keyName, bucketName, volumeName, exception); - omClientResponse = createKeyErrorResponse(ozoneManager.getMetrics(), - omAction, exception, omResponse); + // Append blocks Review comment: We are adding blocks twice for the case when keyInfo != null, as once in prepareKeyInfo and here again. So, can we move the creation of KeyInfo logic to prepareKeyInfo and use prepareCreateKeyResponse just to generate OmClientResponse. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org