Skip to content

Commit

Permalink
Remove isSegRepEnabled check and use _primary_first preference
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <[email protected]>
  • Loading branch information
dreamer-89 committed Aug 30, 2023
1 parent 83df304 commit 02825b3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ private List<DataSourceMetadata> searchInDataSourcesIndex(ClusterState state, Qu
searchSourceBuilder.query(query);
searchSourceBuilder.size(DATASOURCE_QUERY_RESULT_SIZE);
searchRequest.source(searchSourceBuilder);
if (state.isSegmentReplicationEnabled(DATASOURCE_INDEX_NAME)) {
// https://github.com/opensearch-project/sql/issues/1801.
searchRequest.preference("_primary");
}
// https://github.com/opensearch-project/sql/issues/1801.
searchRequest.preference("_primary_first");
ActionFuture<SearchResponse> searchResponseActionFuture;
try (ThreadContext.StoredContext ignored =
client.threadPool().getThreadContext().stashContext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,6 @@ public void testGetDataSourceMetadata() {
"basicauth", dataSourceMetadata.getProperties().get("prometheus.auth.type"));
}

@SneakyThrows
@Test
public void testGetDataSourceMetadataWithSegRepEnabled() {
Mockito.when(clusterService.state().routingTable().hasIndex(DATASOURCE_INDEX_NAME))
.thenReturn(true);
Mockito.when(clusterService.state().isSegmentReplicationEnabled(DATASOURCE_INDEX_NAME))
.thenReturn(true);
Mockito.when(client.search(ArgumentMatchers.any())).thenReturn(searchResponseActionFuture);
Mockito.when(searchResponseActionFuture.actionGet()).thenReturn(searchResponse);
Mockito.when(searchResponse.status()).thenReturn(RestStatus.OK);
Mockito.when(searchResponse.getHits())
.thenReturn(
new SearchHits(
new SearchHit[] {searchHit}, new TotalHits(21, TotalHits.Relation.EQUAL_TO), 1.0F));
Mockito.when(searchHit.getSourceAsString()).thenReturn(getBasicDataSourceMetadataString());
Mockito.when(encryptor.decrypt("password")).thenReturn("password");
Mockito.when(encryptor.decrypt("username")).thenReturn("username");

Optional<DataSourceMetadata> dataSourceMetadataOptional =
openSearchDataSourceMetadataStorage.getDataSourceMetadata(TEST_DATASOURCE_INDEX_NAME);

Assertions.assertFalse(dataSourceMetadataOptional.isEmpty());
DataSourceMetadata dataSourceMetadata = dataSourceMetadataOptional.get();
Assertions.assertEquals(TEST_DATASOURCE_INDEX_NAME, dataSourceMetadata.getName());
Assertions.assertEquals(DataSourceType.PROMETHEUS, dataSourceMetadata.getConnector());
Assertions.assertEquals(
"password", dataSourceMetadata.getProperties().get("prometheus.auth.password"));
Assertions.assertEquals(
"username", dataSourceMetadata.getProperties().get("prometheus.auth.username"));
Assertions.assertEquals(
"basicauth", dataSourceMetadata.getProperties().get("prometheus.auth.type"));
}

@SneakyThrows
@Test
public void testGetDataSourceMetadataWith404SearchResponse() {
Expand Down

0 comments on commit 02825b3

Please sign in to comment.