From 53ff8f0cf2a1230663b0d6a17b8feb5c5d9711a5 Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Tue, 10 Oct 2023 23:18:21 +0530 Subject: [PATCH] Random binary string as prefix to index uuid Signed-off-by: Ashish Singh --- .../src/main/resources/forbidden/opensearch-all-signatures.txt | 1 - .../main/resources/forbidden/opensearch-test-signatures.txt | 3 +++ .../cluster/metadata/MetadataCreateIndexService.java | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/resources/forbidden/opensearch-all-signatures.txt b/buildSrc/src/main/resources/forbidden/opensearch-all-signatures.txt index f9f24fd1e2367..3f9f64fe2193a 100644 --- a/buildSrc/src/main/resources/forbidden/opensearch-all-signatures.txt +++ b/buildSrc/src/main/resources/forbidden/opensearch-all-signatures.txt @@ -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#() java.util.concurrent.ThreadLocalRandom java.security.MessageDigest#clone() @ use org.opensearch.common.hash.MessageDigests diff --git a/buildSrc/src/main/resources/forbidden/opensearch-test-signatures.txt b/buildSrc/src/main/resources/forbidden/opensearch-test-signatures.txt index 43568b3209baf..36f6e27794a41 100644 --- a/buildSrc/src/main/resources/forbidden/opensearch-test-signatures.txt +++ b/buildSrc/src/main/resources/forbidden/opensearch-test-signatures.txt @@ -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#() diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java b/server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java index 8d76a39712ee3..826c6c5bb8a84 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java @@ -111,6 +111,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; @@ -889,7 +890,7 @@ 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()); + indexSettingsBuilder.put(SETTING_INDEX_UUID, Integer.toBinaryString(new Random().nextInt(256)) + UUIDs.randomBase64UUID()); updateReplicationStrategy(indexSettingsBuilder, request.settings(), settings); updateRemoteStoreSettings(indexSettingsBuilder, settings);