Skip to content

Commit

Permalink
Incorporate PR review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Singh <ssashish@amazon.com>
  • Loading branch information
ashking94 committed Oct 18, 2023
1 parent 6d01352 commit 09e60d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public class IndicesService extends AbstractLifecycleComponent
public static final Setting<Integer> CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING = Setting.intSetting(
"cluster.indices.binary-prefix-index-uuid.length",
2,
0,
1,
10,
Property.NodeScope,
Property.Dynamic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ public void testRequestDurabilityWhenRestrictSettingTrue() {
public void testGetIndexUuidWithBinaryPrefix() {

String standardIndexUUIDRegex = "^([a-zA-Z0-9=/_+]|[\\\\\\-]){22}$";
String binaryPrefixIndexUUIDRegex = "^([01]{0,10})([a-zA-Z0-9=/_+]|[\\\\\\-]){22}$";
String binaryPrefixIndexUUIDRegex = "^([01]{1,10})([a-zA-Z0-9=/_+]|[\\\\\\-]){22}$";

Pattern standardIndexUUIDPattern = Pattern.compile(standardIndexUUIDRegex);
Pattern binaryPrefixIndexUUIDPattern = Pattern.compile(binaryPrefixIndexUUIDRegex);
Expand Down Expand Up @@ -1853,16 +1853,45 @@ public void testGetIndexUuidWithBinaryPrefix() {
// Binary prefix setting enabled, binary prefix random length between 2 and 10
settings = Settings.builder()
.put(binaryPrefixEnabledSettings)
.put(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING.getKey(), randomIntBetween(0, 10))
.put(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING.getKey(), randomIntBetween(1, 10))
.build();
clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
indexUUID = MetadataCreateIndexService.getIndexUuidWithBinaryPrefix(clusterSettings);
matcher = binaryPrefixIndexUUIDPattern.matcher(indexUUID);
assertTrue(matcher.matches());

// Binary prefix setting enabled, binary prefix random length 0 or 11
settings = Settings.builder()
.put(binaryPrefixEnabledSettings)
.put(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING.getKey(), 0)
.build();
ClusterSettings finalClusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> MetadataCreateIndexService.getIndexUuidWithBinaryPrefix(finalClusterSettings)
);
assertEquals(
"Failed to parse value [0] for setting [cluster.indices.binary-prefix-index-uuid.length] must be >= 1",
ex.getMessage()
);

settings = Settings.builder()
.put(binaryPrefixEnabledSettings)
.put(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING.getKey(), 11)
.build();
ClusterSettings finalClusterSettings1 = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
ex = assertThrows(
IllegalArgumentException.class,
() -> MetadataCreateIndexService.getIndexUuidWithBinaryPrefix(finalClusterSettings1)
);
assertEquals(
"Failed to parse value [11] for setting [cluster.indices.binary-prefix-index-uuid.length] must be <= 10",
ex.getMessage()
);

// Length 0
indexUUID = UUIDs.randomBase64UUID();
matcher = binaryPrefixIndexUUIDPattern.matcher(indexUUID);
matcher = standardIndexUUIDPattern.matcher(indexUUID);
assertTrue(matcher.matches());

// Length 11
Expand Down

0 comments on commit 09e60d3

Please sign in to comment.