Skip to content

Commit e360727

Browse files
Fix unassigned ml system shard replicas (#1315) (#1316)
* Fix unassigned ml system shard replicas Signed-off-by: Sicheng Song <[email protected]> * Adjust auto replica settings to keep it consistent with AOS default setting Signed-off-by: Sicheng Song <[email protected]> * Update plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java Co-authored-by: Yaliang Wu <[email protected]> Signed-off-by: Sicheng Song <[email protected]> * Modify exception handling Signed-off-by: Sicheng Song <[email protected]> * Modify exception messages Signed-off-by: Sicheng Song <[email protected]> * Add response check Signed-off-by: Sicheng Song <[email protected]> * Add response check and exception handling Signed-off-by: Sicheng Song <[email protected]> * Keep error message consistent Signed-off-by: Sicheng Song <[email protected]> * Keep error message consistent Signed-off-by: Sicheng Song <[email protected]> * Keep error message consistent Signed-off-by: Sicheng Song <[email protected]> --------- Signed-off-by: Sicheng Song <[email protected]> Co-authored-by: Yaliang Wu <[email protected]> (cherry picked from commit 56976e1) Co-authored-by: Sicheng Song <[email protected]>
1 parent 5fccfd5 commit e360727

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

common/src/main/java/org/opensearch/ml/common/CommonValue.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public class CommonValue {
3535
public static final String ML_MODEL_GROUP_INDEX = ".plugins-ml-model-group";
3636
public static final String ML_MODEL_INDEX = ".plugins-ml-model";
3737
public static final String ML_TASK_INDEX = ".plugins-ml-task";
38-
public static final Integer ML_MODEL_GROUP_INDEX_SCHEMA_VERSION = 1;
39-
public static final Integer ML_MODEL_INDEX_SCHEMA_VERSION = 6;
38+
public static final Integer ML_MODEL_GROUP_INDEX_SCHEMA_VERSION = 2;
39+
public static final Integer ML_MODEL_INDEX_SCHEMA_VERSION = 7;
4040
public static final String ML_CONNECTOR_INDEX = ".plugins-ml-connector";
41-
public static final Integer ML_TASK_INDEX_SCHEMA_VERSION = 1;
42-
public static final Integer ML_CONNECTOR_SCHEMA_VERSION = 1;
41+
public static final Integer ML_TASK_INDEX_SCHEMA_VERSION = 2;
42+
public static final Integer ML_CONNECTOR_SCHEMA_VERSION = 2;
4343
public static final String ML_CONFIG_INDEX = ".plugins-ml-config";
44-
public static final Integer ML_CONFIG_INDEX_SCHEMA_VERSION = 1;
44+
public static final Integer ML_CONFIG_INDEX_SCHEMA_VERSION = 2;
4545
public static final String USER_FIELD_MAPPING = " \""
4646
+ CommonValue.USER
4747
+ "\": {\n"

plugin/src/main/java/org/opensearch/ml/indices/MLIndicesHandler.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
package org.opensearch.ml.indices;
77

88
import static org.opensearch.ml.common.CommonValue.META;
9-
import static org.opensearch.ml.common.CommonValue.ML_MODEL_INDEX;
10-
import static org.opensearch.ml.common.CommonValue.ML_TASK_INDEX;
119
import static org.opensearch.ml.common.CommonValue.SCHEMA_VERSION_FIELD;
1210

1311
import java.util.HashMap;
@@ -17,6 +15,7 @@
1715
import org.opensearch.action.admin.indices.create.CreateIndexRequest;
1816
import org.opensearch.action.admin.indices.create.CreateIndexResponse;
1917
import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest;
18+
import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest;
2019
import org.opensearch.client.Client;
2120
import org.opensearch.cluster.metadata.IndexMetadata;
2221
import org.opensearch.cluster.service.ClusterService;
@@ -38,11 +37,13 @@ public class MLIndicesHandler {
3837

3938
ClusterService clusterService;
4039
Client client;
41-
40+
private static final Map<String, Object> indexSettings = Map.of("index.auto_expand_replicas", "0-5");
4241
private static final Map<String, AtomicBoolean> indexMappingUpdated = new HashMap<>();
42+
4343
static {
44-
indexMappingUpdated.put(ML_MODEL_INDEX, new AtomicBoolean(false));
45-
indexMappingUpdated.put(ML_TASK_INDEX, new AtomicBoolean(false));
44+
for (MLIndex mlIndex : MLIndex.values()) {
45+
indexMappingUpdated.put(mlIndex.getIndexName(), new AtomicBoolean(false));
46+
}
4647
}
4748

4849
public void initModelGroupIndexIfAbsent(ActionListener<Boolean> listener) {
@@ -83,7 +84,7 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener<Boolean> listener)
8384
log.error("Failed to create index " + indexName, e);
8485
internalListener.onFailure(e);
8586
});
86-
CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping);
87+
CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping).settings(indexSettings);
8788
client.admin().indices().create(request, actionListener);
8889
} else {
8990
log.debug("index:{} is already created", indexName);
@@ -98,8 +99,23 @@ public void initMLIndexIfAbsent(MLIndex index, ActionListener<Boolean> listener)
9899
new PutMappingRequest().indices(indexName).source(mapping, XContentType.JSON),
99100
ActionListener.wrap(response -> {
100101
if (response.isAcknowledged()) {
101-
indexMappingUpdated.get(indexName).set(true);
102-
internalListener.onResponse(true);
102+
UpdateSettingsRequest updateSettingRequest = new UpdateSettingsRequest();
103+
updateSettingRequest.indices(indexName).settings(indexSettings);
104+
client
105+
.admin()
106+
.indices()
107+
.updateSettings(updateSettingRequest, ActionListener.wrap(updateResponse -> {
108+
if (response.isAcknowledged()) {
109+
indexMappingUpdated.get(indexName).set(true);
110+
internalListener.onResponse(true);
111+
} else {
112+
internalListener
113+
.onFailure(new MLException("Failed to update index setting for: " + indexName));
114+
}
115+
}, exception -> {
116+
log.error("Failed to update index setting for: " + indexName, exception);
117+
internalListener.onFailure(exception);
118+
}));
103119
} else {
104120
internalListener.onFailure(new MLException("Failed to update index: " + indexName));
105121
}

0 commit comments

Comments
 (0)