Skip to content

Commit

Permalink
Added validation applied to OMDirectoryCreateRequest.
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghuazhu committed Jan 24, 2024
1 parent 544011a commit 990e6a4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
Expand Down Expand Up @@ -117,8 +116,8 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
super.preExecute(ozoneManager).getCreateDirectoryRequest();
Preconditions.checkNotNull(createDirectoryRequest);

OmUtils.verifyKeyNameWithSnapshotReservedWord(
createDirectoryRequest.getKeyArgs().getKeyName());
KeyArgs keyArgs = createDirectoryRequest.getKeyArgs();
validateKeyName(ozoneManager, keyArgs, keyArgs.getKeyName());

KeyArgs.Builder newKeyArgs = createDirectoryRequest.getKeyArgs()
.toBuilder().setModificationTime(Time.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.om.OzoneConfigUtil;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.request.util.OmResponseUtil;
Expand Down Expand Up @@ -94,9 +93,9 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
KeyArgs keyArgs = createFileRequest.getKeyArgs();

// Verify key name
OmUtils.verifyKeyNameWithSnapshotReservedWord(keyArgs.getKeyName());
validateKeyName(ozoneManager, StringUtils.removeEnd(keyArgs.getKeyName(),
OzoneConsts.FS_FILE_COPYING_TEMP_SUFFIX));
validateKeyName(ozoneManager, keyArgs,
StringUtils.removeEnd(keyArgs.getKeyName(),
OzoneConsts.FS_FILE_COPYING_TEMP_SUFFIX));

UserInfo userInfo = getUserInfo();
if (keyArgs.getKeyName().length() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
KeyArgs keyArgs = commitKeyRequest.getKeyArgs();

// Verify key name
validateKeyName(ozoneManager, StringUtils.removeEnd(keyArgs.getKeyName(),
OzoneConsts.FS_FILE_COPYING_TEMP_SUFFIX));
validateKeyName(ozoneManager, keyArgs,
StringUtils.removeEnd(keyArgs.getKeyName(),
OzoneConsts.FS_FILE_COPYING_TEMP_SUFFIX));

boolean isHsync = commitKeyRequest.hasHsync() &&
commitKeyRequest.getHsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.common.base.Preconditions;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.om.OzoneConfigUtil;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
Expand Down Expand Up @@ -93,8 +92,7 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
KeyArgs keyArgs = createKeyRequest.getKeyArgs();

// Verify key name
OmUtils.verifyKeyNameWithSnapshotReservedWord(keyArgs.getKeyName());
validateKeyName(ozoneManager, keyArgs.getKeyName());
validateKeyName(ozoneManager, keyArgs, keyArgs.getKeyName());

String keyPath = keyArgs.getKeyName();
keyPath = validateAndNormalizeKey(ozoneManager.getEnableFileSystemPaths(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public OMRequest preExecute(OzoneManager ozoneManager) throws IOException {
Preconditions.checkNotNull(renameKeyRequest);
// Verify key name
KeyArgs renameKeyArgs = renameKeyRequest.getKeyArgs();
validateKeyName(ozoneManager, renameKeyRequest.getToKeyName());
validateKeyName(ozoneManager, renameKeyArgs,
renameKeyRequest.getToKeyName());

String srcKey = extractSrcKey(renameKeyArgs);
String dstKey = extractDstKey(renameKeyRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,11 @@ protected KeyArgs resolveBucketAndCheckOpenKeyAcls(KeyArgs keyArgs,
return resolvedArgs;
}

protected void validateKeyName(OzoneManager ozoneManager, String keyName)
throws OMException {
protected void validateKeyName(OzoneManager ozoneManager, KeyArgs keyArgs,
String keyName) throws OMException {
if (keyArgs != null && keyArgs.getKeyName() != null) {
OmUtils.verifyKeyNameWithSnapshotReservedWord(keyArgs.getKeyName());
}
final boolean checkKeyNameEnabled = ozoneManager.getConfiguration()
.getBoolean(OMConfigKeys.OZONE_OM_KEYNAME_CHARACTER_CHECK_ENABLED_KEY,
OMConfigKeys.OZONE_OM_KEYNAME_CHARACTER_CHECK_ENABLED_DEFAULT);
Expand Down

0 comments on commit 990e6a4

Please sign in to comment.