1818import org .elasticsearch .action .support .single .shard .TransportSingleShardAction ;
1919import org .elasticsearch .client .ElasticsearchClient ;
2020import org .elasticsearch .cluster .ClusterState ;
21+ import org .elasticsearch .cluster .metadata .IndexMetaData ;
2122import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
2223import org .elasticsearch .cluster .routing .ShardsIterator ;
2324import org .elasticsearch .cluster .service .ClusterService ;
@@ -213,6 +214,12 @@ public long getMappingVersion() {
213214 return mappingVersion ;
214215 }
215216
217+ private long settingsVersion ;
218+
219+ public long getSettingsVersion () {
220+ return settingsVersion ;
221+ }
222+
216223 private long globalCheckpoint ;
217224
218225 public long getGlobalCheckpoint () {
@@ -248,13 +255,15 @@ public long getTookInMillis() {
248255
249256 Response (
250257 final long mappingVersion ,
258+ final long settingsVersion ,
251259 final long globalCheckpoint ,
252260 final long maxSeqNo ,
253261 final long maxSeqNoOfUpdatesOrDeletes ,
254262 final Translog .Operation [] operations ,
255263 final long tookInMillis ) {
256264
257265 this .mappingVersion = mappingVersion ;
266+ this .settingsVersion = settingsVersion ;
258267 this .globalCheckpoint = globalCheckpoint ;
259268 this .maxSeqNo = maxSeqNo ;
260269 this .maxSeqNoOfUpdatesOrDeletes = maxSeqNoOfUpdatesOrDeletes ;
@@ -266,6 +275,7 @@ public long getTookInMillis() {
266275 public void readFrom (final StreamInput in ) throws IOException {
267276 super .readFrom (in );
268277 mappingVersion = in .readVLong ();
278+ settingsVersion = in .readVLong ();
269279 globalCheckpoint = in .readZLong ();
270280 maxSeqNo = in .readZLong ();
271281 maxSeqNoOfUpdatesOrDeletes = in .readZLong ();
@@ -277,6 +287,7 @@ public void readFrom(final StreamInput in) throws IOException {
277287 public void writeTo (final StreamOutput out ) throws IOException {
278288 super .writeTo (out );
279289 out .writeVLong (mappingVersion );
290+ out .writeVLong (settingsVersion );
280291 out .writeZLong (globalCheckpoint );
281292 out .writeZLong (maxSeqNo );
282293 out .writeZLong (maxSeqNoOfUpdatesOrDeletes );
@@ -290,6 +301,7 @@ public boolean equals(final Object o) {
290301 if (o == null || getClass () != o .getClass ()) return false ;
291302 final Response that = (Response ) o ;
292303 return mappingVersion == that .mappingVersion &&
304+ settingsVersion == that .settingsVersion &&
293305 globalCheckpoint == that .globalCheckpoint &&
294306 maxSeqNo == that .maxSeqNo &&
295307 maxSeqNoOfUpdatesOrDeletes == that .maxSeqNoOfUpdatesOrDeletes &&
@@ -299,8 +311,14 @@ public boolean equals(final Object o) {
299311
300312 @ Override
301313 public int hashCode () {
302- return Objects .hash (mappingVersion , globalCheckpoint , maxSeqNo , maxSeqNoOfUpdatesOrDeletes ,
303- Arrays .hashCode (operations ), tookInMillis );
314+ return Objects .hash (
315+ mappingVersion ,
316+ settingsVersion ,
317+ globalCheckpoint ,
318+ maxSeqNo ,
319+ maxSeqNoOfUpdatesOrDeletes ,
320+ Arrays .hashCode (operations ),
321+ tookInMillis );
304322 }
305323 }
306324
@@ -333,7 +351,9 @@ protected Response shardOperation(Request request, ShardId shardId) throws IOExc
333351 final IndexService indexService = indicesService .indexServiceSafe (request .getShard ().getIndex ());
334352 final IndexShard indexShard = indexService .getShard (request .getShard ().id ());
335353 final SeqNoStats seqNoStats = indexShard .seqNoStats ();
336- final long mappingVersion = clusterService .state ().metaData ().index (shardId .getIndex ()).getMappingVersion ();
354+ final IndexMetaData indexMetaData = clusterService .state ().metaData ().index (shardId .getIndex ());
355+ final long mappingVersion = indexMetaData .getMappingVersion ();
356+ final long settingsVersion = indexMetaData .getSettingsVersion ();
337357
338358 final Translog .Operation [] operations = getOperations (
339359 indexShard ,
@@ -344,7 +364,13 @@ protected Response shardOperation(Request request, ShardId shardId) throws IOExc
344364 request .getMaxBatchSize ());
345365 // must capture after after snapshotting operations to ensure this MUS is at least the highest MUS of any of these operations.
346366 final long maxSeqNoOfUpdatesOrDeletes = indexShard .getMaxSeqNoOfUpdatesOrDeletes ();
347- return getResponse (mappingVersion , seqNoStats , maxSeqNoOfUpdatesOrDeletes , operations , request .relativeStartNanos );
367+ return getResponse (
368+ mappingVersion ,
369+ settingsVersion ,
370+ seqNoStats ,
371+ maxSeqNoOfUpdatesOrDeletes ,
372+ operations ,
373+ request .relativeStartNanos );
348374 }
349375
350376 @ Override
@@ -420,12 +446,19 @@ private void globalCheckpointAdvancementFailure(
420446 e );
421447 if (e instanceof TimeoutException ) {
422448 try {
423- final long mappingVersion =
424- clusterService .state ().metaData ().index (shardId .getIndex ()).getMappingVersion ();
449+ final IndexMetaData indexMetaData = clusterService .state ().metaData ().index (shardId .getIndex ());
450+ final long mappingVersion = indexMetaData .getMappingVersion ();
451+ final long settingsVersion = indexMetaData .getSettingsVersion ();
425452 final SeqNoStats latestSeqNoStats = indexShard .seqNoStats ();
426453 final long maxSeqNoOfUpdatesOrDeletes = indexShard .getMaxSeqNoOfUpdatesOrDeletes ();
427- listener .onResponse (getResponse (mappingVersion , latestSeqNoStats , maxSeqNoOfUpdatesOrDeletes , EMPTY_OPERATIONS_ARRAY ,
428- request .relativeStartNanos ));
454+ listener .onResponse (
455+ getResponse (
456+ mappingVersion ,
457+ settingsVersion ,
458+ latestSeqNoStats ,
459+ maxSeqNoOfUpdatesOrDeletes ,
460+ EMPTY_OPERATIONS_ARRAY ,
461+ request .relativeStartNanos ));
429462 } catch (final Exception caught ) {
430463 caught .addSuppressed (e );
431464 listener .onFailure (caught );
@@ -510,12 +543,23 @@ static Translog.Operation[] getOperations(
510543 return operations .toArray (EMPTY_OPERATIONS_ARRAY );
511544 }
512545
513- static Response getResponse (final long mappingVersion , final SeqNoStats seqNoStats ,
514- final long maxSeqNoOfUpdates , final Translog .Operation [] operations , long relativeStartNanos ) {
546+ static Response getResponse (
547+ final long mappingVersion ,
548+ final long settingsVersion ,
549+ final SeqNoStats seqNoStats ,
550+ final long maxSeqNoOfUpdates ,
551+ final Translog .Operation [] operations ,
552+ long relativeStartNanos ) {
515553 long tookInNanos = System .nanoTime () - relativeStartNanos ;
516554 long tookInMillis = TimeUnit .NANOSECONDS .toMillis (tookInNanos );
517- return new Response (mappingVersion , seqNoStats .getGlobalCheckpoint (), seqNoStats .getMaxSeqNo (), maxSeqNoOfUpdates ,
518- operations , tookInMillis );
555+ return new Response (
556+ mappingVersion ,
557+ settingsVersion ,
558+ seqNoStats .getGlobalCheckpoint (),
559+ seqNoStats .getMaxSeqNo (),
560+ maxSeqNoOfUpdates ,
561+ operations ,
562+ tookInMillis );
519563 }
520564
521565}
0 commit comments