From e3e812fbe852682da18186c2de3663637fe8ea29 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 01:37:52 +0000 Subject: [PATCH 01/10] Fix unassigned ml system shard replicas Signed-off-by: Sicheng Song --- .../org/opensearch/ml/common/CommonValue.java | 10 +++---- .../ml/indices/MLIndicesHandler.java | 30 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/CommonValue.java b/common/src/main/java/org/opensearch/ml/common/CommonValue.java index 16554933b5..dab60ce986 100644 --- a/common/src/main/java/org/opensearch/ml/common/CommonValue.java +++ b/common/src/main/java/org/opensearch/ml/common/CommonValue.java @@ -35,13 +35,13 @@ public class CommonValue { public static final String ML_MODEL_GROUP_INDEX = ".plugins-ml-model-group"; public static final String ML_MODEL_INDEX = ".plugins-ml-model"; public static final String ML_TASK_INDEX = ".plugins-ml-task"; - public static final Integer ML_MODEL_GROUP_INDEX_SCHEMA_VERSION = 1; - public static final Integer ML_MODEL_INDEX_SCHEMA_VERSION = 6; + public static final Integer ML_MODEL_GROUP_INDEX_SCHEMA_VERSION = 2; + public static final Integer ML_MODEL_INDEX_SCHEMA_VERSION = 7; public static final String ML_CONNECTOR_INDEX = ".plugins-ml-connector"; - public static final Integer ML_TASK_INDEX_SCHEMA_VERSION = 1; - public static final Integer ML_CONNECTOR_SCHEMA_VERSION = 1; + public static final Integer ML_TASK_INDEX_SCHEMA_VERSION = 2; + public static final Integer ML_CONNECTOR_SCHEMA_VERSION = 2; public static final String ML_CONFIG_INDEX = ".plugins-ml-config"; - public static final Integer ML_CONFIG_INDEX_SCHEMA_VERSION = 1; + public static final Integer ML_CONFIG_INDEX_SCHEMA_VERSION = 2; public static final String USER_FIELD_MAPPING = " \"" + CommonValue.USER + "\": {\n" diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index 5d5a00cab8..6912e7c957 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -6,8 +6,6 @@ package org.opensearch.ml.indices; import static org.opensearch.ml.common.CommonValue.META; -import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX; -import static org.opensearch.ml.common.CommonValue.ML_TASK_INDEX; import static org.opensearch.ml.common.CommonValue.SCHEMA_VERSION_FIELD; import java.util.HashMap; @@ -17,6 +15,7 @@ import org.opensearch.action.admin.indices.create.CreateIndexRequest; import org.opensearch.action.admin.indices.create.CreateIndexResponse; import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest; +import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.service.ClusterService; @@ -41,8 +40,9 @@ public class MLIndicesHandler { private static final Map indexMappingUpdated = new HashMap<>(); static { - indexMappingUpdated.put(ML_MODEL_INDEX, new AtomicBoolean(false)); - indexMappingUpdated.put(ML_TASK_INDEX, new AtomicBoolean(false)); + for (MLIndex mlIndex : MLIndex.values()) { + indexMappingUpdated.put(mlIndex.getIndexName(), new AtomicBoolean(false)); + } } public void initModelGroupIndexIfAbsent(ActionListener listener) { @@ -68,6 +68,7 @@ public void initMLConfigIndex(ActionListener listener) { public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) { String indexName = index.getIndexName(); String mapping = index.getMapping(); + final Map indexSettings = Map.of("index.auto_expand_replicas", "0-6"); try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { ActionListener internalListener = ActionListener.runBefore(listener, () -> threadContext.restore()); @@ -83,7 +84,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) log.error("Failed to create index " + indexName, e); internalListener.onFailure(e); }); - CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping); + CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping).settings(indexSettings); client.admin().indices().create(request, actionListener); } else { log.debug("index:{} is already created", indexName); @@ -97,12 +98,19 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) .putMapping( new PutMappingRequest().indices(indexName).source(mapping, XContentType.JSON), ActionListener.wrap(response -> { - if (response.isAcknowledged()) { - indexMappingUpdated.get(indexName).set(true); - internalListener.onResponse(true); - } else { - internalListener.onFailure(new MLException("Failed to update index: " + indexName)); - } + UpdateSettingsRequest updateSettingRequest = new UpdateSettingsRequest(); + updateSettingRequest.indices(indexName).settings(indexSettings); + client + .admin() + .indices() + .updateSettings(updateSettingRequest, ActionListener.wrap(updateResponse -> { + if (response.isAcknowledged()) { + indexMappingUpdated.get(indexName).set(true); + internalListener.onResponse(true); + } else { + internalListener.onFailure(new MLException("Failed to update index: " + indexName)); + } + }, internalListener::onFailure)); }, exception -> { log.error("Failed to update index " + indexName, exception); internalListener.onFailure(exception); From a734dab7c59fc5298962e5b1eec5bacfebb31b37 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 01:53:19 +0000 Subject: [PATCH 02/10] Adjust auto replica settings to keep it consistent with AOS default setting Signed-off-by: Sicheng Song --- .../main/java/org/opensearch/ml/indices/MLIndicesHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index 6912e7c957..28cb622b99 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -68,7 +68,7 @@ public void initMLConfigIndex(ActionListener listener) { public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) { String indexName = index.getIndexName(); String mapping = index.getMapping(); - final Map indexSettings = Map.of("index.auto_expand_replicas", "0-6"); + final Map indexSettings = Map.of("index.auto_expand_replicas", "0-5"); try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { ActionListener internalListener = ActionListener.runBefore(listener, () -> threadContext.restore()); From 1efe2c1f29caf7a81476a1c332fd8a586e583a89 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Fri, 8 Sep 2023 18:53:48 -0700 Subject: [PATCH 03/10] Update plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java Co-authored-by: Yaliang Wu Signed-off-by: Sicheng Song --- .../main/java/org/opensearch/ml/indices/MLIndicesHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index 28cb622b99..fd96355b31 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -108,7 +108,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) indexMappingUpdated.get(indexName).set(true); internalListener.onResponse(true); } else { - internalListener.onFailure(new MLException("Failed to update index: " + indexName)); + internalListener.onFailure(new MLException("Failed to update index setting: " + indexName)); } }, internalListener::onFailure)); }, exception -> { From 75ca2013053f26e2b81547ee2a6b925506747614 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 02:13:45 +0000 Subject: [PATCH 04/10] Modify exception handling Signed-off-by: Sicheng Song --- .../org/opensearch/ml/indices/MLIndicesHandler.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index fd96355b31..f842451709 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -37,8 +37,9 @@ public class MLIndicesHandler { ClusterService clusterService; Client client; - + private static final Map indexSettings = Map.of("index.auto_expand_replicas", "0-5"); private static final Map indexMappingUpdated = new HashMap<>(); + static { for (MLIndex mlIndex : MLIndex.values()) { indexMappingUpdated.put(mlIndex.getIndexName(), new AtomicBoolean(false)); @@ -68,7 +69,6 @@ public void initMLConfigIndex(ActionListener listener) { public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) { String indexName = index.getIndexName(); String mapping = index.getMapping(); - final Map indexSettings = Map.of("index.auto_expand_replicas", "0-5"); try (ThreadContext.StoredContext threadContext = client.threadPool().getThreadContext().stashContext()) { ActionListener internalListener = ActionListener.runBefore(listener, () -> threadContext.restore()); @@ -108,9 +108,13 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) indexMappingUpdated.get(indexName).set(true); internalListener.onResponse(true); } else { - internalListener.onFailure(new MLException("Failed to update index setting: " + indexName)); + internalListener + .onFailure(new MLException("Failed to update index setting: " + indexName)); } - }, internalListener::onFailure)); + }, exception -> { + log.error("Failed to update index setting: " + indexName, exception); + internalListener.onFailure(exception); + })); }, exception -> { log.error("Failed to update index " + indexName, exception); internalListener.onFailure(exception); From e0ee0ab699351182e850255c2c4bcc179b1eb687 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 02:18:25 +0000 Subject: [PATCH 05/10] Modify exception messages Signed-off-by: Sicheng Song --- .../main/java/org/opensearch/ml/indices/MLIndicesHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index f842451709..28d7c9415e 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -109,10 +109,10 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) internalListener.onResponse(true); } else { internalListener - .onFailure(new MLException("Failed to update index setting: " + indexName)); + .onFailure(new MLException("Failed to update index setting for: " + indexName)); } }, exception -> { - log.error("Failed to update index setting: " + indexName, exception); + log.error("Failed to update index setting for: " + indexName, exception); internalListener.onFailure(exception); })); }, exception -> { From d0789313c58deaceaa09d215cebede839bf31b5b Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 02:29:45 +0000 Subject: [PATCH 06/10] Add response check Signed-off-by: Sicheng Song --- .../ml/indices/MLIndicesHandler.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index 28d7c9415e..d1c3267796 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -98,23 +98,25 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) .putMapping( new PutMappingRequest().indices(indexName).source(mapping, XContentType.JSON), ActionListener.wrap(response -> { - UpdateSettingsRequest updateSettingRequest = new UpdateSettingsRequest(); - updateSettingRequest.indices(indexName).settings(indexSettings); - client - .admin() - .indices() - .updateSettings(updateSettingRequest, ActionListener.wrap(updateResponse -> { - if (response.isAcknowledged()) { - indexMappingUpdated.get(indexName).set(true); - internalListener.onResponse(true); - } else { - internalListener - .onFailure(new MLException("Failed to update index setting for: " + indexName)); - } - }, exception -> { - log.error("Failed to update index setting for: " + indexName, exception); - internalListener.onFailure(exception); - })); + if (response.isAcknowledged()) { + UpdateSettingsRequest updateSettingRequest = new UpdateSettingsRequest(); + updateSettingRequest.indices(indexName).settings(indexSettings); + client + .admin() + .indices() + .updateSettings(updateSettingRequest, ActionListener.wrap(updateResponse -> { + if (response.isAcknowledged()) { + indexMappingUpdated.get(indexName).set(true); + internalListener.onResponse(true); + } else { + internalListener + .onFailure(new MLException("Failed to update index setting for: " + indexName)); + } + }, exception -> { + log.error("Failed to update index setting for: " + indexName, exception); + internalListener.onFailure(exception); + })); + } }, exception -> { log.error("Failed to update index " + indexName, exception); internalListener.onFailure(exception); From 56a4b891584bd152dc609bfaaf6f96432a9c33c5 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 02:38:21 +0000 Subject: [PATCH 07/10] Add response check and exception handling Signed-off-by: Sicheng Song --- .../main/java/org/opensearch/ml/indices/MLIndicesHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index d1c3267796..f637f3f77b 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -116,6 +116,8 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) log.error("Failed to update index setting for: " + indexName, exception); internalListener.onFailure(exception); })); + } else { + internalListener.onFailure(new MLException("Failed to update index" + indexName)); } }, exception -> { log.error("Failed to update index " + indexName, exception); From 7f1472b5b04c811874f2e01d442f3ed38109df82 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 02:39:37 +0000 Subject: [PATCH 08/10] Keep error message consistent Signed-off-by: Sicheng Song --- .../main/java/org/opensearch/ml/indices/MLIndicesHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index f637f3f77b..2578b3c818 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -120,7 +120,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) internalListener.onFailure(new MLException("Failed to update index" + indexName)); } }, exception -> { - log.error("Failed to update index " + indexName, exception); + log.error("Failed to update index: " + indexName, exception); internalListener.onFailure(exception); }) ); From a73d4ac53917967650e25b8b4be7e5a4e5539b49 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 02:40:54 +0000 Subject: [PATCH 09/10] Keep error message consistent Signed-off-by: Sicheng Song --- .../main/java/org/opensearch/ml/indices/MLIndicesHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index 2578b3c818..1910170645 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -117,10 +117,10 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) internalListener.onFailure(exception); })); } else { - internalListener.onFailure(new MLException("Failed to update index" + indexName)); + internalListener.onFailure(new MLException("Failed to update index " + indexName)); } }, exception -> { - log.error("Failed to update index: " + indexName, exception); + log.error("Failed to update index " + indexName, exception); internalListener.onFailure(exception); }) ); From 596bb7cc3caf31b5ec76b24fbe50636478094c96 Mon Sep 17 00:00:00 2001 From: Sicheng Song Date: Sat, 9 Sep 2023 02:41:43 +0000 Subject: [PATCH 10/10] Keep error message consistent Signed-off-by: Sicheng Song --- .../main/java/org/opensearch/ml/indices/MLIndicesHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java index 1910170645..af6203f0ef 100644 --- a/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java +++ b/plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java @@ -117,7 +117,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener listener) internalListener.onFailure(exception); })); } else { - internalListener.onFailure(new MLException("Failed to update index " + indexName)); + internalListener.onFailure(new MLException("Failed to update index: " + indexName)); } }, exception -> { log.error("Failed to update index " + indexName, exception);