Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -23,6 +23,7 @@
import java.util.Iterator;
import java.util.Map;

import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.hdds.utils.db.TableIterator;
Expand Down Expand Up @@ -287,13 +288,17 @@ private boolean bucketContainsSnapshotInCache(
)
public static OMRequest blockBucketDeleteWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
DeleteBucketRequest request = req.getDeleteBucketRequest();

if (request.hasBucketName() && request.hasVolumeName()) {
BucketLayout bucketLayout = ctx.getBucketLayout(
request.getVolumeName(), request.getBucketName());
bucketLayout.validateSupportedOperation();
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0) {
DeleteBucketRequest request = req.getDeleteBucketRequest();

if (request.hasBucketName() && request.hasVolumeName()) {
BucketLayout bucketLayout = ctx.getBucketLayout(
request.getVolumeName(), request.getBucketName());
bucketLayout.validateSupportedOperation();
}
}
return req;
Comment on lines +291 to 302

@adoroszlai adoroszlai Jul 10, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same "return early if client is new enough" check can be added in all methods (changing only the enum value being compared to, and the return type (request/response)):

    ClientVersion clientVersion = ClientVersion.fromProtoValue(req.getVersion());
    if (ClientVersion.BUCKET_LAYOUT_SUPPORT.compareTo(clientVersion) <= 0) {
      return req;
    }

That would:

Suggested change
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0) {
DeleteBucketRequest request = req.getDeleteBucketRequest();
if (request.hasBucketName() && request.hasVolumeName()) {
BucketLayout bucketLayout = ctx.getBucketLayout(
request.getVolumeName(), request.getBucketName());
bucketLayout.validateSupportedOperation();
}
}
return req;
ClientVersion clientVersion = ClientVersion.fromProtoValue(req.getVersion());
if (ClientVersion.BUCKET_LAYOUT_SUPPORT.compareTo(clientVersion) <= 0) {
return req;
}
DeleteBucketRequest request = req.getDeleteBucketRequest();
if (request.hasBucketName() && request.hasVolumeName()) {
BucketLayout bucketLayout = ctx.getBucketLayout(
request.getVolumeName(), request.getBucketName());
bucketLayout.validateSupportedOperation();
}
return req;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah sure will make this change add it in a separate if block

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would even go further a bit...
What if we define a method in the ClientVersion enum, call it let's say isNewerThan(ClientVersion), and use that instead of the compareTo?
With that this block can be reduced to an if (ClientVersion.fromProtoValue(req.getVersion()).isNewerThan(ClientVersion.BUCKET_LAYOUT_SUPPORT))

