|
91 | 91 | import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
|
92 | 92 | import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
|
93 | 93 | import static org.opensearch.index.query.QueryBuilders.matchQuery;
|
| 94 | +import static org.opensearch.index.query.QueryBuilders.termQuery; |
| 95 | +import static org.opensearch.index.query.QueryBuilders.boolQuery; |
| 96 | +import static org.opensearch.index.query.QueryBuilders.rangeQuery; |
94 | 97 | import static org.opensearch.indices.replication.SegmentReplicationTarget.REPLICATION_PREFIX;
|
95 | 98 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
|
96 | 99 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAllSuccessful;
|
97 | 100 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
|
| 101 | +import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures; |
98 | 102 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchHits;
|
99 | 103 |
|
100 | 104 | @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
|
@@ -1350,4 +1354,76 @@ public void testPrimaryReceivesDocsDuringReplicaRecovery() throws Exception {
|
1350 | 1354 | ensureGreen(INDEX_NAME);
|
1351 | 1355 | waitForSearchableDocs(2, nodes);
|
1352 | 1356 | }
|
| 1357 | + |
| 1358 | + public void testIndexWhileRecoveringReplica() throws Exception { |
| 1359 | + final String primaryNode = internalCluster().startDataOnlyNode(); |
| 1360 | + assertAcked( |
| 1361 | + prepareCreate(INDEX_NAME).setMapping( |
| 1362 | + jsonBuilder().startObject() |
| 1363 | + .startObject("_routing") |
| 1364 | + .field("required", true) |
| 1365 | + .endObject() |
| 1366 | + .startObject("properties") |
| 1367 | + .startObject("online") |
| 1368 | + .field("type", "boolean") |
| 1369 | + .endObject() |
| 1370 | + .startObject("ts") |
| 1371 | + .field("type", "date") |
| 1372 | + .field("ignore_malformed", false) |
| 1373 | + .field("format", "epoch_millis") |
| 1374 | + .endObject() |
| 1375 | + .startObject("bs") |
| 1376 | + .field("type", "keyword") |
| 1377 | + .endObject() |
| 1378 | + .endObject() |
| 1379 | + .endObject() |
| 1380 | + ) |
| 1381 | + ); |
| 1382 | + ensureYellow(INDEX_NAME); |
| 1383 | + final String replicaNode = internalCluster().startDataOnlyNode(); |
| 1384 | + |
| 1385 | + client().prepareIndex(INDEX_NAME) |
| 1386 | + .setId("1") |
| 1387 | + .setRouting("Y") |
| 1388 | + .setSource("online", false, "bs", "Y", "ts", System.currentTimeMillis() - 100, "type", "s") |
| 1389 | + .get(); |
| 1390 | + client().prepareIndex(INDEX_NAME) |
| 1391 | + .setId("2") |
| 1392 | + .setRouting("X") |
| 1393 | + .setSource("online", true, "bs", "X", "ts", System.currentTimeMillis() - 10000000, "type", "s") |
| 1394 | + .get(); |
| 1395 | + client().prepareIndex(INDEX_NAME) |
| 1396 | + .setId("3") |
| 1397 | + .setRouting(randomAlphaOfLength(2)) |
| 1398 | + .setSource("online", false, "ts", System.currentTimeMillis() - 100, "type", "bs") |
| 1399 | + .get(); |
| 1400 | + client().prepareIndex(INDEX_NAME) |
| 1401 | + .setId("4") |
| 1402 | + .setRouting(randomAlphaOfLength(2)) |
| 1403 | + .setSource("online", true, "ts", System.currentTimeMillis() - 123123, "type", "bs") |
| 1404 | + .get(); |
| 1405 | + refresh(); |
| 1406 | + ensureGreen(INDEX_NAME); |
| 1407 | + waitForSearchableDocs(4, primaryNode, replicaNode); |
| 1408 | + |
| 1409 | + SearchResponse response = client().prepareSearch(INDEX_NAME) |
| 1410 | + .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) |
| 1411 | + .setQuery( |
| 1412 | + boolQuery().must(termQuery("online", true)) |
| 1413 | + .must( |
| 1414 | + boolQuery().should( |
| 1415 | + boolQuery().must(rangeQuery("ts").lt(System.currentTimeMillis() - (15 * 1000))).must(termQuery("type", "bs")) |
| 1416 | + ) |
| 1417 | + .should( |
| 1418 | + boolQuery().must(rangeQuery("ts").lt(System.currentTimeMillis() - (15 * 1000))).must(termQuery("type", "s")) |
| 1419 | + ) |
| 1420 | + ) |
| 1421 | + ) |
| 1422 | + .setVersion(true) |
| 1423 | + .setFrom(0) |
| 1424 | + .setSize(100) |
| 1425 | + .setExplain(true) |
| 1426 | + .get(); |
| 1427 | + assertNoFailures(response); |
| 1428 | + } |
1353 | 1429 | }
|
0 commit comments