41
41
import java .util .Arrays ;
42
42
import java .util .Collections ;
43
43
import java .util .HashMap ;
44
+ import java .util .HashSet ;
44
45
import java .util .List ;
45
46
import java .util .Map ;
46
47
import java .util .Objects ;
48
+ import java .util .Set ;
49
+ import java .util .stream .Collectors ;
47
50
48
51
import static org .elasticsearch .snapshots .SnapshotInfo .METADATA_FIELD_INTRODUCED ;
49
52
@@ -105,12 +108,25 @@ public Entry(Snapshot snapshot, boolean includeGlobalState, boolean partial, Sta
105
108
} else {
106
109
this .shards = shards ;
107
110
this .waitingIndices = findWaitingIndices (shards );
111
+ assert assertShardsConsistent (state , indices , shards );
108
112
}
109
113
this .repositoryStateId = repositoryStateId ;
110
114
this .failure = failure ;
111
115
this .userMetadata = userMetadata ;
112
116
}
113
117
118
+ private static boolean assertShardsConsistent (State state , List <IndexId > indices ,
119
+ ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards ) {
120
+ if ((state == State .INIT || state == State .ABORTED ) && shards .isEmpty ()) {
121
+ return true ;
122
+ }
123
+ final Set <String > indexNames = indices .stream ().map (IndexId ::getName ).collect (Collectors .toSet ());
124
+ final Set <String > indexNamesInShards = new HashSet <>();
125
+ shards .keysIt ().forEachRemaining (s -> indexNamesInShards .add (s .getIndexName ()));
126
+ assert indexNames .equals (indexNamesInShards )
127
+ : "Indices in shards " + indexNamesInShards + " differ from expected indices " + indexNames + " for state [" + state + "]" ;
128
+ return true ;
129
+ }
114
130
public Entry (Snapshot snapshot , boolean includeGlobalState , boolean partial , State state , List <IndexId > indices ,
115
131
long startTime , long repositoryStateId , ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards ,
116
132
Map <String , Object > userMetadata ) {
@@ -189,7 +205,6 @@ public boolean equals(Object o) {
189
205
if (!shards .equals (entry .shards )) return false ;
190
206
if (!snapshot .equals (entry .snapshot )) return false ;
191
207
if (state != entry .state ) return false ;
192
- if (!waitingIndices .equals (entry .waitingIndices )) return false ;
193
208
if (repositoryStateId != entry .repositoryStateId ) return false ;
194
209
195
210
return true ;
@@ -203,7 +218,6 @@ public int hashCode() {
203
218
result = 31 * result + (partial ? 1 : 0 );
204
219
result = 31 * result + shards .hashCode ();
205
220
result = 31 * result + indices .hashCode ();
206
- result = 31 * result + waitingIndices .hashCode ();
207
221
result = 31 * result + Long .hashCode (startTime );
208
222
result = 31 * result + Long .hashCode (repositoryStateId );
209
223
return result ;
0 commit comments