Skip to content

Commit

Permalink
Made review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArafatKhan2198 committed Mar 29, 2024
1 parent efe3ebf commit b7df717
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -755,29 +755,30 @@ public static String normalizeKey(String keyName,
* @param path The path string to be normalized.
* @return The normalized path string.
*/
public static String normalizePathUptilBucket(String path) {
public static String normalizePathUptoBucket(String path) {
if (path == null || path.isEmpty()) {
return "/"; // Handle empty path
return OM_KEY_PREFIX; // Handle empty path
}

// Remove leading slashes
path = path.replaceAll("^/*", "");

String[] segments = path.split("/", -1);
String[] segments = path.split(OM_KEY_PREFIX, -1);

String volumeName = segments[0];
String bucketName = segments.length > 1 ? segments[1] : "";

// Combine volume and bucket.
StringBuilder normalizedPath = new StringBuilder(volumeName);
if (!bucketName.isEmpty()) {
normalizedPath.append("/").append(bucketName);
normalizedPath.append(OM_KEY_PREFIX).append(bucketName);
}

// Add remaining segments as the key
if (segments.length > 2) {
normalizedPath.append("/").append(
String.join("/", Arrays.copyOfRange(segments, 2, segments.length)));
normalizedPath.append(OM_KEY_PREFIX).append(
String.join(OM_KEY_PREFIX,
Arrays.copyOfRange(segments, 2, segments.length)));
}

return normalizedPath.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public static String[] parseObjectStorePath(String path) {
*
* This method adjusts the path according to the bucket layout.
* For {OBJECT_STORE Layout}, it normalizes the path up to the bucket level
* using OmUtils.normalizePathUptilBucket. For other layouts, it
* using OmUtils.normalizePathUptoBucket. For other layouts, it
* normalizes the entire path, including the key, using
* OmUtils.normalizeKey, and does not preserve any trailing slashes.
* The normalized path will always be prefixed with OM_KEY_PREFIX to ensure it
Expand All @@ -324,7 +324,7 @@ public static String[] parseObjectStorePath(String path) {
*/
private static String normalizePath(String path, BucketLayout bucketLayout) {
if (bucketLayout == BucketLayout.OBJECT_STORE) {
return OM_KEY_PREFIX + OmUtils.normalizePathUptilBucket(path);
return OM_KEY_PREFIX + OmUtils.normalizePathUptoBucket(path);
}
return OM_KEY_PREFIX + OmUtils.normalizeKey(path, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void processWithFileSystemLayout(OmKeyInfo updatedKeyInfo,
break;

default:
LOG.debug("Skipping DB update event fir Key: {}", action);
LOG.debug("Skipping DB update event for Key: {}", action);
}
} else {
OmDirectoryInfo updatedDirectoryInfo = new OmDirectoryInfo.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,30 +878,30 @@ public void checkFileSizeDist(String path, int bin0,
}

@Test
public void testNormalizePathUptilBucket() {
public void testNormalizePathUptoBucket() {
// Test null or empty path
assertEquals("/", OmUtils.normalizePathUptilBucket(null));
assertEquals("/", OmUtils.normalizePathUptilBucket(""));
assertEquals("/", OmUtils.normalizePathUptoBucket(null));
assertEquals("/", OmUtils.normalizePathUptoBucket(""));

// Test path with leading slashes
assertEquals("volume1/bucket1/key1/key2",
OmUtils.normalizePathUptilBucket("///volume1/bucket1/key1/key2"));
OmUtils.normalizePathUptoBucket("///volume1/bucket1/key1/key2"));

// Test volume and bucket names
assertEquals("volume1/bucket1",
OmUtils.normalizePathUptilBucket("volume1/bucket1"));
OmUtils.normalizePathUptoBucket("volume1/bucket1"));

// Test with additional segments
assertEquals("volume1/bucket1/key1/key2",
OmUtils.normalizePathUptilBucket("volume1/bucket1/key1/key2"));
OmUtils.normalizePathUptoBucket("volume1/bucket1/key1/key2"));

// Test path with multiple slashes in key names.
assertEquals("volume1/bucket1/key1//key2",
OmUtils.normalizePathUptilBucket("volume1/bucket1/key1//key2"));
OmUtils.normalizePathUptoBucket("volume1/bucket1/key1//key2"));

// Test path with volume, bucket, and special characters in keys
assertEquals("volume/bucket/key$%#1/./////////key$%#2",
OmUtils.normalizePathUptilBucket("volume/bucket/key$%#1/./////////key$%#2"));
OmUtils.normalizePathUptoBucket("volume/bucket/key$%#1/./////////key$%#2"));
}


Expand Down

0 comments on commit b7df717

Please sign in to comment.