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-4102. Normalize Keypath for lookupKey. #1328

Merged
merged 1 commit into from
Sep 28, 2020
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 @@ -29,6 +29,7 @@
import org.apache.hadoop.ozone.TestDataUtil;
import org.apache.hadoop.ozone.client.OzoneBucket;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.client.io.OzoneInputStream;
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.exceptions.OMException;
Expand Down Expand Up @@ -329,6 +330,45 @@ public void testCreateDirectoryFirstThenKeyAndFileWithSameName()
}
}


@Test
public void testReadWithNotNormalizedPath() throws Exception {
OzoneVolume ozoneVolume =
cluster.getRpcClient().getObjectStore().getVolume(volumeName);

OzoneBucket ozoneBucket = ozoneVolume.getBucket(bucketName);

String key = "/dir1///dir2/file1/";

int length = 10;
byte[] input = new byte[length];
Arrays.fill(input, (byte)96);
String inputString = new String(input);

OzoneOutputStream ozoneOutputStream =
ozoneBucket.createKey(key, length);

ozoneOutputStream.write(input);
ozoneOutputStream.write(input, 0, 10);
ozoneOutputStream.close();

// Read the key with given key name.
OzoneInputStream ozoneInputStream = ozoneBucket.readKey(key);
byte[] read = new byte[length];
ozoneInputStream.read(read, 0, length);
ozoneInputStream.close();

Assert.assertEquals(inputString, new String(read));

// Read using filesystem.
FSDataInputStream fsDataInputStream = o3fs.open(new Path(key));
read = new byte[length];
fsDataInputStream.read(read, 0, length);
ozoneInputStream.close();

Assert.assertEquals(inputString, new String(read));
}

private void checkPath(Path path) {
try {
o3fs.getFileStatus(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ private void testDeleteCreatesFakeParentDir() throws Exception {

// Deleting the only child should create the parent dir key if it does
// not exist
String parentKey = o3fs.pathToKey(parent) + "/";
OzoneKeyDetails parentKeyInfo = getKey(parent, true);
assertEquals(parentKey, parentKeyInfo.getName());
FileStatus fileStatus = o3fs.getFileStatus(parent);
Assert.assertTrue(fileStatus.isDirectory());
assertEquals(parent.toString(), fileStatus.getPath().toUri().getPath());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
import org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo;
import org.apache.hadoop.ozone.om.request.OMClientRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PartKeyInfo;
import org.apache.hadoop.ozone.security.OzoneBlockTokenSecretManager;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
Expand Down Expand Up @@ -165,6 +166,8 @@ public class KeyManagerImpl implements KeyManager {
private final KeyProviderCryptoExtension kmsProvider;
private final PrefixManager prefixManager;

private final boolean enableFileSystemPaths;


@VisibleForTesting
public KeyManagerImpl(ScmBlockLocationProtocol scmBlockClient,
Expand Down Expand Up @@ -208,6 +211,9 @@ public KeyManagerImpl(OzoneManager om, ScmClient scmClient,
this.listTrashKeysMax = conf.getInt(
OZONE_CLIENT_LIST_TRASH_KEYS_MAX,
OZONE_CLIENT_LIST_TRASH_KEYS_MAX_DEFAULT);
this.enableFileSystemPaths =
conf.getBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS_DEFAULT);

this.ozoneManager = om;
this.omId = omId;
Expand Down Expand Up @@ -645,7 +651,8 @@ public OmKeyInfo lookupKey(OmKeyArgs args, String clientAddress)
Preconditions.checkNotNull(args);
String volumeName = args.getVolumeName();
String bucketName = args.getBucketName();
String keyName = args.getKeyName();
String keyName = OMClientRequest.validateAndNormalizeKey(
enableFileSystemPaths, args.getKeyName());
metadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName,
bucketName);
OmKeyInfo value = null;
Expand Down