@@ -93,11 +93,12 @@ public static class Entry {
93
93
private final ImmutableOpenMap <String , List <ShardId >> waitingIndices ;
94
94
private final long startTime ;
95
95
private final long repositoryStateId ;
96
+ private final boolean useShardGenerations ;
96
97
@ Nullable private final String failure ;
97
98
98
99
public Entry (Snapshot snapshot , boolean includeGlobalState , boolean partial , State state , List <IndexId > indices ,
99
100
long startTime , long repositoryStateId , ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards ,
100
- String failure ) {
101
+ String failure , boolean useShardGenerations ) {
101
102
this .state = state ;
102
103
this .snapshot = snapshot ;
103
104
this .includeGlobalState = includeGlobalState ;
@@ -114,21 +115,22 @@ public Entry(Snapshot snapshot, boolean includeGlobalState, boolean partial, Sta
114
115
}
115
116
this .repositoryStateId = repositoryStateId ;
116
117
this .failure = failure ;
118
+ this .useShardGenerations = useShardGenerations ;
117
119
}
118
120
119
121
public Entry (Snapshot snapshot , boolean includeGlobalState , boolean partial , State state , List <IndexId > indices ,
120
- long startTime , long repositoryStateId , ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards ) {
121
- this (snapshot , includeGlobalState , partial , state , indices , startTime , repositoryStateId , shards , null );
122
+ long startTime , long repositoryStateId , ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards , boolean useShardGenerations ) {
123
+ this (snapshot , includeGlobalState , partial , state , indices , startTime , repositoryStateId , shards , null , useShardGenerations );
122
124
}
123
125
124
126
public Entry (Entry entry , State state , ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards ) {
125
127
this (entry .snapshot , entry .includeGlobalState , entry .partial , state , entry .indices , entry .startTime ,
126
- entry .repositoryStateId , shards , entry .failure );
128
+ entry .repositoryStateId , shards , entry .failure , entry . useShardGenerations );
127
129
}
128
130
129
131
public Entry (Entry entry , State state , ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards , String failure ) {
130
132
this (entry .snapshot , entry .includeGlobalState , entry .partial , state , entry .indices , entry .startTime ,
131
- entry .repositoryStateId , shards , failure );
133
+ entry .repositoryStateId , shards , failure , entry . useShardGenerations );
132
134
}
133
135
134
136
public Entry (Entry entry , ImmutableOpenMap <ShardId , ShardSnapshotStatus > shards ) {
@@ -188,6 +190,16 @@ public String failure() {
188
190
return failure ;
189
191
}
190
192
193
+ /**
194
+ * Whether to write to the repository in a format only understood by versions newer than
195
+ * {@link SnapshotsService#SHARD_GEN_IN_REPO_DATA_VERSION}.
196
+ *
197
+ * @return true if writing to repository in new format
198
+ */
199
+ public boolean useShardGenerations () {
200
+ return useShardGenerations ;
201
+ }
202
+
191
203
@ Override
192
204
public boolean equals (Object o ) {
193
205
if (this == o ) return true ;
@@ -203,6 +215,7 @@ public boolean equals(Object o) {
203
215
if (!snapshot .equals (entry .snapshot )) return false ;
204
216
if (state != entry .state ) return false ;
205
217
if (repositoryStateId != entry .repositoryStateId ) return false ;
218
+ if (useShardGenerations != entry .useShardGenerations ) return false ;
206
219
207
220
return true ;
208
221
}
@@ -217,6 +230,8 @@ public int hashCode() {
217
230
result = 31 * result + indices .hashCode ();
218
231
result = 31 * result + Long .hashCode (startTime );
219
232
result = 31 * result + Long .hashCode (repositoryStateId );
233
+ result = 31 * result + (useShardGenerations ? 1 : 0 );
234
+
220
235
return result ;
221
236
}
222
237
@@ -445,24 +460,30 @@ public static NamedDiff<Custom> readDiffFrom(StreamInput in) throws IOException
445
460
public SnapshotsInProgress (StreamInput in ) throws IOException {
446
461
Entry [] entries = new Entry [in .readVInt ()];
447
462
for (int i = 0 ; i < entries .length ; i ++) {
448
- Snapshot snapshot = new Snapshot (in );
449
- boolean includeGlobalState = in .readBoolean ();
450
- boolean partial = in .readBoolean ();
451
- State state = State .fromValue (in .readByte ());
463
+ final Snapshot snapshot = new Snapshot (in );
464
+ final boolean includeGlobalState = in .readBoolean ();
465
+ final boolean partial = in .readBoolean ();
466
+ final State state = State .fromValue (in .readByte ());
452
467
int indices = in .readVInt ();
453
468
List <IndexId > indexBuilder = new ArrayList <>();
454
469
for (int j = 0 ; j < indices ; j ++) {
455
470
indexBuilder .add (new IndexId (in .readString (), in .readString ()));
456
471
}
457
- long startTime = in .readLong ();
472
+ final long startTime = in .readLong ();
458
473
ImmutableOpenMap .Builder <ShardId , ShardSnapshotStatus > builder = ImmutableOpenMap .builder ();
459
- int shards = in .readVInt ();
474
+ final int shards = in .readVInt ();
460
475
for (int j = 0 ; j < shards ; j ++) {
461
476
ShardId shardId = new ShardId (in );
462
477
builder .put (shardId , new ShardSnapshotStatus (in ));
463
478
}
464
- long repositoryStateId = in .readLong ();
479
+ final long repositoryStateId = in .readLong ();
465
480
final String failure = in .readOptionalString ();
481
+ final boolean useShardGenerations ;
482
+ if (in .getVersion ().onOrAfter (SnapshotsService .SHARD_GEN_IN_REPO_DATA_VERSION )) {
483
+ useShardGenerations = in .readBoolean ();
484
+ } else {
485
+ useShardGenerations = false ;
486
+ }
466
487
entries [i ] = new Entry (snapshot ,
467
488
includeGlobalState ,
468
489
partial ,
@@ -471,7 +492,8 @@ public SnapshotsInProgress(StreamInput in) throws IOException {
471
492
startTime ,
472
493
repositoryStateId ,
473
494
builder .build (),
474
- failure );
495
+ failure ,
496
+ useShardGenerations );
475
497
}
476
498
this .entries = Arrays .asList (entries );
477
499
}
@@ -496,6 +518,9 @@ public void writeTo(StreamOutput out) throws IOException {
496
518
}
497
519
out .writeLong (entry .repositoryStateId );
498
520
out .writeOptionalString (entry .failure );
521
+ if (out .getVersion ().onOrAfter (SnapshotsService .SHARD_GEN_IN_REPO_DATA_VERSION )) {
522
+ out .writeBoolean (entry .useShardGenerations );
523
+ }
499
524
}
500
525
}
501
526
0 commit comments