Skip to content

Commit

Permalink
Incoporate PR review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Singh <[email protected]>
  • Loading branch information
ashking94 committed Apr 8, 2024
1 parent 1e5e346 commit d32b501
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ String hash(PathInput pathInput) {
String input = pathInput.indexUUID() + pathInput.shardId() + pathInput.dataCategory().getName() + pathInput.dataType()
.getName();
long hash = FNV1a.hash64(input);
return RemoteStoreUtils.longToBase64(hash);
return RemoteStoreUtils.longToUrlBase64(hash);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,14 @@ public static void verifyNoMultipleWriters(List<String> mdFiles, Function<String
/**
* Converts an input hash which occupies 64 bits of space into Base64 (6 bits per character) String. This must not
* be changed as it is used for creating path for storing remote store data on the remote store.
*/
static String longToBase64(long value) {
byte[] hashBytes = ByteBuffer.allocate(Long.BYTES).putLong(value).array();
return base64(hashBytes);
}

/**
* This converts the byte array to base 64 string. `/` is replaced with `_`, `+` is replaced with `-` and `=`
* which is padded at the last is also removed. These characters are either used as delimiter or special character
* requiring special handling in some vendors. The characters present in this base64 version are [A-Za-z0-9_-].
* This must not be changed as it is used for creating path for storing remote store data on the remote store.
*
* @param bytes byte array
* @return base 64 string.
*/
private static String base64(byte[] bytes) {
String base64 = Base64.getEncoder().encodeToString(bytes);
return base64.substring(0, base64.length() - 1).replace('/', '_').replace('+', '-');
static String longToUrlBase64(long value) {
byte[] hashBytes = ByteBuffer.allocate(Long.BYTES).putLong(value).array();
String base64Str = Base64.getUrlEncoder().encodeToString(hashBytes);
return base64Str.substring(0, base64Str.length() - 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public class IndicesService extends AbstractLifecycleComponent
*/
public static final Setting<PathType> CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING = new Setting<>(
"cluster.remote_store.index.path.prefix.type",
PathType.HASHED_PREFIX.toString(),
PathType.FIXED.toString(),
PathType::parseString,
Property.NodeScope,
Property.Dynamic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Map;
import java.util.stream.Collectors;

import static org.opensearch.index.remote.RemoteStoreUtils.longToBase64;
import static org.opensearch.index.remote.RemoteStoreUtils.longToUrlBase64;
import static org.opensearch.index.remote.RemoteStoreUtils.verifyNoMultipleWriters;
import static org.opensearch.index.store.RemoteSegmentStoreDirectory.MetadataFilenameUtils.METADATA_PREFIX;
import static org.opensearch.index.store.RemoteSegmentStoreDirectory.MetadataFilenameUtils.SEPARATOR;
Expand Down Expand Up @@ -205,7 +205,7 @@ public void testLongToBase64() {
"6kv3yZNv9kY"
);
for (Map.Entry<Long, String> entry : longToExpectedBase64String.entrySet()) {
assertEquals(entry.getValue(), longToBase64(entry.getKey()));
assertEquals(entry.getValue(), longToUrlBase64(entry.getKey()));
assertEquals(11, entry.getValue().length());
}
}
Expand Down

0 comments on commit d32b501

Please sign in to comment.