diff --git a/CHANGELOG.md b/CHANGELOG.md index aa1a15cab..c36151ef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), * Bulk allocate objects for nmslib index creation to avoid malloc fragmentation ([#773](https://github.com/opensearch-project/k-NN/pull/773)) ### Bug Fixes ### Infrastructure +Disable index refresh for system indices ([#773](https://github.com/opensearch-project/k-NN/pull/915)) ### Documentation ### Maintenance ### Refactoring \ No newline at end of file diff --git a/src/test/java/org/opensearch/knn/index/FaissIT.java b/src/test/java/org/opensearch/knn/index/FaissIT.java index cbf6bc976..ece41d01b 100644 --- a/src/test/java/org/opensearch/knn/index/FaissIT.java +++ b/src/test/java/org/opensearch/knn/index/FaissIT.java @@ -106,7 +106,7 @@ public void testEndToEnd_fromMethod() throws Exception { } // Assert we have the right number of documents in the index - refreshAllIndices(); + refreshAllNonSystemIndices(); assertEquals(testData.indexData.docs.length, getDocCount(indexName)); int k = 10; diff --git a/src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java b/src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java index a8203f247..41d53d72c 100644 --- a/src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java +++ b/src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java @@ -13,6 +13,9 @@ import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentHelper; +import org.opensearch.core.xcontent.DeprecationHandler; +import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.core.xcontent.XContentParser; import org.opensearch.index.query.MatchAllQueryBuilder; import org.opensearch.knn.index.query.KNNQueryBuilder; import org.opensearch.knn.index.KNNSettings; @@ -22,7 +25,6 @@ import org.opensearch.knn.indices.ModelState; import org.opensearch.knn.plugin.KNNPlugin; import org.opensearch.knn.plugin.script.KNNScoringScriptEngine; -import org.apache.hc.core5.http.io.entity.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.opensearch.client.Request; @@ -60,6 +62,7 @@ import java.util.Locale; import java.util.Map; import java.util.PriorityQueue; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -112,6 +115,7 @@ public class KNNRestTestCase extends ODFERestTestCase { private static final String DOCUMENT_FIELD_FOUND = "found"; protected static final int DELAY_MILLI_SEC = 1000; protected static final int NUM_OF_ATTEMPTS = 30; + private static final String SYSTEM_INDEX_PREFIX = ".opendistro"; @AfterClass public static void dumpCoverage() throws IOException, MalformedObjectNameException { @@ -1267,4 +1271,39 @@ public interface IProxy { void reset(); } + + protected void refreshAllNonSystemIndices() throws Exception { + Response response = adminClient().performRequest(new Request("GET", "/_cat/indices?format=json&expand_wildcards=all")); + XContentType xContentType = XContentType.fromMediaType(response.getEntity().getContentType()); + try ( + XContentParser parser = xContentType.xContent() + .createParser( + NamedXContentRegistry.EMPTY, + DeprecationHandler.THROW_UNSUPPORTED_OPERATION, + response.getEntity().getContent() + ) + ) { + XContentParser.Token token = parser.nextToken(); + List> parserList; + if (token == XContentParser.Token.START_ARRAY) { + parserList = parser.listOrderedMap().stream().map(obj -> (Map) obj).collect(Collectors.toList()); + } else { + parserList = Collections.singletonList(parser.mapOrdered()); + } + Set indices = parserList.stream() + .map(index -> (String) index.get("index")) + .filter(index -> !index.startsWith(SYSTEM_INDEX_PREFIX)) + .collect(Collectors.toSet()); + for (String index : indices) { + refreshIndex(index); + } + } + } + + protected void refreshIndex(final String index) throws IOException { + Request request = new Request("POST", "/" + index + "/_refresh"); + + Response response = client().performRequest(request); + assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode())); + } }