21
21
22
22
import org .elasticsearch .Version ;
23
23
import org .elasticsearch .cluster .RestoreInProgress ;
24
+ import org .elasticsearch .cluster .metadata .IndexMetaData ;
24
25
import org .elasticsearch .common .io .stream .StreamInput ;
25
26
import org .elasticsearch .common .io .stream .StreamOutput ;
26
27
import org .elasticsearch .common .io .stream .Writeable ;
27
28
import org .elasticsearch .common .xcontent .ToXContent ;
28
29
import org .elasticsearch .common .xcontent .ToXContentObject ;
29
30
import org .elasticsearch .common .xcontent .XContentBuilder ;
31
+ import org .elasticsearch .repositories .IndexId ;
30
32
import org .elasticsearch .snapshots .Snapshot ;
31
33
32
34
import java .io .IOException ;
@@ -220,14 +222,14 @@ public String toString() {
220
222
public static class SnapshotRecoverySource extends RecoverySource {
221
223
private final String restoreUUID ;
222
224
private final Snapshot snapshot ;
223
- private final String index ;
225
+ private final IndexId index ;
224
226
private final Version version ;
225
227
226
- public SnapshotRecoverySource (String restoreUUID , Snapshot snapshot , Version version , String index ) {
228
+ public SnapshotRecoverySource (String restoreUUID , Snapshot snapshot , Version version , IndexId indexId ) {
227
229
this .restoreUUID = restoreUUID ;
228
230
this .snapshot = Objects .requireNonNull (snapshot );
229
231
this .version = Objects .requireNonNull (version );
230
- this .index = Objects .requireNonNull (index );
232
+ this .index = Objects .requireNonNull (indexId );
231
233
}
232
234
233
235
SnapshotRecoverySource (StreamInput in ) throws IOException {
@@ -238,7 +240,11 @@ public SnapshotRecoverySource(String restoreUUID, Snapshot snapshot, Version ver
238
240
}
239
241
snapshot = new Snapshot (in );
240
242
version = Version .readVersion (in );
241
- index = in .readString ();
243
+ if (in .getVersion ().onOrAfter (Version .V_7_7_0 )) {
244
+ index = new IndexId (in );
245
+ } else {
246
+ index = new IndexId (in .readString (), IndexMetaData .INDEX_UUID_NA_VALUE );
247
+ }
242
248
}
243
249
244
250
public String restoreUUID () {
@@ -249,7 +255,13 @@ public Snapshot snapshot() {
249
255
return snapshot ;
250
256
}
251
257
252
- public String index () {
258
+ /**
259
+ * Gets the {@link IndexId} of the recovery source. May contain {@link IndexMetaData#INDEX_UUID_NA_VALUE} as the index uuid if it
260
+ * was created by an older version master in a mixed version cluster.
261
+ *
262
+ * @return IndexId
263
+ */
264
+ public IndexId index () {
253
265
return index ;
254
266
}
255
267
@@ -264,7 +276,11 @@ protected void writeAdditionalFields(StreamOutput out) throws IOException {
264
276
}
265
277
snapshot .writeTo (out );
266
278
Version .writeVersion (version , out );
267
- out .writeString (index );
279
+ if (out .getVersion ().onOrAfter (Version .V_7_7_0 )) {
280
+ index .writeTo (out );
281
+ } else {
282
+ out .writeString (index .getName ());
283
+ }
268
284
}
269
285
270
286
@ Override
@@ -277,7 +293,7 @@ public void addAdditionalFields(XContentBuilder builder, ToXContent.Params param
277
293
builder .field ("repository" , snapshot .getRepository ())
278
294
.field ("snapshot" , snapshot .getSnapshotId ().getName ())
279
295
.field ("version" , version .toString ())
280
- .field ("index" , index )
296
+ .field ("index" , index . getName () )
281
297
.field ("restoreUUID" , restoreUUID );
282
298
}
283
299
0 commit comments