1919
2020package org .elasticsearch .indices .recovery ;
2121
22- import org .apache .lucene .util .Constants ;
2322import org .elasticsearch .action .DocWriteResponse ;
2423import org .elasticsearch .action .admin .cluster .health .ClusterHealthResponse ;
24+ import org .elasticsearch .action .admin .cluster .node .hotthreads .NodeHotThreads ;
2525import org .elasticsearch .action .delete .DeleteResponse ;
2626import org .elasticsearch .action .index .IndexResponse ;
2727import org .elasticsearch .cluster .ClusterState ;
2828import org .elasticsearch .cluster .node .DiscoveryNode ;
2929import org .elasticsearch .cluster .routing .allocation .command .MoveAllocationCommand ;
3030import org .elasticsearch .common .Priority ;
3131import org .elasticsearch .common .settings .Settings ;
32+ import org .elasticsearch .common .unit .TimeValue ;
3233import org .elasticsearch .index .query .QueryBuilders ;
3334import org .elasticsearch .test .ESIntegTestCase ;
3435import org .elasticsearch .test .hamcrest .ElasticsearchAssertions ;
3536
3637import java .util .concurrent .atomic .AtomicBoolean ;
3738import java .util .concurrent .atomic .AtomicInteger ;
39+ import java .util .stream .Collectors ;
3840
39- import static org .hamcrest .Matchers .equalTo ;
4041
4142@ ESIntegTestCase .ClusterScope (scope = ESIntegTestCase .Scope .TEST )
4243public class IndexPrimaryRelocationIT extends ESIntegTestCase {
4344
4445 private static final int RELOCATION_COUNT = 15 ;
4546
4647 public void testPrimaryRelocationWhileIndexing () throws Exception {
47- assumeFalse ("https://github.com/elastic/elasticsearch/issues/46526" , Constants .MAC_OS_X );
4848 internalCluster ().ensureAtLeastNumDataNodes (randomIntBetween (2 , 3 ));
4949 client ().admin ().indices ().prepareCreate ("test" )
5050 .setSettings (Settings .builder ().put ("index.number_of_shards" , 1 ).put ("index.number_of_replicas" , 0 ))
@@ -56,7 +56,7 @@ public void testPrimaryRelocationWhileIndexing() throws Exception {
5656 Thread indexingThread = new Thread () {
5757 @ Override
5858 public void run () {
59- while (finished .get () == false ) {
59+ while (finished .get () == false && numAutoGenDocs . get () < 10_000 ) {
6060 IndexResponse indexResponse = client ().prepareIndex ("test" , "type" , "id" ).setSource ("field" , "value" ).get ();
6161 assertEquals (DocWriteResponse .Result .CREATED , indexResponse .getResult ());
6262 DeleteResponse deleteResponse = client ().prepareDelete ("test" , "type" , "id" ).get ();
@@ -82,8 +82,18 @@ public void run() {
8282 .add (new MoveAllocationCommand ("test" , 0 , relocationSource .getId (), relocationTarget .getId ()))
8383 .execute ().actionGet ();
8484 ClusterHealthResponse clusterHealthResponse = client ().admin ().cluster ().prepareHealth ()
85+ .setTimeout (TimeValue .timeValueSeconds (60 ))
8586 .setWaitForEvents (Priority .LANGUID ).setWaitForNoRelocatingShards (true ).execute ().actionGet ();
86- assertThat (clusterHealthResponse .isTimedOut (), equalTo (false ));
87+ if (clusterHealthResponse .isTimedOut ()) {
88+ final String hotThreads = client ().admin ().cluster ().prepareNodesHotThreads ().setIgnoreIdleThreads (false ).get ().getNodes ()
89+ .stream ().map (NodeHotThreads ::getHotThreads ).collect (Collectors .joining ("\n " ));
90+ final ClusterState clusterState = client ().admin ().cluster ().prepareState ().get ().getState ();
91+ logger .info ("timed out for waiting for relocation iteration [{}] \n cluster state {} \n hot threads {}" ,
92+ i , clusterState , hotThreads );
93+ finished .set (true );
94+ indexingThread .join ();
95+ throw new AssertionError ("timed out waiting for relocation iteration [" + i + "] " );
96+ }
8797 logger .info ("--> [iteration {}] relocation complete" , i );
8898 relocationSource = relocationTarget ;
8999 // indexing process aborted early, no need for more relocations as test has already failed
0 commit comments