Skip to content
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

HDDS-11705. Snapshot operations on linked buckets should work on actual underlying bucket #7434

Merged
merged 20 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
4 changes: 2 additions & 2 deletions dev-support/ci/selective_ci_checks.bats
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ load bats-assert/load.bash
}

@test "native test in other module" {
run dev-support/ci/selective_ci_checks.sh 822c0dee1a
run dev-support/ci/selective_ci_checks.sh 3115158830483c527fb978e1edc15473d81191d2
swamirishi marked this conversation as resolved.
Show resolved Hide resolved

assert_output -p 'basic-checks=["rat","author","checkstyle","findbugs","native"]'
assert_output -p needs-build=true
assert_output -p needs-compile=true
assert_output -p needs-compose-tests=false
assert_output -p needs-dependency-check=true
assert_output -p needs-integration-tests=false
assert_output -p needs-integration-tests=true
assert_output -p needs-kubernetes-tests=false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public static SnapshotStatus valueOf(SnapshotStatusProto status) {
private UUID globalPreviousSnapshotId;
private String snapshotPath; // snapshot mask
private String checkpointDir;
private boolean isLinked;
private String linkedVolumeName;
private String linkedBucketName;
/**
* RocksDB's transaction sequence number at the time of checkpoint creation.
*/
Expand Down Expand Up @@ -148,6 +151,9 @@ private SnapshotInfo(Builder b) {
this.exclusiveReplicatedSize = b.exclusiveReplicatedSize;
this.deepCleanedDeletedDir = b.deepCleanedDeletedDir;
this.lastTransactionInfo = b.lastTransactionInfo;
this.linkedVolumeName = b.linkedVolumeName;
this.linkedBucketName = b.linkedBucketName;
this.isLinked = b.isLinked;
}

public void setName(String name) {
Expand Down Expand Up @@ -246,6 +252,18 @@ public void setSstFiltered(boolean sstFiltered) {
this.sstFiltered = sstFiltered;
}

public void setLinked(boolean linked) {
isLinked = linked;
}

public void setLinkedBucketName(String linkedBucketName) {
this.linkedBucketName = linkedBucketName;
}

public void setLinkedVolumeName(String linkedVolumeName) {
this.linkedVolumeName = linkedVolumeName;
}

public static org.apache.hadoop.ozone.om.helpers.SnapshotInfo.Builder
newBuilder() {
return new org.apache.hadoop.ozone.om.helpers.SnapshotInfo.Builder();
Expand All @@ -272,7 +290,10 @@ public SnapshotInfo.Builder toBuilder() {
.setExclusiveSize(exclusiveSize)
.setExclusiveReplicatedSize(exclusiveReplicatedSize)
.setDeepCleanedDeletedDir(deepCleanedDeletedDir)
.setLastTransactionInfo(lastTransactionInfo);
.setLastTransactionInfo(lastTransactionInfo)
.setLinked(isLinked)
.setLinkedVolumeName(linkedVolumeName)
.setLinkedBucketName(linkedBucketName);
}

/**
Expand All @@ -299,6 +320,9 @@ public static class Builder {
private long exclusiveReplicatedSize;
private boolean deepCleanedDeletedDir;
private ByteString lastTransactionInfo;
private boolean isLinked = false;
private String linkedVolumeName;
private String linkedBucketName;

public Builder() {
// default values
Expand Down Expand Up @@ -422,6 +446,21 @@ public Builder setLastTransactionInfo(ByteString lastTransactionInfo) {
return this;
}

public Builder setLinked(boolean linked) {
isLinked = linked;
return this;
}

public Builder setLinkedBucketName(String linkedBucketName) {
this.linkedBucketName = linkedBucketName;
return this;
}

public Builder setLinkedVolumeName(String linkedVolumeName) {
this.linkedVolumeName = linkedVolumeName;
return this;
}

public SnapshotInfo build() {
Preconditions.checkNotNull(name);
return new SnapshotInfo(this);
Expand Down Expand Up @@ -459,6 +498,15 @@ public OzoneManagerProtocolProtos.SnapshotInfo getProtobuf() {
if (lastTransactionInfo != null) {
sib.setLastTransactionInfo(lastTransactionInfo);
}
sib.setIsLinked(isLinked);

if (linkedVolumeName != null) {
sib.setLinkedVolumeName(linkedVolumeName);
}

if (linkedBucketName != null) {
sib.setLinkedBucketName(linkedBucketName);
}

sib.setSnapshotPath(snapshotPath)
.setCheckpointDir(checkpointDir)
Expand Down Expand Up @@ -532,6 +580,16 @@ public static SnapshotInfo getFromProtobuf(
osib.setLastTransactionInfo(snapshotInfoProto.getLastTransactionInfo());
}

if (snapshotInfoProto.hasLinkedVolumeName()) {
osib.setLinkedVolumeName(snapshotInfoProto.getLinkedVolumeName());
}

if (snapshotInfoProto.hasLinkedBucketName()) {
osib.setLinkedBucketName(snapshotInfoProto.getLinkedBucketName());
}

osib.setLinked(snapshotInfoProto.hasIsLinked() && snapshotInfoProto.getIsLinked());

osib.setSnapshotPath(snapshotInfoProto.getSnapshotPath())
.setCheckpointDir(snapshotInfoProto.getCheckpointDir())
.setDbTxSequenceNumber(snapshotInfoProto.getDbTxSequenceNumber());
Expand Down Expand Up @@ -701,7 +759,10 @@ public boolean equals(Object o) {
exclusiveSize == that.exclusiveSize &&
exclusiveReplicatedSize == that.exclusiveReplicatedSize &&
deepCleanedDeletedDir == that.deepCleanedDeletedDir &&
Objects.equals(lastTransactionInfo, that.lastTransactionInfo);
Objects.equals(lastTransactionInfo, that.lastTransactionInfo) &&
isLinked == that.isLinked &&
Objects.equals(linkedVolumeName, that.linkedVolumeName) &&
Objects.equals(linkedBucketName, that.linkedBucketName);
}

@Override
Expand All @@ -712,7 +773,8 @@ public int hashCode() {
globalPreviousSnapshotId, snapshotPath, checkpointDir,
deepClean, sstFiltered,
referencedSize, referencedReplicatedSize,
exclusiveSize, exclusiveReplicatedSize, deepCleanedDeletedDir, lastTransactionInfo);
exclusiveSize, exclusiveReplicatedSize, deepCleanedDeletedDir, lastTransactionInfo,
linkedBucketName, linkedVolumeName, isLinked);
}

/**
Expand Down Expand Up @@ -746,6 +808,9 @@ public String toString() {
", exclusiveReplicatedSize: '" + exclusiveReplicatedSize + '\'' +
", deepCleanedDeletedDir: '" + deepCleanedDeletedDir + '\'' +
", lastTransactionInfo: '" + lastTransactionInfo + '\'' +
", isLinked: '" + isLinked + '\'' +
", linkedVolumeName: '" + linkedVolumeName + '\'' +
", linkedBucketName: '" + linkedBucketName + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,57 @@ private static BucketLayout getDefaultBucketLayout(OzoneClient client) {
public static OzoneBucket createBucket(OzoneClient client,
String vol, BucketArgs bucketArgs, String bukName)
throws IOException {
return createBucket(client, vol, bucketArgs, bukName, false);
}

public static OzoneBucket createBucket(OzoneClient client,
String vol, BucketArgs bucketArgs, String bukName,
boolean createLinkedBucket)
throws IOException {
ObjectStore objectStore = client.getObjectStore();
OzoneVolume volume = objectStore.getVolume(vol);
volume.createBucket(bukName, bucketArgs);
return volume.getBucket(bukName);
String sourceBucket = bukName;
if (createLinkedBucket) {
sourceBucket = bukName + RandomStringUtils.randomNumeric(5);
}
volume.createBucket(sourceBucket, bucketArgs);
OzoneBucket ozoneBucket = volume.getBucket(sourceBucket);
if (createLinkedBucket) {
ozoneBucket = createLinkedBucket(client, vol, sourceBucket, bukName);
}
return ozoneBucket;
}

public static OzoneBucket createLinkedBucket(OzoneClient client, String vol, String sourceBucketName,
String linkedBucketName) throws IOException {
BucketArgs.Builder bb = new BucketArgs.Builder()
.setStorageType(StorageType.DEFAULT)
.setVersioning(false)
.setSourceVolume(vol)
.setSourceBucket(sourceBucketName);
return createBucket(client, vol, bb.build(), linkedBucketName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we need to call createBucket with true flag? Currently, it is calling createBucket which defaults to not linked bucket.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createLinkedBucket is called by createBucket when the flag is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the sourceBucket is present it creates a linked bucket

}

public static OzoneBucket createVolumeAndBucket(OzoneClient client,
BucketLayout bucketLayout)
throws IOException {
return createVolumeAndBucket(client, bucketLayout, false);
}

public static OzoneBucket createVolumeAndBucket(OzoneClient client,
BucketLayout bucketLayout) throws IOException {
BucketLayout bucketLayout, boolean createLinkedBucket) throws IOException {
final int attempts = 5;
for (int i = 0; i < attempts; i++) {
try {
String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
String bucketName = "bucket" + RandomStringUtils.randomNumeric(5);
return createVolumeAndBucket(client, volumeName, bucketName,
OzoneBucket ozoneBucket = createVolumeAndBucket(client, volumeName, bucketName,
bucketLayout);
if (createLinkedBucket) {
String targetBucketName = ozoneBucket.getName() + RandomStringUtils.randomNumeric(5);
ozoneBucket = createLinkedBucket(client, volumeName, bucketName, targetBucketName);
}
return ozoneBucket;
} catch (OMException e) {
if (e.getResult() != OMException.ResultCodes.VOLUME_ALREADY_EXISTS
&& e.getResult() != OMException.ResultCodes.BUCKET_ALREADY_EXISTS) {
Expand Down
Loading