Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -1710,6 +1710,7 @@ message SnapshotMoveDeletedKeysRequest {
optional SnapshotInfo fromSnapshot = 1;
repeated SnapshotMoveKeyInfos nextDBKeys = 2;
repeated SnapshotMoveKeyInfos reclaimKeys = 3;
repeated hadoop.hdds.KeyValue renamedKeys = 4;
}

message SnapshotMoveKeyInfos {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.hadoop.ozone.om.request.snapshot;

import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
import org.apache.hadoop.ozone.om.OmSnapshot;
import org.apache.hadoop.ozone.om.OmSnapshotManager;
Expand Down Expand Up @@ -88,6 +89,8 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
moveDeletedKeysRequest.getNextDBKeysList();
List<SnapshotMoveKeyInfos> reclaimKeysList =
moveDeletedKeysRequest.getReclaimKeysList();
List<HddsProtos.KeyValue> renamedKeysList =
moveDeletedKeysRequest.getRenamedKeysList();

OmSnapshot omNextSnapshot = null;

Expand All @@ -100,7 +103,7 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,

omClientResponse = new OMSnapshotMoveDeletedKeysResponse(
omResponse.build(), omFromSnapshot, omNextSnapshot,
nextDBKeysList, reclaimKeysList);
nextDBKeysList, reclaimKeysList, renamedKeysList);

} catch (IOException ex) {
omClientResponse = new OMSnapshotMoveDeletedKeysResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.hadoop.ozone.om.response.snapshot;

import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.utils.db.BatchOperation;
import org.apache.hadoop.hdds.utils.db.DBStore;
import org.apache.hadoop.ozone.om.OMMetadataManager;
Expand Down Expand Up @@ -46,16 +47,19 @@ public class OMSnapshotMoveDeletedKeysResponse extends OMClientResponse {
private OmSnapshot nextSnapshot;
private List<SnapshotMoveKeyInfos> nextDBKeysList;
private List<SnapshotMoveKeyInfos> reclaimKeysList;
private List<HddsProtos.KeyValue> renamedKeysList;

public OMSnapshotMoveDeletedKeysResponse(OMResponse omResponse,
@Nonnull OmSnapshot omFromSnapshot, OmSnapshot omNextSnapshot,
List<SnapshotMoveKeyInfos> nextDBKeysList,
List<SnapshotMoveKeyInfos> reclaimKeysList) {
List<SnapshotMoveKeyInfos> reclaimKeysList,
List<HddsProtos.KeyValue> renamedKeysList) {
super(omResponse);
this.fromSnapshot = omFromSnapshot;
this.nextSnapshot = omNextSnapshot;
this.nextDBKeysList = nextDBKeysList;
this.reclaimKeysList = reclaimKeysList;
this.renamedKeysList = renamedKeysList;
}

/**
Expand All @@ -76,27 +80,37 @@ protected void addToDBBatch(OMMetadataManager omMetadataManager,
// Init Batch Operation for snapshot db.
try (BatchOperation writeBatch = nextSnapshotStore.initBatchOperation()) {
processKeys(writeBatch, nextSnapshot.getMetadataManager(),
nextDBKeysList);
nextDBKeysList, true);
nextSnapshotStore.commitBatchOperation(writeBatch);
}
} else {
// Handle the case where there is no next Snapshot.
processKeys(batchOperation, omMetadataManager, nextDBKeysList);
processKeys(batchOperation, omMetadataManager, nextDBKeysList, true);
}

// Update From Snapshot Deleted Table.
DBStore fromSnapshotStore = fromSnapshot.getMetadataManager().getStore();
try (BatchOperation fromSnapshotBatchOp =
fromSnapshotStore.initBatchOperation()) {
processKeys(fromSnapshotBatchOp, fromSnapshot.getMetadataManager(),
reclaimKeysList);
reclaimKeysList, false);
fromSnapshotStore.commitBatchOperation(fromSnapshotBatchOp);
}
}

private void processKeys(BatchOperation batchOp,
OMMetadataManager metadataManager,
List<SnapshotMoveKeyInfos> keyList) throws IOException {
List<SnapshotMoveKeyInfos> keyList,
boolean isNextDB) throws IOException {

// Move renamed keys to only the next snapshot or active DB.
if (isNextDB) {
for (HddsProtos.KeyValue renamedKey: renamedKeysList) {
metadataManager.getSnapshotRenamedKeyTable()
.putWithBatch(batchOp, renamedKey.getKey(), renamedKey.getValue());
}
}

for (SnapshotMoveKeyInfos dBKey : keyList) {
RepeatedOmKeyInfo omKeyInfos =
createRepeatedOmKeyInfo(dBKey.getKeyInfosList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ServiceException;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.utils.BackgroundService;
import org.apache.hadoop.hdds.utils.BackgroundTask;
import org.apache.hadoop.hdds.utils.BackgroundTaskQueue;
Expand Down Expand Up @@ -190,6 +191,7 @@ public BackgroundTaskResult call() throws Exception {
// or keep it in current snapshot deleted table.
List<SnapshotMoveKeyInfos> toReclaimList = new ArrayList<>();
List<SnapshotMoveKeyInfos> toNextDBList = new ArrayList<>();
List<HddsProtos.KeyValue> renamedKeysList = new ArrayList<>();

try (TableIterator<String, ? extends Table.KeyValue<String,
RepeatedOmKeyInfo>> deletedIterator = snapshotDeletedTable
Expand Down Expand Up @@ -222,9 +224,11 @@ public BackgroundTaskResult call() throws Exception {
SnapshotMoveKeyInfos.Builder toNextDb = SnapshotMoveKeyInfos
.newBuilder()
.setKey(deletedKey);
HddsProtos.KeyValue.Builder renamedKey = HddsProtos.KeyValue
.newBuilder();

for (OmKeyInfo keyInfo: repeatedOmKeyInfo.getOmKeyInfoList()) {
splitRepeatedOmKeyInfo(toReclaim, toNextDb,
splitRepeatedOmKeyInfo(toReclaim, toNextDb, renamedKey,
keyInfo, previousKeyTable, renamedKeyTable,
bucketInfo, volumeId);
}
Expand All @@ -237,10 +241,13 @@ public BackgroundTaskResult call() throws Exception {
}
toNextDBList.add(toNextDb.build());
deletionCount++;
if (renamedKey.hasKey() && renamedKey.hasValue()) {
renamedKeysList.add(renamedKey.build());
}
}
// Submit Move request to OM.
submitSnapshotMoveDeletedKeys(snapInfo, toReclaimList,
toNextDBList);
toNextDBList, renamedKeysList);
snapshotLimit--;
successRunCount.incrementAndGet();
} catch (IOException ex) {
Expand Down Expand Up @@ -275,13 +282,16 @@ private void submitSnapshotPurgeRequest(List<String> purgeSnapshotKeys) {
}
}

@SuppressWarnings("checkstyle:ParameterNumber")
private void splitRepeatedOmKeyInfo(SnapshotMoveKeyInfos.Builder toReclaim,
SnapshotMoveKeyInfos.Builder toNextDb, OmKeyInfo keyInfo,
SnapshotMoveKeyInfos.Builder toNextDb,
HddsProtos.KeyValue.Builder renamedKey, OmKeyInfo keyInfo,
Table<String, OmKeyInfo> previousKeyTable,
Table<String, String> renamedKeyTable,
OmBucketInfo bucketInfo, long volumeId) throws IOException {

if (checkKeyReclaimable(previousKeyTable, renamedKeyTable,
keyInfo, bucketInfo, volumeId)) {
keyInfo, bucketInfo, volumeId, renamedKey)) {
// Move to next non deleted snapshot's deleted table
toNextDb.addKeyInfos(keyInfo.getProtobuf(
ClientVersion.CURRENT_VERSION));
Expand All @@ -294,16 +304,18 @@ private void splitRepeatedOmKeyInfo(SnapshotMoveKeyInfos.Builder toReclaim,

private void submitSnapshotMoveDeletedKeys(SnapshotInfo snapInfo,
List<SnapshotMoveKeyInfos> toReclaimList,
List<SnapshotMoveKeyInfos> toNextDBList) {
List<SnapshotMoveKeyInfos> toNextDBList,
List<HddsProtos.KeyValue> renamedKeysList) {

SnapshotMoveDeletedKeysRequest.Builder moveDeletedKeysBuilder =
SnapshotMoveDeletedKeysRequest.newBuilder()
.setFromSnapshot(snapInfo.getProtobuf());

SnapshotMoveDeletedKeysRequest moveDeletedKeys =
moveDeletedKeysBuilder.addAllReclaimKeys(toReclaimList)
.addAllNextDBKeys(toNextDBList).build();

SnapshotMoveDeletedKeysRequest moveDeletedKeys = moveDeletedKeysBuilder
.addAllReclaimKeys(toReclaimList)
.addAllNextDBKeys(toNextDBList)
.addAllRenamedKeys(renamedKeysList)
.build();

OMRequest omRequest = OMRequest.newBuilder()
.setCmdType(Type.SnapshotMoveDeletedKeys)
Expand All @@ -318,7 +330,8 @@ private boolean checkKeyReclaimable(
Table<String, OmKeyInfo> previousKeyTable,
Table<String, String> renamedKeyTable,
OmKeyInfo deletedKeyInfo, OmBucketInfo bucketInfo,
long volumeId) throws IOException {
long volumeId, HddsProtos.KeyValue.Builder renamedKeyBuilder)
throws IOException {

String dbKey;
// Handle case when the deleted snapshot is the first snapshot.
Expand All @@ -345,7 +358,13 @@ private boolean checkKeyReclaimable(
deletedKeyInfo.getKeyName());
}

// renamedKeyTable: volumeName/bucketName/objectID -> OMRenameKeyInfo
/*
snapshotRenamedKeyTable:
1) /volumeName/bucketName/objectID ->
/volumeId/bucketId/parentId/fileName (FSO)
2) /volumeName/bucketName/objectID ->
/volumeName/bucketName/keyName (non-FSO)
*/
String dbRenameKey = ozoneManager.getMetadataManager().getRenameKey(
deletedKeyInfo.getVolumeName(), deletedKeyInfo.getBucketName(),
deletedKeyInfo.getObjectID());
Expand All @@ -355,6 +374,9 @@ private boolean checkKeyReclaimable(
// Check key exists in renamedKeyTable of the Snapshot
String renamedKey = renamedKeyTable.getIfExist(dbRenameKey);

if (renamedKey != null) {
renamedKeyBuilder.setKey(dbRenameKey).setValue(renamedKey);
}
// previousKeyTable is fileTable if the bucket is FSO,
// otherwise it is the keyTable.
OmKeyInfo prevKeyInfo = renamedKey != null ? previousKeyTable
Expand Down