|
41 | 41 | import org.elasticsearch.cluster.node.VersionInformation;
|
42 | 42 | import org.elasticsearch.cluster.project.TestProjectResolvers;
|
43 | 43 | import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
| 44 | +import org.elasticsearch.cluster.routing.OperationRouting; |
| 45 | +import org.elasticsearch.cluster.routing.ShardIterator; |
44 | 46 | import org.elasticsearch.cluster.routing.ShardRouting;
|
45 | 47 | import org.elasticsearch.cluster.routing.ShardRoutingState;
|
46 | 48 | import org.elasticsearch.cluster.routing.TestShardRouting;
|
|
133 | 135 | import static org.hamcrest.Matchers.hasSize;
|
134 | 136 | import static org.mockito.ArgumentMatchers.any;
|
135 | 137 | import static org.mockito.ArgumentMatchers.anyBoolean;
|
| 138 | +import static org.mockito.ArgumentMatchers.eq; |
| 139 | +import static org.mockito.ArgumentMatchers.nullable; |
136 | 140 | import static org.mockito.Mockito.mock;
|
137 | 141 | import static org.mockito.Mockito.when;
|
138 | 142 |
|
@@ -1812,4 +1816,106 @@ public void onFailure(Exception ex) {
|
1812 | 1816 | assertTrue(ESTestCase.terminate(threadPool));
|
1813 | 1817 | }
|
1814 | 1818 | }
|
| 1819 | + |
| 1820 | + public void testSkippedIndicesWithRefreshBlock() { |
| 1821 | + final ProjectId projectId = randomProjectIdOrDefault(); |
| 1822 | + |
| 1823 | + String normalIndexName = "test-normal"; |
| 1824 | + String blockedIndexName = "test-blocked"; |
| 1825 | + final String[] indexNames = {normalIndexName, blockedIndexName}; |
| 1826 | + final Index normalIndex = new Index(normalIndexName, UUIDs.randomBase64UUID()); |
| 1827 | + final Index blockedIndex = new Index(blockedIndexName, UUIDs.randomBase64UUID()); |
| 1828 | + final int numberOfShards = randomIntBetween(1, 3); |
| 1829 | + final int numberOfReplicas = randomIntBetween(0, 1); |
| 1830 | + final int totalShards = numberOfShards + numberOfShards * numberOfReplicas; |
| 1831 | + |
| 1832 | + ClusterState clusterState = ClusterStateCreationUtils.stateWithAssignedPrimariesAndReplicas( |
| 1833 | + projectId, |
| 1834 | + indexNames, |
| 1835 | + numberOfShards, |
| 1836 | + numberOfReplicas |
| 1837 | + ); |
| 1838 | + ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder().blocks(clusterState.blocks()); |
| 1839 | + blocksBuilder.addIndexBlock(projectId, "test-blocked", IndexMetadata.INDEX_REFRESH_BLOCK); |
| 1840 | + clusterState = ClusterState.builder(clusterState).blocks(blocksBuilder).build(); |
| 1841 | + List<ShardIterator> shardIts = new ArrayList<>(); |
| 1842 | + for (int i = 0; i < totalShards; i++) { |
| 1843 | + shardIts.add(new ShardIterator(new ShardId(normalIndex, randomInt()), Collections.emptyList())); |
| 1844 | + shardIts.add(new ShardIterator(new ShardId(blockedIndex, randomInt()), Collections.emptyList())); |
| 1845 | + } |
| 1846 | + final OperationRouting operationRouting = mock(OperationRouting.class); |
| 1847 | + when( |
| 1848 | + operationRouting.searchShards( |
| 1849 | + eq(clusterState.projectState(projectId)), |
| 1850 | + eq(indexNames), |
| 1851 | + any(), |
| 1852 | + nullable(String.class), |
| 1853 | + any(), |
| 1854 | + any() |
| 1855 | + ) |
| 1856 | + ).thenReturn(shardIts); |
| 1857 | + ClusterService clusterService = mock(ClusterService.class); |
| 1858 | + when(clusterService.state()).thenReturn(clusterState); |
| 1859 | + when(clusterService.getSettings()).thenReturn(Settings.EMPTY); |
| 1860 | + when(clusterService.operationRouting()).thenReturn(operationRouting); |
| 1861 | + |
| 1862 | + Settings settings = Settings.builder() |
| 1863 | + .put("node.name", TransportSearchAction.class.getSimpleName()) |
| 1864 | + .build(); |
| 1865 | + TransportVersion transportVersion = TransportVersionUtils.getNextVersion(TransportVersions.MINIMUM_CCS_VERSION, true); |
| 1866 | + ThreadPool threadPool = new ThreadPool(settings, MeterRegistry.NOOP, new DefaultBuiltInExecutorBuilders()); |
| 1867 | + try { |
| 1868 | + TransportService transportService = MockTransportService.createNewService( |
| 1869 | + Settings.EMPTY, |
| 1870 | + VersionInformation.CURRENT, |
| 1871 | + transportVersion, |
| 1872 | + threadPool |
| 1873 | + ); |
| 1874 | + NodeClient client = new NodeClient(settings, threadPool); |
| 1875 | + SearchService searchService = mock(SearchService.class); |
| 1876 | + when(searchService.getRewriteContext(any(), any(), any(), anyBoolean())).thenReturn( |
| 1877 | + new QueryRewriteContext(null, null, null, null, null, null) |
| 1878 | + ); |
| 1879 | + |
| 1880 | + TransportSearchAction transportSearchAction = new TransportSearchAction( |
| 1881 | + threadPool, |
| 1882 | + new NoneCircuitBreakerService(), |
| 1883 | + transportService, |
| 1884 | + searchService, |
| 1885 | + null, |
| 1886 | + new SearchTransportService(transportService, client, null), |
| 1887 | + null, |
| 1888 | + clusterService, |
| 1889 | + new ActionFilters(Collections.emptySet()), |
| 1890 | + TestProjectResolvers.usingRequestHeader(threadPool.getThreadContext()), |
| 1891 | + TestIndexNameExpressionResolver.newInstance(threadPool.getThreadContext()), |
| 1892 | + null, |
| 1893 | + null, |
| 1894 | + new SearchResponseMetrics(TelemetryProvider.NOOP.getMeterRegistry()), |
| 1895 | + client, |
| 1896 | + new UsageService() |
| 1897 | + ); |
| 1898 | + |
| 1899 | + SearchRequest searchRequest = new SearchRequest(indexNames); |
| 1900 | + searchRequest.allowPartialSearchResults(true); |
| 1901 | + List<SearchShardIterator> searchShardIts = transportSearchAction.getLocalShardsIterator( |
| 1902 | + clusterState.projectState(projectId), |
| 1903 | + searchRequest, |
| 1904 | + searchRequest.getLocalClusterAlias(), |
| 1905 | + new HashSet<>(), |
| 1906 | + indexNames |
| 1907 | + ); |
| 1908 | + |
| 1909 | + assertThat(searchShardIts.size(), equalTo(shardIts.size())); |
| 1910 | + for (SearchShardIterator searchShardIt : searchShardIts) { |
| 1911 | + if (searchShardIt.skip()) { |
| 1912 | + assertThat(searchShardIt.shardId().getIndexName(), equalTo("test-blocked")); |
| 1913 | + } else { |
| 1914 | + assertThat(searchShardIt.shardId().getIndexName(), equalTo("test-normal")); |
| 1915 | + } |
| 1916 | + } |
| 1917 | + } finally { |
| 1918 | + assertTrue(ESTestCase.terminate(threadPool)); |
| 1919 | + } |
| 1920 | + } |
1815 | 1921 | }
|
0 commit comments