@@ -1465,14 +1465,34 @@ 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
14691468 assertThatLogger (
14701469 () -> currentStateHolder .set (
14711470 reconcileAndBuildNewState (
14721471 reconciler ,
14731472 initialClusterState ,
1473+ DesiredBalance .BECOME_MASTER_INITIAL ,
1474+ preventAllocationOnNode2Decider ,
1475+ yesDecider
1476+ )
1477+ ),
1478+ UndesiredAllocationsTracker .class ,
1479+ new MockLog .UnseenEventExpectation (
1480+ "Should not log if desired balance is not yet computed" ,
1481+ UndesiredAllocationsTracker .class .getCanonicalName (),
1482+ Level .WARN ,
1483+ shardInUndesiredAllocationMessage
1484+ )
1485+ );
1486+
1487+ // Desired assignment matches current routing table, should not log
1488+ assertThatLogger (
1489+ () -> currentStateHolder .set (
1490+ reconcileAndBuildNewState (
1491+ reconciler ,
1492+ currentStateHolder .get (),
14741493 new DesiredBalance (1 , allShardsDesiredOnDataNode1 ),
1475- preventAllocationOnNode2Decider
1494+ preventAllocationOnNode2Decider ,
1495+ yesDecider
14761496 )
14771497 ),
14781498 UndesiredAllocationsTracker .class ,
@@ -1507,6 +1527,26 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
15071527 // Advance past the logging threshold
15081528 timeProvider .advanceByMillis (randomLongBetween (undesiredAllocationThreshold .millis (), undesiredAllocationThreshold .millis () * 2 ));
15091529
1530+ // If the desired balance is missing for some reason, we shouldn't log, and we shouldn't reset the became-undesired time
1531+ assertThatLogger (
1532+ () -> currentStateHolder .set (
1533+ reconcileAndBuildNewState (
1534+ reconciler ,
1535+ currentStateHolder .get (),
1536+ new DesiredBalance (1 , Map .of ()),
1537+ preventAllocationOnNode2Decider ,
1538+ yesDecider
1539+ )
1540+ ),
1541+ UndesiredAllocationsTracker .class ,
1542+ new MockLog .UnseenEventExpectation (
1543+ "Should not log because there is no desired allocations" ,
1544+ UndesiredAllocationsTracker .class .getCanonicalName (),
1545+ Level .WARN ,
1546+ shardInUndesiredAllocationMessage
1547+ )
1548+ );
1549+
15101550 // Now it should log
15111551 assertThatLogger (
15121552 () -> currentStateHolder .set (
0 commit comments