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 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
Expand Up @@ -38,6 +38,7 @@
import java.util.UUID;

import com.google.common.cache.RemovalListener;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.StringUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.server.ServerUtils;
Expand Down Expand Up @@ -656,7 +657,12 @@ private ReferenceCounted<OmSnapshot> getSnapshot(
// don't allow snapshot indicator without snapshot name
throw new OMException(INVALID_KEY_NAME);
}

// Updating the volumeName & bucketName in case the bucket is a linked bucket. We need to do this before a
// permission check, since linked bucket permissions and source bucket permissions could be different.
ResolvedBucket resolvedBucket = ozoneManager.resolveBucketLink(Pair.of(volumeName,
swamirishi marked this conversation as resolved.
Show resolved Hide resolved
sumitagrawl marked this conversation as resolved.
Show resolved Hide resolved
bucketName), false);
volumeName = resolvedBucket.realVolume();
bucketName = resolvedBucket.realBucket();
String snapshotTableKey = SnapshotInfo.getTableKey(volumeName,
bucketName, snapshotName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2968,6 +2968,11 @@ public ListKeysLightResult listKeysLight(String volumeName,
public SnapshotInfo getSnapshotInfo(String volumeName, String bucketName,
String snapshotName) throws IOException {
metrics.incNumSnapshotInfos();
// Updating the volumeName & bucketName in case the bucket is a linked bucket. We need to do this before a
// permission check, since linked bucket permissions and source bucket permissions could be different.
swamirishi marked this conversation as resolved.
Show resolved Hide resolved
ResolvedBucket resolvedBucket = resolveBucketLink(Pair.of(volumeName, bucketName), false);
volumeName = resolvedBucket.realVolume();
swamirishi marked this conversation as resolved.
Show resolved Hide resolved
bucketName = resolvedBucket.realBucket();
Map<String, String> auditMap = buildAuditMap(volumeName);
auditMap.put(OzoneConsts.BUCKET, bucketName);
try {
Expand All @@ -2994,6 +2999,11 @@ public ListSnapshotResponse listSnapshot(
String volumeName, String bucketName, String snapshotPrefix,
String prevSnapshot, int maxListResult) throws IOException {
metrics.incNumSnapshotLists();
// Updating the volumeName & bucketName in case the bucket is a linked bucket. We need to do this before a
// permission check, since linked bucket permissions and source bucket permissions could be different.
ResolvedBucket resolvedBucket = resolveBucketLink(Pair.of(volumeName, bucketName), false);
volumeName = resolvedBucket.realVolume();
bucketName = resolvedBucket.realBucket();
Map<String, String> auditMap = buildAuditMap(volumeName);
auditMap.put(OzoneConsts.BUCKET, bucketName);
try {
Expand Down Expand Up @@ -4898,6 +4908,11 @@ public SnapshotDiffResponse snapshotDiff(String volume,
boolean forceFullDiff,
boolean disableNativeDiff)
throws IOException {
// Updating the volumeName & bucketName in case the bucket is a linked bucket. We need to do this before a
// permission check, since linked bucket permissions and source bucket permissions could be different.
ResolvedBucket resolvedBucket = resolveBucketLink(Pair.of(volume, bucket), false);
volume = resolvedBucket.realVolume();
bucket = resolvedBucket.realBucket();

if (isAclEnabled) {
omMetadataReader.checkAcls(ResourceType.BUCKET, StoreType.OZONE, ACLType.READ, volume, bucket, null);
Expand Down Expand Up @@ -4925,7 +4940,9 @@ public List<SnapshotDiffJob> listSnapshotDiffJobs(String volume,
String jobStatus,
boolean listAll)
throws IOException {

ResolvedBucket resolvedBucket = this.resolveBucketLink(Pair.of(volume, bucket), false);
hemantk-12 marked this conversation as resolved.
Show resolved Hide resolved
volume = resolvedBucket.realBucket();
bucket = resolvedBucket.realBucket();
if (isAclEnabled) {
omMetadataReader.checkAcls(ResourceType.BUCKET, StoreType.OZONE, ACLType.LIST, volume, bucket, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

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

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.client.DefaultReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.utils.TransactionInfo;
import org.apache.hadoop.ozone.om.ResolvedBucket;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.hdds.utils.db.RDBStore;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
Expand Down Expand Up @@ -75,8 +77,8 @@ public class OMSnapshotCreateRequest extends OMClientRequest {
LoggerFactory.getLogger(OMSnapshotCreateRequest.class);

private final String snapshotPath;
private final String volumeName;
private final String bucketName;
private String volumeName;
private String bucketName;
private final String snapshotName;
private final SnapshotInfo snapshotInfo;

Expand Down Expand Up @@ -106,7 +108,11 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
final OMRequest omRequest = super.preExecute(ozoneManager);
// Verify name
OmUtils.validateSnapshotName(snapshotName);

// Updating the volumeName & bucketName in case the bucket is a linked bucket. We need to do this before a
// permission check, since linked bucket permissions and source bucket permissions could be different.
ResolvedBucket bucket = ozoneManager.resolveBucketLink(Pair.of(volumeName, bucketName), this);
sumitagrawl marked this conversation as resolved.
Show resolved Hide resolved
this.volumeName = bucket.realVolume();
this.bucketName = bucket.realBucket();
UserGroupInformation ugi = createUGIForApi();
String bucketOwner = ozoneManager.getBucketOwner(volumeName, bucketName,
IAccessAuthorizer.ACLType.READ, OzoneObj.ResourceType.BUCKET);
Expand All @@ -120,6 +126,8 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
return omRequest.toBuilder().setCreateSnapshotRequest(
omRequest.getCreateSnapshotRequest().toBuilder()
.setSnapshotId(toProtobuf(UUID.randomUUID()))
.setVolumeName(volumeName)
.setBucketName(this.bucketName)
.setCreationTime(Time.now())
.build()).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

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

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.ozone.om.ResolvedBucket;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
Expand Down Expand Up @@ -82,6 +84,11 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {

String volumeName = deleteSnapshotRequest.getVolumeName();
String bucketName = deleteSnapshotRequest.getBucketName();
// Updating the volumeName & bucketName in case the bucket is a linked bucket. We need to do this before a
// permission check, since linked bucket permissions and source bucket permissions could be different.
ResolvedBucket resolvedBucket = ozoneManager.resolveBucketLink(Pair.of(volumeName, bucketName), this);
volumeName = resolvedBucket.realVolume();
bucketName = resolvedBucket.realBucket();

// Permission check
UserGroupInformation ugi = createUGIForApi();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@

import java.io.IOException;
import java.nio.file.InvalidPathException;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
import org.apache.hadoop.hdds.utils.db.cache.CacheValue;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.audit.AuditLogger;
import org.apache.hadoop.ozone.audit.OMAction;
import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.om.ResolvedBucket;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.request.OMClientRequest;
Expand Down Expand Up @@ -75,6 +78,11 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {

String volumeName = renameSnapshotRequest.getVolumeName();
String bucketName = renameSnapshotRequest.getBucketName();
// Updating the volumeName & bucketName in case the bucket is a linked bucket. We need to do this before a
// permission check, since linked bucket permissions and source bucket permissions could be different.
ResolvedBucket resolvedBucket = ozoneManager.resolveBucketLink(Pair.of(volumeName, bucketName), this);
volumeName = resolvedBucket.realVolume();
bucketName = resolvedBucket.realBucket();

// Permission check
UserGroupInformation ugi = createUGIForApi();
Expand Down