Skip to content

Commit

Permalink
Random binary string as prefix to index uuid
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 12, 2023
1 parent 52018ec commit c55eb2a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ java.nio.file.Files#getFileStore(java.nio.file.Path) @ Use org.opensearch.env.En
java.nio.file.Files#isWritable(java.nio.file.Path) @ Use org.opensearch.env.Environment.isWritable() instead, impacted by JDK-8034057

@defaultMessage Use org.opensearch.common.Randomness#get for reproducible sources of randomness
java.util.Random#<init>()
java.util.concurrent.ThreadLocalRandom

java.security.MessageDigest#clone() @ use org.opensearch.common.hash.MessageDigests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ com.carrotsearch.randomizedtesting.annotations.Nightly @ We don't run nightly te
org.junit.Test @defaultMessage Just name your test method testFooBar

java.lang.Math#random() @ Use one of the various randomization methods from LuceneTestCase or OpenSearchTestCase for reproducibility

@defaultMessage Use org.opensearch.common.Randomness#get for reproducible sources of randomness
java.util.Random#<init>()
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/^(green \s+
open \s+
index1 \s+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
([01]{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 @@ -112,6 +112,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -896,7 +897,16 @@ static Settings aggregateIndexSettings(
indexSettingsBuilder.put(SETTING_CREATION_DATE, Instant.now().toEpochMilli());
}
indexSettingsBuilder.put(IndexMetadata.SETTING_INDEX_PROVIDED_NAME, request.getProvidedName());
indexSettingsBuilder.put(SETTING_INDEX_UUID, UUIDs.randomBase64UUID());

String binaryPrefix = "";
if (clusterSettings.get(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_SETTING)) {
// We generate random binary string of size 10.
binaryPrefix = Integer.toBinaryString(new Random().nextInt(1024));
if (binaryPrefix.length() < 10) {
binaryPrefix = "0".repeat(10 - binaryPrefix.length()) + binaryPrefix;
}
}
indexSettingsBuilder.put(SETTING_INDEX_UUID, binaryPrefix + UUIDs.randomBase64UUID());

updateReplicationStrategy(indexSettingsBuilder, request.settings(), settings);
updateRemoteStoreSettings(indexSettingsBuilder, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ public void apply(Settings value, Settings current, Settings previous) {
RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING,
RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING,
IndicesService.CLUSTER_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING,
IndicesService.CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING
IndicesService.CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING,
IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_SETTING
)
)
);
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/org/opensearch/indices/IndicesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ public class IndicesService extends AbstractLifecycleComponent
Property.Final
);

/**
* This setting is used to append binary string (of size 10) prefix to index uuid.
*/
public static final Setting<Boolean> CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_SETTING = Setting.boolSetting(
"cluster.indices.binary-prefix-index-uuid.enable",
false,
Property.NodeScope,
Property.Dynamic
);

/**
* The node's settings.
*/
Expand Down

0 comments on commit c55eb2a

Please sign in to comment.