Skip to content

Commit

Permalink
Do refresh only for non system indices (#915) (#916)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Gaievski <[email protected]>
(cherry picked from commit a5214a3)
  • Loading branch information
martin-gaievski authored May 25, 2023
1 parent 9a1606f commit 591c3f9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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
4 changes: 2 additions & 2 deletions src/test/java/org/opensearch/knn/index/FaissIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void setUpClass() throws IOException {
testData = new TestUtils.TestData(testIndexVectors.getPath(), testQueries.getPath());
}

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

Expand Down Expand Up @@ -106,7 +106,7 @@ public void testEndToEnd_fromMethod() throws IOException, InterruptedException {
}

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

int k = 10;
Expand Down
42 changes: 41 additions & 1 deletion src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import com.google.common.io.Resources;
import com.google.common.primitives.Floats;
import org.apache.commons.lang.StringUtils;
import org.apache.http.util.EntityUtils;
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;
Expand All @@ -20,7 +24,6 @@
import org.opensearch.knn.indices.ModelState;
import org.opensearch.knn.plugin.KNNPlugin;
import org.opensearch.knn.plugin.script.KNNScoringScriptEngine;
import org.apache.http.util.EntityUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.opensearch.client.Request;
Expand Down Expand Up @@ -59,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;

Expand Down Expand Up @@ -111,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 {
Expand Down Expand Up @@ -1266,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().getValue());
try (
XContentParser parser = xContentType.xContent()
.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.getEntity().getContent()
)
) {
XContentParser.Token token = parser.nextToken();
List<Map<String, Object>> parserList;
if (token == XContentParser.Token.START_ARRAY) {
parserList = parser.listOrderedMap().stream().map(obj -> (Map<String, Object>) obj).collect(Collectors.toList());
} else {
parserList = Collections.singletonList(parser.mapOrdered());
}
Set<String> 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()));
}
}

0 comments on commit 591c3f9

Please sign in to comment.