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 17, 2023
1 parent 07920ef commit 849285c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/^(green \s+
open \s+
index1 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
1 \s+
0 \s+
0 \s+
Expand Down Expand Up @@ -81,7 +81,7 @@
/^( \s+
close \s+
index-2 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
\s+
\s+
\s+
Expand Down Expand Up @@ -122,7 +122,7 @@
/^(green \s+
close \s+
index-2 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
3 \s+
0 \s+
\s+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/^(green \s+
open \s+
index1 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
1 \s+
0 \s+
0 \s+
Expand Down Expand Up @@ -66,7 +66,7 @@
/^(green \s+
open \s+
\.index1 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
1 \s+
0 \s+
0 \s+
Expand Down Expand Up @@ -111,7 +111,7 @@
/^(green \s+
open \s+
index1 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
1 \s+
0 \s+
0 \s+
Expand All @@ -129,7 +129,7 @@
/^(green \s+
open \s+
index1 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
1 \s+
0 \s+
0 \s+
Expand Down Expand Up @@ -171,7 +171,7 @@
/^(green \s+
open \s+
index1 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
1 \s+
0 \s+
0 \s+
Expand All @@ -189,7 +189,7 @@
/^(green \s+
open \s+
index1 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
1 \s+
0 \s+
0 \s+
Expand Down Expand Up @@ -229,7 +229,7 @@
/^(green \s+
open \s+
index1 \s+
([01]{10})?([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{0,10})([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
1 \s+
0 \s+
0 \s+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
import org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.UUIDs;
import org.opensearch.common.compress.CompressedXContent;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.IndexScopedSettings;
Expand Down Expand Up @@ -107,6 +108,8 @@
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -1810,6 +1813,64 @@ public void testRequestDurabilityWhenRestrictSettingTrue() {
assertEquals(Translog.Durability.REQUEST, INDEX_TRANSLOG_DURABILITY_SETTING.get(indexSettings));
}

public void testGetIndexUuidWithBinaryPrefix() {

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

Pattern standardIndexUUIDPattern = Pattern.compile(standardIndexUUIDRegex);
Pattern binaryPrefixIndexUUIDPattern = Pattern.compile(binaryPrefixIndexUUIDRegex);

Settings binaryPrefixEnabledSettings = Settings.builder()
.put(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_SETTING.getKey(), true)
.build();
Settings standardIndexUUIDSetting = Settings.builder()
.put(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_SETTING.getKey(), false)
.build();

// Binary prefix setting disabled, no binary prefix length
ClusterSettings clusterSettings = new ClusterSettings(standardIndexUUIDSetting, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
String indexUUID = MetadataCreateIndexService.getIndexUuidWithBinaryPrefix(clusterSettings);
Matcher matcher = standardIndexUUIDPattern.matcher(indexUUID);
assertTrue(matcher.matches());

// Binary prefix setting disabled, variable binary prefix length
Settings settings = Settings.builder()
.put(standardIndexUUIDSetting)
.put(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING.getKey(), randomIntBetween(0, 10))
.build();
clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
indexUUID = MetadataCreateIndexService.getIndexUuidWithBinaryPrefix(clusterSettings);
matcher = standardIndexUUIDPattern.matcher(indexUUID);
assertTrue(matcher.matches());

// Binary prefix setting enabled, default binary prefix length
clusterSettings = new ClusterSettings(binaryPrefixEnabledSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
indexUUID = MetadataCreateIndexService.getIndexUuidWithBinaryPrefix(clusterSettings);
matcher = binaryPrefixIndexUUIDPattern.matcher(indexUUID);
assertTrue(matcher.matches());

// 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))
.build();
clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
indexUUID = MetadataCreateIndexService.getIndexUuidWithBinaryPrefix(clusterSettings);
matcher = binaryPrefixIndexUUIDPattern.matcher(indexUUID);
assertTrue(matcher.matches());

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

// Length 11
indexUUID = randomFrom("0", "1") + "1".repeat(10) + UUIDs.randomBase64UUID();
matcher = binaryPrefixIndexUUIDPattern.matcher(indexUUID);
assertFalse(matcher.matches());
}

private IndexTemplateMetadata addMatchingTemplate(Consumer<IndexTemplateMetadata.Builder> configurator) {
IndexTemplateMetadata.Builder builder = templateMetadataBuilder("template1", "te*");
configurator.accept(builder);
Expand Down

0 comments on commit 849285c

Please sign in to comment.