adoroszlai commented on code in PR #8225:
URL: https://github.com/apache/ozone/pull/8225#discussion_r2028360224
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java:
##########
@@ -760,7 +761,7 @@ public static String normalizeKey(String keyName,
if (!StringUtils.isBlank(keyName)) {
String normalizedKeyName;
if (keyName.startsWith(OM_KEY_PREFIX)) {
- normalizedKeyName = new Path(keyName).toUri().getPath();
+ normalizedKeyName = new
Path(normalizeDoubleSlashPath(keyName)).toUri().getPath();
} else {
normalizedKeyName = new Path(OM_KEY_PREFIX + keyName)
Review Comment:
I may be missing something, but the existing logic and addition of
`normalizeDoubleSlashPath` seems unnecessarily complex to me. Double `/` is
handled in `normalizeDoubleSlashPath`, 1 or 3+ `/` by `Path`, no slash by
`else`. Also, for double slash we create `Path` twice (once new function, once
here).
Can we just remove prefix of any number of `/`, add a single `/`, and pass
that through `new Path(...).toUri().getPath()`?
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFSWithObjectStoreCreate.java:
##########
@@ -386,6 +387,47 @@ public void testListKeysWithNotNormalizedPath() throws
Exception {
checkKeyList(ozoneKeyIterator, keys);
}
+ @Test
+ public void testDoubleSlashPrefixPathNormalization() throws Exception {
+ OzoneVolume ozoneVolume =
+ client.getObjectStore().getVolume(volumeName);
+ OzoneBucket ozoneBucket = ozoneVolume.getBucket(bucketName);
+ String doubleSlashKey = "//dir1/key1";
+ String normalizedDoubleSlashKey = "dir1/key1";
+ String tripleSlashKey = "///dir2/key2";
+ String normalizedTripleSlashKey = "dir2/key2";
+ byte[] data = new byte[10];
+ Arrays.fill(data, (byte)96);
+ ArrayList<String> expectedKeys = new ArrayList<>();
+ expectedKeys.add("dir1/");
+ expectedKeys.add(normalizedDoubleSlashKey);
+ expectedKeys.add("dir2/");
+ expectedKeys.add(normalizedTripleSlashKey);
+
+ OzoneOutputStream stream1 = ozoneBucket.createKey(doubleSlashKey,
data.length);
+ stream1.write(data, 0, data.length);
+ stream1.close();
+ OzoneOutputStream stream2 = ozoneBucket.createKey(tripleSlashKey,
data.length);
+ stream2.write(data, 0, data.length);
+ stream2.close();
Review Comment:
Please use `TestDataUtil.createKey`.
##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v1/AbstractS3SDKV1Tests.java:
##########
@@ -365,6 +368,34 @@ public void testPutObject() {
assertEquals("37b51d194a7513e45b56f6524f2d51f2",
putObjectResult.getETag());
}
+ @Test
+ public void testPutDoubleSlashPrefixObject() {
+ final String bucketName = getBucketName();
+ final String keyName = "//dir1";
+ final String content = "bar";
+ OzoneConfiguration conf = cluster.getConf();
+ // Create a FSO bucket for test
+ try (OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(conf)) {
+ ObjectStore store = ozoneClient.getObjectStore();
+ OzoneVolume volume = store.getS3Volume();
+ OmBucketInfo.Builder bucketInfo = new OmBucketInfo.Builder()
+ .setVolumeName(volume.getName())
+ .setBucketName(bucketName)
+ .setBucketLayout(BucketLayout.FILE_SYSTEM_OPTIMIZED);
+ OzoneManagerProtocol ozoneManagerProtocol =
store.getClientProxy().getOzoneManagerClient();
+ ozoneManagerProtocol.createBucket(bucketInfo.build());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
Review Comment:
nit: test can throw original exception
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFSWithObjectStoreCreate.java:
##########
@@ -386,6 +387,47 @@ public void testListKeysWithNotNormalizedPath() throws
Exception {
checkKeyList(ozoneKeyIterator, keys);
}
+ @Test
+ public void testDoubleSlashPrefixPathNormalization() throws Exception {
+ OzoneVolume ozoneVolume =
+ client.getObjectStore().getVolume(volumeName);
+ OzoneBucket ozoneBucket = ozoneVolume.getBucket(bucketName);
+ String doubleSlashKey = "//dir1/key1";
+ String normalizedDoubleSlashKey = "dir1/key1";
+ String tripleSlashKey = "///dir2/key2";
+ String normalizedTripleSlashKey = "dir2/key2";
Review Comment:
To avoid duplication, the test can be parameterized with number of slashes
to add as prefix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]