@@ -197,6 +197,10 @@ public int count() {
197197 return count ;
198198 }
199199
200+ public Set <ProjectRepo > repos () {
201+ return entries .keySet ();
202+ }
203+
200204 public Iterable <List <Entry >> entriesByRepo () {
201205 return () -> Iterators .map (entries .values ().iterator (), byRepo -> byRepo .entries );
202206 }
@@ -504,7 +508,7 @@ private static boolean assertShardStateConsistent(
504508 int shardId ,
505509 ShardSnapshotStatus shardSnapshotStatus
506510 ) {
507- if (shardSnapshotStatus .isActive ()) {
511+ if (shardSnapshotStatus .isActiveOrAssignedQueued ()) {
508512 Tuple <String , Integer > plainShardId = Tuple .tuple (indexName , shardId );
509513 assert assignedShards .add (plainShardId ) : plainShardId + " is assigned twice in " + entries ;
510514 assert queuedShards .contains (plainShardId ) == false : plainShardId + " is queued then assigned in " + entries ;
@@ -752,6 +756,19 @@ public static ShardSnapshotStatus success(String nodeId, ShardSnapshotResult sha
752756 return new ShardSnapshotStatus (nodeId , ShardState .SUCCESS , shardSnapshotResult .getGeneration (), null , shardSnapshotResult );
753757 }
754758
759+ @ SuppressForbidden (reason = "using a private constructor within the same file" )
760+ public static ShardSnapshotStatus assignedQueued (String nodeId , ShardGeneration generation ) {
761+ return new ShardSnapshotStatus (nodeId , ShardState .QUEUED , generation , null , null );
762+ }
763+
764+ public boolean isAssignedQueued () {
765+ return state == ShardState .QUEUED && nodeId != null && generation != null ;
766+ }
767+
768+ public boolean isUnassignedQueued () {
769+ return this == UNASSIGNED_QUEUED || (state == ShardState .QUEUED && nodeId == null && generation == null );
770+ }
771+
755772 public ShardSnapshotStatus (
756773 @ Nullable String nodeId ,
757774 ShardState state ,
@@ -772,8 +789,16 @@ private boolean assertConsistent() {
772789 assert state .failed () == false || reason != null ;
773790 assert (state != ShardState .INIT && state != ShardState .WAITING && state != ShardState .PAUSED_FOR_NODE_REMOVAL )
774791 || nodeId != null : "Null node id for state [" + state + "]" ;
775- assert state != ShardState .QUEUED || (nodeId == null && generation == null && reason == null )
776- : "Found unexpected non-null values for queued state shard nodeId[" + nodeId + "][" + generation + "][" + reason + "]" ;
792+ assert state != ShardState .QUEUED || (isUnassignedQueued () || isAssignedQueued ())
793+ : "Found unexpected shard state=["
794+ + state
795+ + "], nodeId=["
796+ + nodeId
797+ + "], generation=["
798+ + generation
799+ + "], reason=["
800+ + reason
801+ + "]" ;
777802 assert state == ShardState .SUCCESS || shardSnapshotResult == null ;
778803 assert shardSnapshotResult == null || shardSnapshotResult .getGeneration ().equals (generation )
779804 : "generation [" + generation + "] does not match result generation [" + shardSnapshotResult .getGeneration () + "]" ;
@@ -787,7 +812,7 @@ public static ShardSnapshotStatus readFrom(StreamInput in) throws IOException {
787812 final ShardGeneration generation = in .readOptionalWriteable (ShardGeneration ::new );
788813 final String reason = in .readOptionalString ();
789814 final ShardSnapshotResult shardSnapshotResult = in .readOptionalWriteable (ShardSnapshotResult ::new );
790- if (state == ShardState .QUEUED ) {
815+ if (state == ShardState .QUEUED && nodeId == null && generation == null ) {
791816 return UNASSIGNED_QUEUED ;
792817 }
793818 return new ShardSnapshotStatus (nodeId , state , generation , reason , shardSnapshotResult );
@@ -819,13 +844,18 @@ public ShardSnapshotResult shardSnapshotResult() {
819844 * ({@link ShardState#INIT} or {@link ShardState#ABORTED}) or about to write to it in state {@link ShardState#WAITING} or
820845 * {@link ShardState#PAUSED_FOR_NODE_REMOVAL}.
821846 */
847+ // TODO: review its usage again
822848 public boolean isActive () {
823849 return switch (state ) {
824850 case INIT , ABORTED , WAITING , PAUSED_FOR_NODE_REMOVAL -> true ;
825851 case SUCCESS , FAILED , MISSING , QUEUED -> false ;
826852 };
827853 }
828854
855+ public boolean isActiveOrAssignedQueued () {
856+ return isActive () || isAssignedQueued ();
857+ }
858+
829859 @ Override
830860 public void writeTo (StreamOutput out ) throws IOException {
831861 out .writeOptionalString (nodeId );
@@ -1210,7 +1240,7 @@ public Entry abort() {
12101240 final String nodeId = status .nodeId ();
12111241 status = new ShardSnapshotStatus (
12121242 nodeId ,
1213- nodeId == null ? ShardState .FAILED : ShardState .ABORTED ,
1243+ nodeId == null ? ShardState .FAILED : ShardState .ABORTED , // TODO: Aborted if assigned queued?
12141244 status .generation (),
12151245 "aborted by snapshot deletion"
12161246 );
0 commit comments