@@ -1465,14 +1465,35 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
14651465
14661466 final var shardInUndesiredAllocationMessage = "Shard [" + shardToPreventMovement + "][0] has been in an undesired allocation for *" ;
14671467
1468- // Desired assignment matches current routing table , should not log
1468+ // Desired balance not yet computed , should not log
14691469 assertThatLogger (
14701470 () -> currentStateHolder .set (
14711471 reconcileAndBuildNewState (
14721472 reconciler ,
14731473 initialClusterState ,
1474+ DesiredBalance .BECOME_MASTER_INITIAL ,
1475+ preventAllocationOnNode2Decider ,
1476+ yesDecider
1477+ )
1478+ ),
1479+ UndesiredAllocationsTracker .class ,
1480+ new MockLog .UnseenEventExpectation (
1481+ "Should not log if desired balance is not yet computed" ,
1482+ UndesiredAllocationsTracker .class .getCanonicalName (),
1483+ Level .WARN ,
1484+ shardInUndesiredAllocationMessage
1485+ )
1486+ );
1487+
1488+ // Desired assignment matches current routing table, should not log
1489+ assertThatLogger (
1490+ () -> currentStateHolder .set (
1491+ reconcileAndBuildNewState (
1492+ reconciler ,
1493+ currentStateHolder .get (),
14741494 new DesiredBalance (1 , allShardsDesiredOnDataNode1 ),
1475- preventAllocationOnNode2Decider
1495+ preventAllocationOnNode2Decider ,
1496+ yesDecider
14761497 )
14771498 ),
14781499 UndesiredAllocationsTracker .class ,
@@ -1507,6 +1528,26 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
15071528 // Advance past the logging threshold
15081529 timeProvider .advanceByMillis (randomLongBetween (undesiredAllocationThreshold .millis (), undesiredAllocationThreshold .millis () * 2 ));
15091530
1531+ // If the desired balance is missing for some reason, we shouldn't log, and we shouldn't reset the became-undesired time
1532+ assertThatLogger (
1533+ () -> currentStateHolder .set (
1534+ reconcileAndBuildNewState (
1535+ reconciler ,
1536+ currentStateHolder .get (),
1537+ new DesiredBalance (1 , Map .of ()),
1538+ preventAllocationOnNode2Decider ,
1539+ yesDecider
1540+ )
1541+ ),
1542+ UndesiredAllocationsTracker .class ,
1543+ new MockLog .UnseenEventExpectation (
1544+ "Should not log because there is no desired allocations" ,
1545+ UndesiredAllocationsTracker .class .getCanonicalName (),
1546+ Level .WARN ,
1547+ shardInUndesiredAllocationMessage
1548+ )
1549+ );
1550+
15101551 // Now it should log
15111552 assertThatLogger (
15121553 () -> currentStateHolder .set (
0 commit comments