25
25
import org .elasticsearch .cluster .ClusterState ;
26
26
import org .elasticsearch .cluster .metadata .MetaData ;
27
27
import org .elasticsearch .cluster .node .DiscoveryNode ;
28
+ import org .elasticsearch .cluster .routing .UnassignedInfo .AllocationStatus ;
28
29
import org .elasticsearch .common .Nullable ;
29
30
import org .elasticsearch .common .Randomness ;
30
31
import org .elasticsearch .common .collect .Tuple ;
@@ -641,14 +642,27 @@ public List<ShardRouting> ignored() {
641
642
* Should be used with caution, typically,
642
643
* the correct usage is to removeAndIgnore from the iterator.
643
644
* @see #ignored()
644
- * @see UnassignedIterator#removeAndIgnore()
645
+ * @see UnassignedIterator#removeAndIgnore(AllocationStatus )
645
646
* @see #isIgnoredEmpty()
647
+ * @return true iff the decision caused a change to the unassigned info
646
648
*/
647
- public void ignoreShard (ShardRouting shard ) {
649
+ public boolean ignoreShard (ShardRouting shard , AllocationStatus allocationStatus ) {
650
+ boolean changed = false ;
648
651
if (shard .primary ()) {
649
652
ignoredPrimaries ++;
653
+ UnassignedInfo currInfo = shard .unassignedInfo ();
654
+ assert currInfo != null ;
655
+ if (allocationStatus .equals (currInfo .getLastAllocationStatus ()) == false ) {
656
+ UnassignedInfo newInfo = new UnassignedInfo (currInfo .getReason (), currInfo .getMessage (), currInfo .getFailure (),
657
+ currInfo .getNumFailedAllocations (), currInfo .getUnassignedTimeInNanos (),
658
+ currInfo .getUnassignedTimeInMillis (), currInfo .isDelayed (),
659
+ allocationStatus );
660
+ shard = shard .updateUnassignedInfo (newInfo );
661
+ changed = true ;
662
+ }
650
663
}
651
664
ignored .add (shard );
665
+ return changed ;
652
666
}
653
667
654
668
public class UnassignedIterator implements Iterator <ShardRouting > {
@@ -685,10 +699,13 @@ public ShardRouting initialize(String nodeId, @Nullable String existingAllocatio
685
699
* will be added back to unassigned once the metadata is constructed again).
686
700
* Typically this is used when an allocation decision prevents a shard from being allocated such
687
701
* that subsequent consumers of this API won't try to allocate this shard again.
702
+ *
703
+ * @param attempt the result of the allocation attempt
704
+ * @return true iff the decision caused an update to the unassigned info
688
705
*/
689
- public void removeAndIgnore () {
706
+ public boolean removeAndIgnore (AllocationStatus attempt ) {
690
707
innerRemove ();
691
- ignoreShard (current );
708
+ return ignoreShard (current , attempt );
692
709
}
693
710
694
711
private void updateShardRouting (ShardRouting shardRouting ) {
@@ -721,7 +738,7 @@ public ShardRouting demotePrimaryToReplicaShard() {
721
738
}
722
739
723
740
/**
724
- * Unsupported operation, just there for the interface. Use {@link #removeAndIgnore()} or
741
+ * Unsupported operation, just there for the interface. Use {@link #removeAndIgnore(AllocationStatus )} or
725
742
* {@link #initialize(String, String, long)}.
726
743
*/
727
744
@ Override
@@ -747,8 +764,8 @@ public boolean isEmpty() {
747
764
748
765
/**
749
766
* Returns <code>true</code> iff any unassigned shards are marked as temporarily ignored.
750
- * @see UnassignedShards#ignoreShard(ShardRouting)
751
- * @see UnassignedIterator#removeAndIgnore()
767
+ * @see UnassignedShards#ignoreShard(ShardRouting, AllocationStatus )
768
+ * @see UnassignedIterator#removeAndIgnore(AllocationStatus )
752
769
*/
753
770
public boolean isIgnoredEmpty () {
754
771
return ignored .isEmpty ();
@@ -878,6 +895,7 @@ public static boolean assertShardStats(RoutingNodes routingNodes) {
878
895
assert inactiveShardCount == routingNodes .inactiveShardCount :
879
896
"Inactive Shard count [" + inactiveShardCount + "] but RoutingNodes returned inactive shards [" + routingNodes .inactiveShardCount + "]" ;
880
897
assert routingNodes .getRelocatingShardCount () == relocating : "Relocating shards mismatch [" + routingNodes .getRelocatingShardCount () + "] but expected [" + relocating + "]" ;
898
+
881
899
return true ;
882
900
}
883
901
0 commit comments