-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-7984. [Snapshot] Store Ozone keys ever renamed in renamedKeyTable for efficient lookup in SnapshotDeletingService #4333
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 3 commits
2334165
c1e9053
c17a354
04f7fdf
7e186d8
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 |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /** | ||
| * 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.helpers; | ||
|
|
||
|
|
||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RepeatedString; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Argument for renamedKeyTable. Helps to store List<String> which represents | ||
| * all the renames that happened to particular key in between snapshots. | ||
| */ | ||
| public class OmKeyRenameInfo { | ||
| private List<String> omKeyRenameInfoList; | ||
|
|
||
| public OmKeyRenameInfo(List<String> omKeyRenameInfoList) { | ||
| this.omKeyRenameInfoList = omKeyRenameInfoList; | ||
| } | ||
|
|
||
| public OmKeyRenameInfo(String keyRenameInfo) { | ||
| this.omKeyRenameInfoList = new ArrayList<>(); | ||
| this.omKeyRenameInfoList.add(keyRenameInfo); | ||
| } | ||
|
|
||
| public void addOmKeyRenameInfo(String keyRenameInfo) { | ||
| this.omKeyRenameInfoList.add(keyRenameInfo); | ||
| } | ||
|
|
||
| public List<String> getOmKeyRenameInfoList() { | ||
| return omKeyRenameInfoList; | ||
| } | ||
|
|
||
| public List<String> cloneOmKeyRenameInfoList() { | ||
| return new ArrayList<>(omKeyRenameInfoList); | ||
| } | ||
|
|
||
|
|
||
| public static OmKeyRenameInfo getFromProto(RepeatedString | ||
| repeatedString) throws IOException { | ||
| List<String> list = new ArrayList<>(repeatedString.getKeyNameList()); | ||
| return new OmKeyRenameInfo.Builder().setOmKeyRenameList(list).build(); | ||
| } | ||
|
|
||
| public RepeatedString getProto() { | ||
| List<String> list = new ArrayList<>(cloneOmKeyRenameInfoList()); | ||
|
|
||
| RepeatedString.Builder builder = RepeatedString.newBuilder() | ||
| .addAllKeyName(list); | ||
| return builder.build(); | ||
| } | ||
|
|
||
| public OmKeyRenameInfo copyObject() { | ||
| return new OmKeyRenameInfo(new ArrayList<>(omKeyRenameInfoList)); | ||
| } | ||
|
|
||
| /** | ||
| * Builder of OmKeyRenameInfo. | ||
| */ | ||
| public static class Builder { | ||
| private List<String> omKeyRenameList; | ||
|
|
||
| public Builder() { } | ||
|
|
||
| public OmKeyRenameInfo.Builder setOmKeyRenameList(List<String> stringList) { | ||
| this.omKeyRenameList = stringList; | ||
| return this; | ||
| } | ||
|
|
||
| public OmKeyRenameInfo build() { | ||
| return new OmKeyRenameInfo(omKeyRenameList); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * 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.codec; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.protobuf.InvalidProtocolBufferException; | ||
| import org.apache.hadoop.hdds.utils.db.Codec; | ||
| import org.apache.hadoop.ozone.om.helpers.OmKeyRenameInfo; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.RepeatedString; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Codec to encode OmKeyRenameInfo as byte array. | ||
| */ | ||
| public class OmKeyRenameInfoCodec implements Codec<OmKeyRenameInfo> { | ||
| @Override | ||
| public byte[] toPersistedFormat(OmKeyRenameInfo object) throws IOException { | ||
| Preconditions | ||
| .checkNotNull(object, "Null object can't be converted to byte array."); | ||
| return object.getProto().toByteArray(); | ||
| } | ||
|
|
||
| @Override | ||
| public OmKeyRenameInfo fromPersistedFormat(byte[] rawData) | ||
| throws IOException { | ||
| Preconditions.checkNotNull(rawData, | ||
| "Null byte array can't converted to real object."); | ||
| try { | ||
| return OmKeyRenameInfo.getFromProto(RepeatedString.parseFrom(rawData)); | ||
| } catch (InvalidProtocolBufferException ex) { | ||
| throw new IllegalArgumentException( | ||
| "Can't encode the the raw data from the byte array", ex); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public OmKeyRenameInfo copyObject(OmKeyRenameInfo object) { | ||
| return object.copyObject(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import org.apache.hadoop.ozone.om.OMMetadataManager; | ||
| import org.apache.hadoop.ozone.om.helpers.BucketLayout; | ||
| import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; | ||
| import org.apache.hadoop.ozone.om.helpers.OmKeyRenameInfo; | ||
| import org.apache.hadoop.ozone.om.response.CleanupTableInfo; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos | ||
| .OMResponse; | ||
|
|
@@ -30,11 +31,12 @@ | |
| import javax.annotation.Nonnull; | ||
|
|
||
| import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.KEY_TABLE; | ||
| import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.RENAMED_KEY_TABLE; | ||
|
|
||
| /** | ||
| * Response for RenameKey request. | ||
| */ | ||
| @CleanupTableInfo(cleanupTables = {KEY_TABLE}) | ||
| @CleanupTableInfo(cleanupTables = {KEY_TABLE, RENAMED_KEY_TABLE}) | ||
| public class OMKeyRenameResponse extends OmKeyResponse { | ||
|
|
||
| private String fromKeyName; | ||
|
|
@@ -73,13 +75,26 @@ public void addToDBBatch(OMMetadataManager omMetadataManager, | |
| BatchOperation batchOperation) throws IOException { | ||
| String volumeName = renameKeyInfo.getVolumeName(); | ||
| String bucketName = renameKeyInfo.getBucketName(); | ||
| String fromDbKey = omMetadataManager | ||
| .getOzoneKey(volumeName, bucketName, fromKeyName); | ||
| omMetadataManager.getKeyTable(getBucketLayout()) | ||
| .deleteWithBatch(batchOperation, | ||
| omMetadataManager.getOzoneKey(volumeName, bucketName, fromKeyName)); | ||
| .deleteWithBatch(batchOperation, fromDbKey); | ||
| omMetadataManager.getKeyTable(getBucketLayout()) | ||
| .putWithBatch(batchOperation, | ||
| omMetadataManager.getOzoneKey(volumeName, bucketName, toKeyName), | ||
| renameKeyInfo); | ||
|
|
||
| String renameDbKey = omMetadataManager.getRenameKey( | ||
| renameKeyInfo.getVolumeName(), renameKeyInfo.getBucketName(), | ||
| renameKeyInfo.getObjectID()); | ||
| OmKeyRenameInfo omKeyRenameInfo = omMetadataManager.getRenamedKeyTable() | ||
| .get(renameDbKey); | ||
| if (omKeyRenameInfo == null) { | ||
| omKeyRenameInfo = new OmKeyRenameInfo(fromDbKey); | ||
| omMetadataManager.getRenamedKeyTable().putWithBatch( | ||
| batchOperation, renameDbKey, omKeyRenameInfo); | ||
| } | ||
|
Comment on lines
+92
to
+96
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. This means we are actually only storing the Ozone key's original name correct?
Member
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. Yes correct, We only need the original key name. In between key renames are not necessary. But keeping this to store |
||
|
|
||
| } | ||
|
|
||
| public OmKeyInfo getRenameKeyInfo() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.