Skip to content

Commit

Permalink
Change the index update settings to make it only contain dynamic sett…
Browse files Browse the repository at this point in the history
  • Loading branch information
b4sjoo authored Feb 26, 2024
1 parent 771dbb9 commit 0713dcd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.utils;

import lombok.extern.log4j.Log4j2;
import java.util.Map;

@Log4j2
public class IndexUtils {

// This setting is for index creation.
public static final Map<String, Object> INDEX_SETTINGS = Map.of("index.number_of_shards", "1", "index.auto_expand_replicas", "0-1");

// This setting is for index update only, so only dynamic settings should be contained!
public static final Map<String, Object> UPDATED_INDEX_SETTINGS = Map.of("index.auto_expand_replicas", "0-1");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.ml.common.utils;

import org.junit.Test;
import java.util.Map;
import static org.junit.Assert.assertEquals;

public class IndexUtilsTest {

@Test
public void testIndexSettingsContainsExpectedValues() {
Map<String, Object> indexSettings = IndexUtils.INDEX_SETTINGS;
assertEquals("index.number_of_shards should be 1", indexSettings.get("index.number_of_shards"), "1");
assertEquals("index.auto_expand_replicas should be 0-1", indexSettings.get("index.auto_expand_replicas"), "0-1");
assertEquals("INDEX_SETTINGS should contain exactly 2 settings", 2, indexSettings.size());
}

@Test
public void testUpdatedIndexSettingsContainsExpectedValues() {
Map<String, Object> updatedIndexSettings = IndexUtils.UPDATED_INDEX_SETTINGS;
assertEquals("index.auto_expand_replicas should be 0-1", updatedIndexSettings.get("index.auto_expand_replicas"), "0-1");
assertEquals("INDEX_SETTINGS should contain exactly 1 settings", 1, updatedIndexSettings.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
package org.opensearch.ml.memory.index;

import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.META_INDEX_NAME;
import static org.opensearch.ml.common.utils.IndexUtils.INDEX_SETTINGS;

import java.io.IOException;
import java.time.Instant;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.opensearch.OpenSearchStatusException;
import org.opensearch.OpenSearchWrapperException;
Expand Down Expand Up @@ -74,8 +74,6 @@ public class ConversationMetaIndex {
private Client client;
private ClusterService clusterService;

public static final Map<String, Object> INDEX_SETTINGS = Map.of("index.number_of_shards", "1", "index.auto_expand_replicas", "0-1");

private String getUserStrFromThreadContext() {
return client.threadPool().getThreadContext().getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.opensearch.ml.memory.index;

import static org.opensearch.ml.common.conversation.ConversationalIndexConstants.INTERACTIONS_INDEX_NAME;
import static org.opensearch.ml.memory.index.ConversationMetaIndex.INDEX_SETTINGS;
import static org.opensearch.ml.common.utils.IndexUtils.INDEX_SETTINGS;

import java.io.IOException;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import static org.opensearch.ml.common.CommonValue.META;
import static org.opensearch.ml.common.CommonValue.SCHEMA_VERSION_FIELD;
import static org.opensearch.ml.memory.index.ConversationMetaIndex.INDEX_SETTINGS;
import static org.opensearch.ml.common.utils.IndexUtils.INDEX_SETTINGS;
import static org.opensearch.ml.common.utils.IndexUtils.UPDATED_INDEX_SETTINGS;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -123,7 +124,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener<Boolean> listener)
ActionListener.wrap(response -> {
if (response.isAcknowledged()) {
UpdateSettingsRequest updateSettingRequest = new UpdateSettingsRequest();
updateSettingRequest.indices(indexName).settings(INDEX_SETTINGS);
updateSettingRequest.indices(indexName).settings(UPDATED_INDEX_SETTINGS);
client
.admin()
.indices()
Expand Down

0 comments on commit 0713dcd

Please sign in to comment.