-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-10077. Add hsync metadata to hsync'ed keys in OpenKeyTable as well #6046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
665dc84
a933b83
9ac270e
7bdb083
a15c9ae
e4d8d3e
2274739
de7ec3f
80cc7b2
74f98ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.WithMetadata; | ||
| import org.apache.hadoop.ozone.om.request.util.OmResponseUtil; | ||
| import org.apache.hadoop.ozone.om.request.util.OmKeyHSyncUtil; | ||
| import org.apache.hadoop.ozone.om.request.validation.RequestFeatureValidator; | ||
| import org.apache.hadoop.ozone.om.request.validation.RequestProcessingPhase; | ||
| import org.apache.hadoop.ozone.om.request.validation.ValidationCondition; | ||
|
|
@@ -81,8 +82,7 @@ | |
| public class OMKeyCommitRequest extends OMKeyRequest { | ||
|
|
||
| @VisibleForTesting | ||
| public static final Logger LOG = | ||
| LoggerFactory.getLogger(OMKeyCommitRequest.class); | ||
| public static final Logger LOG = LoggerFactory.getLogger(OMKeyCommitRequest.class); | ||
|
|
||
| public OMKeyCommitRequest(OMRequest omRequest, BucketLayout bucketLayout) { | ||
| super(omRequest, bucketLayout); | ||
|
|
@@ -237,7 +237,7 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn | |
|
|
||
| final String clientIdString = String.valueOf(writerClientId); | ||
| if (null != keyToDelete) { | ||
| isPreviousCommitHsync = java.util.Optional.ofNullable(keyToDelete) | ||
| isPreviousCommitHsync = java.util.Optional.of(keyToDelete) | ||
| .map(WithMetadata::getMetadata) | ||
| .map(meta -> meta.get(OzoneConsts.HSYNC_CLIENT_ID)) | ||
| .filter(id -> id.equals(clientIdString)) | ||
|
|
@@ -263,8 +263,14 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn | |
| omKeyInfo.getMetadata().putAll(KeyValueUtil.getFromProtobuf( | ||
| commitKeyArgs.getMetadataList())); | ||
|
|
||
| // non-null indicates it is necessary to update the open key | ||
| OmKeyInfo newOpenKeyInfo = null; | ||
|
|
||
| if (isHSync) { | ||
| omKeyInfo.getMetadata().put(OzoneConsts.HSYNC_CLIENT_ID, clientIdString); | ||
| if (!OmKeyHSyncUtil.isHSyncedPreviously(omKeyInfo, clientIdString, dbOpenKey)) { | ||
smengcl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| omKeyInfo.getMetadata().put(OzoneConsts.HSYNC_CLIENT_ID, clientIdString); | ||
| newOpenKeyInfo = omKeyInfo.copyObject(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modification time should be updated for newOpenKeyInfo.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Then the mod time in open key would indicate the first time the key is hsync'ed (since open key will only be updated on the first hsync). Done. |
||
| } | ||
| } else if (isRecovery) { | ||
| omKeyInfo.getMetadata().remove(OzoneConsts.HSYNC_CLIENT_ID); | ||
| omKeyInfo.getMetadata().remove(OzoneConsts.LEASE_RECOVERY); | ||
|
|
@@ -337,6 +343,13 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn | |
| // So that this key can't be committed again. | ||
| omMetadataManager.getOpenKeyTable(getBucketLayout()).addCacheEntry( | ||
| dbOpenKey, trxnLogIndex); | ||
|
|
||
| // Prevent hsync metadata from getting committed to the final key | ||
| omKeyInfo.getMetadata().remove(OzoneConsts.HSYNC_CLIENT_ID); | ||
| } else if (newOpenKeyInfo != null) { | ||
| // isHSync is true and newOpenKeyInfo is set, update OpenKeyTable | ||
| omMetadataManager.getOpenKeyTable(getBucketLayout()).addCacheEntry( | ||
| dbOpenKey, newOpenKeyInfo, trxnLogIndex); | ||
| } | ||
|
|
||
| omMetadataManager.getKeyTable(getBucketLayout()).addCacheEntry( | ||
|
|
@@ -346,7 +359,7 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn | |
|
|
||
| omClientResponse = new OMKeyCommitResponse(omResponse.build(), | ||
| omKeyInfo, dbOzoneKey, dbOpenKey, omBucketInfo.copyObject(), | ||
| oldKeyVersionsToDeleteMap, isHSync); | ||
| oldKeyVersionsToDeleteMap, isHSync, newOpenKeyInfo); | ||
|
|
||
| result = Result.SUCCESS; | ||
| } catch (IOException | InvalidPathException ex) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.ozone.om.request.util; | ||
|
|
||
| import org.apache.hadoop.ozone.OzoneConsts; | ||
| import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Helper methods related to OM key HSync. | ||
| */ | ||
| public final class OmKeyHSyncUtil { | ||
|
|
||
| public static final Logger LOG = LoggerFactory.getLogger(OmKeyHSyncUtil.class); | ||
|
|
||
| private OmKeyHSyncUtil() { | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if the key has been hsync'ed before (has metadata HSYNC_CLIENT_ID). | ||
| * @param omKeyInfo OmKeyInfo | ||
| * @param clientIdString Client ID String | ||
| * @param dbOpenKey dbOpenKey | ||
| */ | ||
| public static boolean isHSyncedPreviously(OmKeyInfo omKeyInfo, String clientIdString, String dbOpenKey) { | ||
| // Check whether the key has been hsync'ed before | ||
| final String previousHsyncClientId = omKeyInfo.getMetadata().get(OzoneConsts.HSYNC_CLIENT_ID); | ||
| if (previousHsyncClientId != null) { | ||
| if (clientIdString.equals(previousHsyncClientId)) { | ||
| // Same client ID, no need to update OpenKeyTable. One less DB write | ||
| return true; | ||
| } else { | ||
| // Sanity check. Should never enter | ||
| LOG.warn("Client ID '{}' currently hsync'ing key does not match previous hsync client ID '{}'. dbOpenKey='{}'", | ||
| clientIdString, previousHsyncClientId, dbOpenKey); | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.