An other option may be (though it means introducing a new method for every version) to add a static method named like isNewerThanBucketLayout(int version), do the proto to enum conversion in the method than the compareTo, and return a boolen, so that the usage would look like:
if (ClientVersion.isNewerThanBucketLayout(req.getVersion()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd suggest:

ClientVersion.BUCKET_LAYOUT_SUPPORT.isSupportedByClient(req.getVersion())

(which also highlights why "SUPPORT" shouldn't be part of the enum constant name...)


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.hadoop.hdds.client.ECReplicationConfig;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
Expand Down Expand Up @@ -438,7 +439,8 @@ public static OMRequest disallowCreateDirectoryWithECReplicationConfig(
)
public static OMRequest blockCreateDirectoryWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getCreateDirectoryRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getCreateDirectoryRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getCreateDirectoryRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.OzoneConsts;
Expand Down Expand Up @@ -431,7 +432,8 @@ public static OMRequest disallowCreateFileWithECReplicationConfig(
)
public static OMRequest blockCreateFileWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getCreateFileRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getCreateFileRequest().hasKeyArgs()) {

KeyArgs keyArgs = req.getCreateFileRequest().getKeyArgs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.google.common.base.Preconditions;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
Expand Down Expand Up @@ -304,7 +305,8 @@ public static OMRequest disallowAllocateBlockWithECReplicationConfig(
)
public static OMRequest blockAllocateBlockWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getAllocateBlockRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getAllocateBlockRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getAllocateBlockRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.OzoneConfigKeys;
Expand Down Expand Up @@ -469,7 +470,8 @@ public static OMRequest disallowCommitKeyWithECReplicationConfig(
)
public static OMRequest blockCommitKeyWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getCommitKeyRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getCommitKeyRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getCommitKeyRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.google.common.base.Preconditions;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.om.OMConfigKeys;
Expand Down Expand Up @@ -430,7 +431,8 @@ public static OMRequest disallowCreateKeyWithECReplicationConfig(
)
public static OMRequest blockCreateKeyWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getCreateKeyRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getCreateKeyRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getCreateKeyRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
Expand Down Expand Up @@ -239,7 +240,8 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
)
public static OMRequest blockDeleteKeyWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getDeleteKeyRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getDeleteKeyRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getDeleteKeyRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import com.google.common.base.Preconditions;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.OzoneConsts;
Expand Down Expand Up @@ -276,7 +277,8 @@ private Map<String, String> buildAuditMap(
)
public static OMRequest blockRenameKeyWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getRenameKeyRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getRenameKeyRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getRenameKeyRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
Expand Down Expand Up @@ -357,7 +358,8 @@ protected static void addDeletedKeys(Map<String, String> auditMap,
)
public static OMRequest blockDeleteKeysWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getDeleteKeysRequest().hasDeleteKeys()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getDeleteKeysRequest().hasDeleteKeys()) {
DeleteKeyArgs keyArgs = req.getDeleteKeysRequest().getDeleteKeys();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
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.key;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.hdds.utils.db.Table;
import org.apache.hadoop.hdds.utils.db.cache.CacheKey;
Expand Down Expand Up @@ -303,7 +304,8 @@ private Map<String, String> buildAuditMap(Map<String, String> auditMap,
)
public static OMRequest blockRenameKeysWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getRenameKeysRequest().hasRenameKeysArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getRenameKeysRequest().hasRenameKeysArgs()) {
RenameKeysArgs keyArgs = req.getRenameKeysRequest().getRenameKeysArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import com.google.common.collect.Lists;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.OzoneConsts;
Expand Down Expand Up @@ -171,7 +172,8 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
)
public static OMRequest blockAddAclWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getAddAclRequest().hasObj()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getAddAclRequest().hasObj()) {
OzoneObj obj = OzoneObjInfo.fromProtobuf(req.getAddAclRequest().getObj());
String path = obj.getPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import com.google.common.collect.Lists;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.OzoneConsts;
Expand Down Expand Up @@ -172,7 +173,8 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
)
public static OMRequest blockRemoveAclWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getRemoveAclRequest().hasObj()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getRemoveAclRequest().hasObj()) {
OzoneObj obj =
OzoneObjInfo.fromProtobuf(req.getRemoveAclRequest().getObj());
String path = obj.getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import com.google.common.collect.Lists;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.OzoneConsts;
Expand Down Expand Up @@ -168,7 +169,8 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
)
public static OMRequest blockSetAclWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getSetAclRequest().hasObj()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getSetAclRequest().hasObj()) {
OzoneObj obj =
OzoneObjInfo.fromProtobuf(req.getSetAclRequest().getObj());
String path = obj.getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.common.base.Preconditions;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.om.helpers.KeyValueUtil;
import org.apache.ratis.server.protocol.TermIndex;
Expand Down Expand Up @@ -326,7 +327,8 @@ protected void logResult(OzoneManager ozoneManager,
)
public static OMRequest blockInitiateMPUWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getInitiateMultiPartUploadRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getInitiateMultiPartUploadRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getInitiateMultiPartUploadRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.file.InvalidPathException;
import java.util.Map;

import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
Expand Down Expand Up @@ -295,7 +296,8 @@ public static OMRequest disallowAbortMultiPartUploadWithECReplicationConfig(
)
public static OMRequest blockMPUAbortWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getAbortMultiPartUploadRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getAbortMultiPartUploadRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getAbortMultiPartUploadRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
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.s3.multipart;

import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.audit.OMAction;
Expand Down Expand Up @@ -386,7 +387,8 @@ public static OMRequest disallowCommitMultiPartUploadWithECReplicationConfig(
)
public static OMRequest blockMPUCommitWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getCommitMultiPartUploadRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getCommitMultiPartUploadRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getCommitMultiPartUploadRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.function.BiFunction;

import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.om.OzoneConfigUtil;
import org.apache.hadoop.ozone.om.request.file.OMDirectoryCreateRequestWithFSO;
import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
Expand Down Expand Up @@ -748,7 +749,8 @@ private void updateCache(OMMetadataManager omMetadataManager,
)
public static OMRequest blockMPUCompleteWithBucketLayoutFromOldClient(
OMRequest req, ValidationContext ctx) throws IOException {
if (req.getCompleteMultiPartUploadRequest().hasKeyArgs()) {
if (ClientVersion.fromProtoValue(req.getVersion())
.compareTo(ClientVersion.BUCKET_LAYOUT_SUPPORT) < 0 && req.getCompleteMultiPartUploadRequest().hasKeyArgs()) {
KeyArgs keyArgs = req.getCompleteMultiPartUploadRequest().getKeyArgs();

if (keyArgs.hasVolumeName() && keyArgs.hasBucketName()) {
Expand Down
Loading