use of org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE in project OpenSearch by opensearch-project.
the class SearchServiceTests method testSetSearchThrottled.
public void testSetSearchThrottled() {
createIndex("throttled_threadpool_index");
client().execute(InternalOrPrivateSettingsPlugin.UpdateInternalOrPrivateAction.INSTANCE, new InternalOrPrivateSettingsPlugin.UpdateInternalOrPrivateAction.Request("throttled_threadpool_index", IndexSettings.INDEX_SEARCH_THROTTLED.getKey(), "true")).actionGet();
final SearchService service = getInstanceFromNode(SearchService.class);
Index index = resolveIndex("throttled_threadpool_index");
assertTrue(service.getIndicesService().indexServiceSafe(index).getIndexSettings().isSearchThrottled());
client().prepareIndex("throttled_threadpool_index").setId("1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();
SearchResponse searchResponse = client().prepareSearch("throttled_threadpool_index").setIndicesOptions(IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED).setSize(1).get();
assertSearchHits(searchResponse, "1");
// we add a search action listener in a plugin above to assert that this is actually used
client().execute(InternalOrPrivateSettingsPlugin.UpdateInternalOrPrivateAction.INSTANCE, new InternalOrPrivateSettingsPlugin.UpdateInternalOrPrivateAction.Request("throttled_threadpool_index", IndexSettings.INDEX_SEARCH_THROTTLED.getKey(), "false")).actionGet();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().prepareUpdateSettings("throttled_threadpool_index").setSettings(Settings.builder().put(IndexSettings.INDEX_SEARCH_THROTTLED.getKey(), false)).get());
assertEquals("can not update private setting [index.search.throttled]; this setting is managed by OpenSearch", iae.getMessage());
assertFalse(service.getIndicesService().indexServiceSafe(index).getIndexSettings().isSearchThrottled());
SearchRequest searchRequest = new SearchRequest().allowPartialSearchResults(false);
ShardSearchRequest req = new ShardSearchRequest(OriginalIndices.NONE, searchRequest, new ShardId(index, 0), 1, new AliasFilter(null, Strings.EMPTY_ARRAY), 1f, -1, null, null);
Thread currentThread = Thread.currentThread();
// we still make sure can match is executed on the network thread
service.canMatch(req, ActionListener.wrap(r -> assertSame(Thread.currentThread(), currentThread), e -> fail("unexpected")));
}
use of org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE in project OpenSearch by opensearch-project.
the class UnsafeBootstrapAndDetachCommandIT method testAllClusterManagerEligibleNodesFailedDanglingIndexImport.
public void testAllClusterManagerEligibleNodesFailedDanglingIndexImport() throws Exception {
internalCluster().setBootstrapClusterManagerNodeIndex(0);
Settings settings = Settings.builder().put(AUTO_IMPORT_DANGLING_INDICES_SETTING.getKey(), true).build();
logger.info("--> start mixed data and cluster-manager-eligible node and bootstrap cluster");
// node ordinal 0
String clusterManagerNode = internalCluster().startNode(settings);
logger.info("--> start data-only node and ensure 2 nodes stable cluster");
// node ordinal 1
String dataNode = internalCluster().startDataOnlyNode(settings);
ensureStableCluster(2);
logger.info("--> index 1 doc and ensure index is green");
client().prepareIndex("test").setId("1").setSource("field1", "value1").setRefreshPolicy(IMMEDIATE).get();
ensureGreen("test");
assertBusy(() -> internalCluster().getInstances(IndicesService.class).forEach(indicesService -> assertTrue(indicesService.allPendingDanglingIndicesWritten())));
logger.info("--> verify 1 doc in the index");
assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
assertThat(client().prepareGet("test", "1").execute().actionGet().isExists(), equalTo(true));
logger.info("--> stop data-only node and detach it from the old cluster");
Settings dataNodeDataPathSettings = Settings.builder().put(internalCluster().dataPathSettings(dataNode), true).put(AUTO_IMPORT_DANGLING_INDICES_SETTING.getKey(), true).build();
assertBusy(() -> internalCluster().getInstance(GatewayMetaState.class, dataNode).allPendingAsyncStatesWritten());
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(dataNode));
final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataNodeDataPathSettings).put(AUTO_IMPORT_DANGLING_INDICES_SETTING.getKey(), true).build());
detachCluster(environment, false);
logger.info("--> stop cluster-manager-eligible node, clear its data and start it again - new cluster should form");
internalCluster().restartNode(clusterManagerNode, new InternalTestCluster.RestartCallback() {
@Override
public boolean clearData(String nodeName) {
return true;
}
});
logger.info("--> start data-only only node and ensure 2 nodes stable cluster");
internalCluster().startDataOnlyNode(dataNodeDataPathSettings);
ensureStableCluster(2);
logger.info("--> verify that the dangling index exists and has green status");
assertBusy(() -> {
assertThat(client().admin().indices().prepareExists("test").execute().actionGet().isExists(), equalTo(true));
});
ensureGreen("test");
logger.info("--> verify the doc is there");
assertThat(client().prepareGet("test", "1").execute().actionGet().isExists(), equalTo(true));
}
use of org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE in project OpenSearch by opensearch-project.
the class IndexShardIT method testShardHasMemoryBufferOnTranslogRecover.
public void testShardHasMemoryBufferOnTranslogRecover() throws Throwable {
createIndex("test");
ensureGreen();
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
IndexService indexService = indicesService.indexService(resolveIndex("test"));
IndexShard shard = indexService.getShardOrNull(0);
client().prepareIndex("test").setId("0").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get();
client().prepareDelete("test", "0").get();
client().prepareIndex("test").setId("1").setSource("{\"foo\" : \"bar\"}", XContentType.JSON).setRefreshPolicy(IMMEDIATE).get();
CheckedFunction<DirectoryReader, DirectoryReader, IOException> wrapper = directoryReader -> directoryReader;
shard.close("simon says", false);
AtomicReference<IndexShard> shardRef = new AtomicReference<>();
List<Exception> failures = new ArrayList<>();
IndexingOperationListener listener = new IndexingOperationListener() {
@Override
public void postIndex(ShardId shardId, Engine.Index index, Engine.IndexResult result) {
try {
assertNotNull(shardRef.get());
// this is all IMC needs to do - check current memory and refresh
assertTrue(shardRef.get().getIndexBufferRAMBytesUsed() > 0);
shardRef.get().refresh("test");
} catch (Exception e) {
failures.add(e);
throw e;
}
}
@Override
public void postDelete(ShardId shardId, Engine.Delete delete, Engine.DeleteResult result) {
try {
assertNotNull(shardRef.get());
// this is all IMC needs to do - check current memory and refresh
assertTrue(shardRef.get().getIndexBufferRAMBytesUsed() > 0);
shardRef.get().refresh("test");
} catch (Exception e) {
failures.add(e);
throw e;
}
}
};
final IndexShard newShard = newIndexShard(indexService, shard, wrapper, getInstanceFromNode(CircuitBreakerService.class), listener);
shardRef.set(newShard);
recoverShard(newShard);
try {
ExceptionsHelper.rethrowAndSuppress(failures);
} finally {
newShard.close("just do it", randomBoolean());
}
}
use of org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE in project OpenSearch by opensearch-project.
the class GatewayIndexStateIT method testRecoverMissingAnalyzer.
/**
* This test really tests worst case scenario where we have a missing analyzer setting.
* In that case we now have the ability to check the index on local recovery from disk
* if it is sane and if we can successfully create an IndexService.
* This also includes plugins etc.
*/
public void testRecoverMissingAnalyzer() throws Exception {
logger.info("--> starting one node");
internalCluster().startNode();
prepareCreate("test").setSettings(Settings.builder().put("index.analysis.analyzer.test.tokenizer", "standard").put("index.number_of_shards", "1")).setMapping("{\n" + " \"properties\": {\n" + " \"field1\": {\n" + " \"type\": \"text\",\n" + " \"analyzer\": \"test\"\n" + " }\n" + " }\n" + " }").get();
logger.info("--> indexing a simple document");
client().prepareIndex("test").setId("1").setSource("field1", "value one").setRefreshPolicy(IMMEDIATE).get();
logger.info("--> waiting for green status");
if (usually()) {
ensureYellow();
} else {
internalCluster().startNode();
client().admin().cluster().health(Requests.clusterHealthRequest().waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForNoRelocatingShards(true).waitForNodes("2")).actionGet();
}
ClusterState state = client().admin().cluster().prepareState().get().getState();
final IndexMetadata metadata = state.getMetadata().index("test");
final IndexMetadata.Builder brokenMeta = IndexMetadata.builder(metadata).settings(metadata.getSettings().filter((s) -> "index.analysis.analyzer.test.tokenizer".equals(s) == false));
restartNodesOnBrokenClusterState(ClusterState.builder(state).metadata(Metadata.builder(state.getMetadata()).put(brokenMeta)));
// check that the cluster does not keep reallocating shards
assertBusy(() -> {
final RoutingTable routingTable = client().admin().cluster().prepareState().get().getState().routingTable();
final IndexRoutingTable indexRoutingTable = routingTable.index("test");
assertNotNull(indexRoutingTable);
for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) {
assertTrue(shardRoutingTable.primaryShard().unassigned());
assertEquals(UnassignedInfo.AllocationStatus.DECIDERS_NO, shardRoutingTable.primaryShard().unassignedInfo().getLastAllocationStatus());
assertThat(shardRoutingTable.primaryShard().unassignedInfo().getNumFailedAllocations(), greaterThan(0));
}
}, 60, TimeUnit.SECONDS);
client().admin().indices().prepareClose("test").get();
// try to open it with the broken setting - fail again!
OpenSearchException ex = expectThrows(OpenSearchException.class, () -> client().admin().indices().prepareOpen("test").get());
assertEquals(ex.getMessage(), "Failed to verify index " + metadata.getIndex());
assertNotNull(ex.getCause());
assertEquals(MapperParsingException.class, ex.getCause().getClass());
assertThat(ex.getCause().getMessage(), containsString("analyzer [test] has not been configured in mappings"));
}
use of org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE in project OpenSearch by opensearch-project.
the class UnsafeBootstrapAndDetachCommandIT method testAllMasterEligibleNodesFailedDanglingIndexImport.
public void testAllMasterEligibleNodesFailedDanglingIndexImport() throws Exception {
internalCluster().setBootstrapMasterNodeIndex(0);
Settings settings = Settings.builder().put(AUTO_IMPORT_DANGLING_INDICES_SETTING.getKey(), true).build();
logger.info("--> start mixed data and master-eligible node and bootstrap cluster");
// node ordinal 0
String masterNode = internalCluster().startNode(settings);
logger.info("--> start data-only node and ensure 2 nodes stable cluster");
// node ordinal 1
String dataNode = internalCluster().startDataOnlyNode(settings);
ensureStableCluster(2);
logger.info("--> index 1 doc and ensure index is green");
client().prepareIndex("test").setId("1").setSource("field1", "value1").setRefreshPolicy(IMMEDIATE).get();
ensureGreen("test");
assertBusy(() -> internalCluster().getInstances(IndicesService.class).forEach(indicesService -> assertTrue(indicesService.allPendingDanglingIndicesWritten())));
logger.info("--> verify 1 doc in the index");
assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
assertThat(client().prepareGet("test", "1").execute().actionGet().isExists(), equalTo(true));
logger.info("--> stop data-only node and detach it from the old cluster");
Settings dataNodeDataPathSettings = Settings.builder().put(internalCluster().dataPathSettings(dataNode), true).put(AUTO_IMPORT_DANGLING_INDICES_SETTING.getKey(), true).build();
assertBusy(() -> internalCluster().getInstance(GatewayMetaState.class, dataNode).allPendingAsyncStatesWritten());
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(dataNode));
final Environment environment = TestEnvironment.newEnvironment(Settings.builder().put(internalCluster().getDefaultSettings()).put(dataNodeDataPathSettings).put(AUTO_IMPORT_DANGLING_INDICES_SETTING.getKey(), true).build());
detachCluster(environment, false);
logger.info("--> stop master-eligible node, clear its data and start it again - new cluster should form");
internalCluster().restartNode(masterNode, new InternalTestCluster.RestartCallback() {
@Override
public boolean clearData(String nodeName) {
return true;
}
});
logger.info("--> start data-only only node and ensure 2 nodes stable cluster");
internalCluster().startDataOnlyNode(dataNodeDataPathSettings);
ensureStableCluster(2);
logger.info("--> verify that the dangling index exists and has green status");
assertBusy(() -> {
assertThat(client().admin().indices().prepareExists("test").execute().actionGet().isExists(), equalTo(true));
});
ensureGreen("test");
logger.info("--> verify the doc is there");
assertThat(client().prepareGet("test", "1").execute().actionGet().isExists(), equalTo(true));
}
Aggregations