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