Skip to content

Commit 591c3f9

Browse files
Do refresh only for non system indices (#915) (#916)
Signed-off-by: Martin Gaievski <gaievski@amazon.com> (cherry picked from commit a5214a3)
1 parent 9a1606f commit 591c3f9

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818
* Bulk allocate objects for nmslib index creation to avoid malloc fragmentation ([#773](https://github.com/opensearch-project/k-NN/pull/773))
1919
### Bug Fixes
2020
### Infrastructure
21+
* Disable index refresh for system indices ([#773](https://github.com/opensearch-project/k-NN/pull/915))
2122
### Documentation
2223
### Maintenance
2324
### Refactoring

src/test/java/org/opensearch/knn/index/FaissIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void setUpClass() throws IOException {
5555
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
5656
}
5757

58-
public void testEndToEnd_fromMethod() throws IOException, InterruptedException {
58+
public void testEndToEnd_fromMethod() throws Exception {
5959
String indexName = "test-index-1";
6060
String fieldName = "test-field-1";
6161

@@ -106,7 +106,7 @@ public void testEndToEnd_fromMethod() throws IOException, InterruptedException {
106106
}
107107

108108
// Assert we have the right number of documents in the index
109-
refreshAllIndices();
109+
refreshAllNonSystemIndices();
110110
assertEquals(testData.indexData.docs.length, getDocCount(indexName));
111111

112112
int k = 10;

src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java

+41-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
import com.google.common.io.Resources;
1010
import com.google.common.primitives.Floats;
1111
import org.apache.commons.lang.StringUtils;
12+
import org.apache.http.util.EntityUtils;
1213
import org.opensearch.common.bytes.BytesReference;
1314
import org.opensearch.common.xcontent.XContentHelper;
15+
import org.opensearch.core.xcontent.DeprecationHandler;
16+
import org.opensearch.core.xcontent.NamedXContentRegistry;
17+
import org.opensearch.core.xcontent.XContentParser;
1418
import org.opensearch.index.query.MatchAllQueryBuilder;
1519
import org.opensearch.knn.index.query.KNNQueryBuilder;
1620
import org.opensearch.knn.index.KNNSettings;
@@ -20,7 +24,6 @@
2024
import org.opensearch.knn.indices.ModelState;
2125
import org.opensearch.knn.plugin.KNNPlugin;
2226
import org.opensearch.knn.plugin.script.KNNScoringScriptEngine;
23-
import org.apache.http.util.EntityUtils;
2427
import org.junit.AfterClass;
2528
import org.junit.Before;
2629
import org.opensearch.client.Request;
@@ -59,6 +62,7 @@
5962
import java.util.Locale;
6063
import java.util.Map;
6164
import java.util.PriorityQueue;
65+
import java.util.Set;
6266
import java.util.concurrent.TimeUnit;
6367
import java.util.stream.Collectors;
6468

@@ -111,6 +115,7 @@ public class KNNRestTestCase extends ODFERestTestCase {
111115
private static final String DOCUMENT_FIELD_FOUND = "found";
112116
protected static final int DELAY_MILLI_SEC = 1000;
113117
protected static final int NUM_OF_ATTEMPTS = 30;
118+
private static final String SYSTEM_INDEX_PREFIX = ".opendistro";
114119

115120
@AfterClass
116121
public static void dumpCoverage() throws IOException, MalformedObjectNameException {
@@ -1266,4 +1271,39 @@ public interface IProxy {
12661271

12671272
void reset();
12681273
}
1274+
1275+
protected void refreshAllNonSystemIndices() throws Exception {
1276+
Response response = adminClient().performRequest(new Request("GET", "/_cat/indices?format=json&expand_wildcards=all"));
1277+
XContentType xContentType = XContentType.fromMediaType(response.getEntity().getContentType().getValue());
1278+
try (
1279+
XContentParser parser = xContentType.xContent()
1280+
.createParser(
1281+
NamedXContentRegistry.EMPTY,
1282+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
1283+
response.getEntity().getContent()
1284+
)
1285+
) {
1286+
XContentParser.Token token = parser.nextToken();
1287+
List<Map<String, Object>> parserList;
1288+
if (token == XContentParser.Token.START_ARRAY) {
1289+
parserList = parser.listOrderedMap().stream().map(obj -> (Map<String, Object>) obj).collect(Collectors.toList());
1290+
} else {
1291+
parserList = Collections.singletonList(parser.mapOrdered());
1292+
}
1293+
Set<String> indices = parserList.stream()
1294+
.map(index -> (String) index.get("index"))
1295+
.filter(index -> !index.startsWith(SYSTEM_INDEX_PREFIX))
1296+
.collect(Collectors.toSet());
1297+
for (String index : indices) {
1298+
refreshIndex(index);
1299+
}
1300+
}
1301+
}
1302+
1303+
protected void refreshIndex(final String index) throws IOException {
1304+
Request request = new Request("POST", "/" + index + "/_refresh");
1305+
1306+
Response response = client().performRequest(request);
1307+
assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
1308+
}
12691309
}

0 commit comments

Comments
 (0)