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 <[email protected]>
  • Loading branch information
ashking94 committed Oct 16, 2023
1 parent 4e70992 commit 07920ef
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -890,16 +890,7 @@ static Settings aggregateIndexSettings(
indexSettingsBuilder.put(SETTING_CREATION_DATE, Instant.now().toEpochMilli());
}
indexSettingsBuilder.put(IndexMetadata.SETTING_INDEX_PROVIDED_NAME, request.getProvidedName());

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());
indexSettingsBuilder.put(SETTING_INDEX_UUID, getIndexUuidWithBinaryPrefix(clusterSettings));

updateReplicationStrategy(indexSettingsBuilder, request.settings(), settings);
updateRemoteStoreSettings(indexSettingsBuilder, settings);
Expand Down Expand Up @@ -938,6 +929,24 @@ static Settings aggregateIndexSettings(
return indexSettings;
}

/**
* Gets index uuid where the first 10 characters are random binary string.
*
* @return index uuid with binary prefix.
*/
public static String getIndexUuidWithBinaryPrefix(ClusterSettings clusterSettings) {
// We generate random binary string of size 10.
String binaryPrefix = "";
if (clusterSettings.get(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_SETTING)) {
int length = clusterSettings.get(IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING);
binaryPrefix = Integer.toBinaryString(new Random().nextInt((int) Math.pow(2, length)));
if (binaryPrefix.length() < length) {
binaryPrefix = "0".repeat(length - binaryPrefix.length()) + binaryPrefix;
}
}
return binaryPrefix + UUIDs.randomBase64UUID();
}

/**
* Updates index settings to set replication strategy by default based on cluster level settings or remote store
* node attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@ public void apply(Settings value, Settings current, Settings previous) {
RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING,
IndicesService.CLUSTER_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING,
IndicesService.CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING,
IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_SETTING
IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_SETTING,
IndicesService.CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING
)
)
);
Expand Down
12 changes: 12 additions & 0 deletions server/src/main/java/org/opensearch/indices/IndicesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ public class IndicesService extends AbstractLifecycleComponent
Property.Dynamic
);

/**
* This setting is used to control the length of appended binary string (of size 10) prefix to index uuid if enabled.
*/
public static final Setting<Integer> CLUSTER_INDICES_BINARY_PREFIX_INDEX_UUID_LENGTH_SETTING = Setting.intSetting(
"cluster.indices.binary-prefix-index-uuid.length",
2,
0,
10,
Property.NodeScope,
Property.Dynamic
);

/**
* The node's settings.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,10 @@ public ClusterState execute(ClusterState currentState) {
indexMdBuilder.settings(
Settings.builder()
.put(snapshotIndexMetadata.getSettings())
.put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
.put(
IndexMetadata.SETTING_INDEX_UUID,
MetadataCreateIndexService.getIndexUuidWithBinaryPrefix(clusterSettings)
)
);
shardLimitValidator.validateShardLimit(
renamedIndexName,
Expand Down

0 comments on commit 07920ef

Please sign in to comment.