Skip to content

Commit 9de6f06

Browse files
committed
Add IT for executing search and PIT against refresh blocked indices
1 parent 0edc27c commit 9de6f06

File tree

3 files changed

+140
-2
lines changed

3 files changed

+140
-2
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.search;
11+
12+
import org.elasticsearch.action.admin.indices.readonly.AddIndexBlockRequest;
13+
import org.elasticsearch.action.admin.indices.readonly.TransportAddIndexBlockAction;
14+
import org.elasticsearch.action.search.ClosePointInTimeRequest;
15+
import org.elasticsearch.action.search.OpenPointInTimeRequest;
16+
import org.elasticsearch.action.search.SearchRequest;
17+
import org.elasticsearch.action.search.SearchResponse;
18+
import org.elasticsearch.action.search.TransportClosePointInTimeAction;
19+
import org.elasticsearch.action.search.TransportOpenPointInTimeAction;
20+
import org.elasticsearch.cluster.metadata.IndexMetadata;
21+
import org.elasticsearch.common.bytes.BytesReference;
22+
import org.elasticsearch.core.TimeValue;
23+
import org.elasticsearch.index.query.QueryBuilders;
24+
import org.elasticsearch.search.builder.PointInTimeBuilder;
25+
import org.elasticsearch.search.builder.SearchSourceBuilder;
26+
import org.elasticsearch.test.ESIntegTestCase;
27+
28+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
29+
30+
public class SearchWithIndexBlocksIT extends ESIntegTestCase {
31+
32+
public void testSearchIndexWithIndexRefreshBlock() {
33+
createIndex("test");
34+
35+
var addIndexBlockRequest = new AddIndexBlockRequest(IndexMetadata.APIBlock.REFRESH, "test");
36+
client().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest).actionGet();
37+
38+
indexRandom(
39+
true,
40+
prepareIndex("test").setId("1").setSource("field", "value"),
41+
prepareIndex("test").setId("2").setSource("field", "value"),
42+
prepareIndex("test").setId("3").setSource("field", "value"),
43+
prepareIndex("test").setId("4").setSource("field", "value"),
44+
prepareIndex("test").setId("5").setSource("field", "value"),
45+
prepareIndex("test").setId("6").setSource("field", "value")
46+
);
47+
48+
assertHitCount(prepareSearch().setQuery(QueryBuilders.matchAllQuery()), 0);
49+
}
50+
51+
public void testSearchMultipleIndicesEachWithAnIndexRefreshBlock() {
52+
createIndex("test");
53+
createIndex("test2");
54+
55+
var addIndexBlockRequest = new AddIndexBlockRequest(IndexMetadata.APIBlock.REFRESH, "test", "test2");
56+
client().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest).actionGet();
57+
58+
indexRandom(
59+
true,
60+
prepareIndex("test").setId("1").setSource("field", "value"),
61+
prepareIndex("test").setId("2").setSource("field", "value"),
62+
prepareIndex("test").setId("3").setSource("field", "value"),
63+
prepareIndex("test").setId("4").setSource("field", "value"),
64+
prepareIndex("test").setId("5").setSource("field", "value"),
65+
prepareIndex("test").setId("6").setSource("field", "value"),
66+
prepareIndex("test2").setId("1").setSource("field", "value"),
67+
prepareIndex("test2").setId("2").setSource("field", "value"),
68+
prepareIndex("test2").setId("3").setSource("field", "value"),
69+
prepareIndex("test2").setId("4").setSource("field", "value"),
70+
prepareIndex("test2").setId("5").setSource("field", "value"),
71+
prepareIndex("test2").setId("6").setSource("field", "value")
72+
);
73+
74+
assertHitCount(prepareSearch().setQuery(QueryBuilders.matchAllQuery()), 0);
75+
}
76+
77+
public void testSearchMultipleIndicesWithOneIndexRefreshBlock() {
78+
createIndex("test");
79+
createIndex("test2");
80+
81+
// Only block test
82+
var addIndexBlockRequest = new AddIndexBlockRequest(IndexMetadata.APIBlock.REFRESH, "test");
83+
client().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest).actionGet();
84+
85+
indexRandom(
86+
true,
87+
prepareIndex("test").setId("1").setSource("field", "value"),
88+
prepareIndex("test").setId("2").setSource("field", "value"),
89+
prepareIndex("test").setId("3").setSource("field", "value"),
90+
prepareIndex("test").setId("4").setSource("field", "value"),
91+
prepareIndex("test").setId("5").setSource("field", "value"),
92+
prepareIndex("test").setId("6").setSource("field", "value"),
93+
prepareIndex("test2").setId("1").setSource("field", "value"),
94+
prepareIndex("test2").setId("2").setSource("field", "value"),
95+
prepareIndex("test2").setId("3").setSource("field", "value"),
96+
prepareIndex("test2").setId("4").setSource("field", "value"),
97+
prepareIndex("test2").setId("5").setSource("field", "value"),
98+
prepareIndex("test2").setId("6").setSource("field", "value")
99+
);
100+
101+
// We should get test2 results (not blocked)
102+
assertHitCount(prepareSearch().setQuery(QueryBuilders.matchAllQuery()), 6);
103+
}
104+
105+
public void testOpenPITWithIndexRefreshBlock() {
106+
createIndex("test");
107+
108+
var addIndexBlockRequest = new AddIndexBlockRequest(IndexMetadata.APIBlock.REFRESH, "test");
109+
client().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest).actionGet();
110+
111+
indexRandom(
112+
true,
113+
prepareIndex("test").setId("1").setSource("field", "value"),
114+
prepareIndex("test").setId("2").setSource("field", "value"),
115+
prepareIndex("test").setId("3").setSource("field", "value"),
116+
prepareIndex("test").setId("4").setSource("field", "value"),
117+
prepareIndex("test").setId("5").setSource("field", "value"),
118+
prepareIndex("test").setId("6").setSource("field", "value")
119+
);
120+
121+
BytesReference pitId = null;
122+
try {
123+
OpenPointInTimeRequest openPITRequest = new OpenPointInTimeRequest("test").keepAlive(TimeValue.timeValueSeconds(10))
124+
.allowPartialSearchResults(true);
125+
pitId = client().execute(TransportOpenPointInTimeAction.TYPE, openPITRequest).actionGet().getPointInTimeId();
126+
SearchRequest searchRequest = new SearchRequest().source(
127+
new SearchSourceBuilder().pointInTimeBuilder(new PointInTimeBuilder(pitId).setKeepAlive(TimeValue.timeValueSeconds(10)))
128+
);
129+
SearchResponse searchResponse = client().search(searchRequest).actionGet();
130+
assertHitCount(searchResponse, 0);
131+
} finally {
132+
if (pitId != null) {
133+
client().execute(TransportClosePointInTimeAction.TYPE, new ClosePointInTimeRequest(pitId)).actionGet();
134+
}
135+
}
136+
}
137+
}

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ public enum APIBlock implements Writeable {
283283
READ("read", INDEX_READ_BLOCK, Property.ServerlessPublic),
284284
WRITE("write", INDEX_WRITE_BLOCK, Property.ServerlessPublic),
285285
METADATA("metadata", INDEX_METADATA_BLOCK, Property.ServerlessPublic),
286-
READ_ONLY_ALLOW_DELETE("read_only_allow_delete", INDEX_READ_ONLY_ALLOW_DELETE_BLOCK);
286+
READ_ONLY_ALLOW_DELETE("read_only_allow_delete", INDEX_READ_ONLY_ALLOW_DELETE_BLOCK),
287+
REFRESH("refresh", INDEX_REFRESH_BLOCK);
287288

288289
final String name;
289290
final String settingName;

server/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ public void onFailure(Exception ex) {
18171817
}
18181818
}
18191819

1820-
public void testSkippedIndicesWithRefreshBlock() {
1820+
public void testSkippedIteratorsForIndicesWithRefreshBlock() {
18211821
final ProjectId projectId = randomProjectIdOrDefault();
18221822

18231823
String normalIndexName = "test-normal";

0 commit comments

Comments
 (0)