Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -1028,6 +1028,10 @@ message RepeatedKeyInfo {
repeated KeyInfo keyInfo = 1;
}

message RepeatedString {
repeated string keyName = 1;
}

message OzoneFileStatusProto {
optional KeyInfo keyInfo = 2;
optional uint64 blockSize = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.hadoop.ozone.om.helpers.OmDBTenantState;
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyRenameInfo;
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.lock.IOzoneManagerLock;
Expand Down Expand Up @@ -374,6 +375,8 @@ String getMultipartKey(String volume, String bucket, String key, String

Table<String, SnapshotInfo> getSnapshotInfoTable();

Table<String, OmKeyRenameInfo> getRenamedKeyTable();

/**
* Gets the OM Meta table.
* @return meta table reference.
Expand Down Expand Up @@ -482,6 +485,18 @@ default String getOzonePathKey(long volumeId, long bucketId,
String getOpenFileName(long volumeId, long bucketId,
long parentObjectId, String fileName, long id);


/**
* Given a volume, bucket and a objectID, return the corresponding DB rename
* key.
*
* @param volume - volume name
* @param bucket - bucket name
* @param objectID - objectID of the key
* @return DB rename key as String.
*/
String getRenameKey(String volume, String bucket, long objectID);

/**
* Returns the DB key name of a multipart upload key in OM metadata store.
*
Expand Down
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
Expand Up @@ -64,6 +64,7 @@
import org.apache.hadoop.ozone.om.codec.OmDBTenantStateCodec;
import org.apache.hadoop.ozone.om.codec.OmVolumeArgsCodec;
import org.apache.hadoop.ozone.om.codec.RepeatedOmKeyInfoCodec;
import org.apache.hadoop.ozone.om.codec.OmKeyRenameInfoCodec;
import org.apache.hadoop.ozone.om.codec.S3SecretValueCodec;
import org.apache.hadoop.ozone.om.codec.OmDBSnapshotInfoCodec;
import org.apache.hadoop.ozone.om.codec.TokenIdentifierCodec;
Expand All @@ -83,6 +84,7 @@
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyRenameInfo;
import org.apache.hadoop.ozone.om.helpers.S3SecretValue;
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
Expand Down Expand Up @@ -193,6 +195,8 @@ public class OmMetadataManagerImpl implements OMMetadataManager,
* |----------------------------------------------------------------------|
* | snapshotInfoTable | /volume/bucket/snapshotName -> SnapshotInfo |
* |----------------------------------------------------------------------|
* | renamedKeyTable | /volumeName/bucketName/objectID -> OmKeyRenameInfo|
* |----------------------------------------------------------------------|
*/

public static final String USER_TABLE = "userTable";
Expand All @@ -219,6 +223,7 @@ public class OmMetadataManagerImpl implements OMMetadataManager,
"principalToAccessIdsTable";
public static final String TENANT_STATE_TABLE = "tenantStateTable";
public static final String SNAPSHOT_INFO_TABLE = "snapshotInfoTable";
public static final String RENAMED_KEY_TABLE = "renamedKeyTable";

static final String[] ALL_TABLES = new String[] {
USER_TABLE,
Expand All @@ -240,7 +245,8 @@ public class OmMetadataManagerImpl implements OMMetadataManager,
TENANT_ACCESS_ID_TABLE,
PRINCIPAL_TO_ACCESS_IDS_TABLE,
TENANT_STATE_TABLE,
SNAPSHOT_INFO_TABLE
SNAPSHOT_INFO_TABLE,
RENAMED_KEY_TABLE
};

private DBStore store;
Expand All @@ -267,7 +273,9 @@ public class OmMetadataManagerImpl implements OMMetadataManager,
private Table tenantAccessIdTable;
private Table principalToAccessIdsTable;
private Table tenantStateTable;

private Table snapshotInfoTable;
private Table renamedKeyTable;

private boolean isRatisEnabled;
private boolean ignorePipelineinKey;
Expand Down Expand Up @@ -502,6 +510,7 @@ public static DBStoreBuilder addOMTablesAndCodecs(DBStoreBuilder builder) {
.addTable(PRINCIPAL_TO_ACCESS_IDS_TABLE)
.addTable(TENANT_STATE_TABLE)
.addTable(SNAPSHOT_INFO_TABLE)
.addTable(RENAMED_KEY_TABLE)
.addCodec(OzoneTokenIdentifier.class, new TokenIdentifierCodec())
.addCodec(OmKeyInfo.class, new OmKeyInfoCodec(true))
.addCodec(RepeatedOmKeyInfo.class,
Expand All @@ -516,10 +525,9 @@ public static DBStoreBuilder addOMTablesAndCodecs(DBStoreBuilder builder) {
.addCodec(OmDirectoryInfo.class, new OmDirectoryInfoCodec())
.addCodec(OmDBTenantState.class, new OmDBTenantStateCodec())
.addCodec(OmDBAccessIdInfo.class, new OmDBAccessIdInfoCodec())
.addCodec(OmDBUserPrincipalInfo.class,
new OmDBUserPrincipalInfoCodec())
.addCodec(SnapshotInfo.class,
new OmDBSnapshotInfoCodec());
.addCodec(OmDBUserPrincipalInfo.class, new OmDBUserPrincipalInfoCodec())
.addCodec(SnapshotInfo.class, new OmDBSnapshotInfoCodec())
.addCodec(OmKeyRenameInfo.class, new OmKeyRenameInfoCodec());
}

/**
Expand Down Expand Up @@ -622,6 +630,11 @@ protected void initializeOmTables(boolean addCacheMetrics)
String.class, SnapshotInfo.class);
checkTableStatus(snapshotInfoTable, SNAPSHOT_INFO_TABLE, addCacheMetrics);

// objectID -> renamedKeys (renamed keys for key table)
renamedKeyTable = this.store.getTable(RENAMED_KEY_TABLE,
String.class, OmKeyRenameInfo.class);
checkTableStatus(renamedKeyTable, RENAMED_KEY_TABLE, addCacheMetrics);

}

/**
Expand Down Expand Up @@ -1614,6 +1627,11 @@ public Table<String, SnapshotInfo> getSnapshotInfoTable() {
return snapshotInfoTable;
}

@Override
public Table<String, OmKeyRenameInfo> getRenamedKeyTable() {
return renamedKeyTable;
}

/**
* Update store used by subclass.
*
Expand Down Expand Up @@ -1676,6 +1694,16 @@ public String getOpenFileName(long volumeId, long bucketId,
return openKey.toString();
}

@Override
public String getRenameKey(String volumeName, String bucketName,
long objectID) {
StringBuilder renameKey = new StringBuilder();
renameKey.append(OM_KEY_PREFIX).append(volumeName);
renameKey.append(OM_KEY_PREFIX).append(bucketName);
renameKey.append(OM_KEY_PREFIX).append(objectID);
return renameKey.toString();
}

@Override
public String getMultipartKey(long volumeId, long bucketId,
long parentID, String fileName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmMultipartKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmPrefixInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyRenameInfo;
import org.apache.hadoop.ozone.om.helpers.S3SecretValue;
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
Expand Down Expand Up @@ -229,6 +230,15 @@ String.class, new StringCodec(), OmKeyInfo.class,
SnapshotInfo.class,
new OmDBSnapshotInfoCodec());

public static final DBColumnFamilyDefinition<String, OmKeyRenameInfo>
RENAMED_KEY_TABLE =
new DBColumnFamilyDefinition<>(
OmMetadataManagerImpl.RENAMED_KEY_TABLE,
String.class, // /volumeName/bucketName/objectID
new StringCodec(),
OmKeyRenameInfo.class, // list of key renames
new OmKeyRenameInfoCodec());

@Override
public String getName() {
return OzoneConsts.OM_DB_NAME;
Expand All @@ -248,7 +258,7 @@ public DBColumnFamilyDefinition[] getColumnFamilies() {
FILE_TABLE, OPEN_FILE_TABLE, DELETED_DIR_TABLE, META_TABLE,
TENANT_ACCESS_ID_TABLE,
PRINCIPAL_TO_ACCESS_IDS_TABLE, TENANT_STATE_TABLE,
SNAPSHOT_INFO_TABLE};
SNAPSHOT_INFO_TABLE, RENAMED_KEY_TABLE};
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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 OmKeyRenameInfo instead single String, so we can expand on it further if needed.


}

public OmKeyInfo getRenameKeyInfo() {
Expand Down
Loading