88import org .apache .logging .log4j .message .ParameterizedMessage ;
99import org .elasticsearch .ElasticsearchException ;
1010import org .elasticsearch .ExceptionsHelper ;
11+ import org .elasticsearch .Version ;
1112import org .elasticsearch .action .Action ;
1213import org .elasticsearch .action .ActionListener ;
1314import org .elasticsearch .action .ActionRequestValidationException ;
1819import org .elasticsearch .cluster .ClusterState ;
1920import org .elasticsearch .cluster .metadata .IndexMetaData ;
2021import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
22+ import org .elasticsearch .cluster .metadata .MetaData ;
2123import org .elasticsearch .cluster .routing .ShardsIterator ;
2224import org .elasticsearch .cluster .service .ClusterService ;
2325import org .elasticsearch .common .inject .Inject ;
3436import org .elasticsearch .index .shard .ShardId ;
3537import org .elasticsearch .index .translog .Translog ;
3638import org .elasticsearch .indices .IndicesService ;
39+ import org .elasticsearch .indices .cluster .IndicesClusterStateService ;
3740import org .elasticsearch .tasks .Task ;
3841import org .elasticsearch .threadpool .ThreadPool ;
3942import org .elasticsearch .transport .TransportService ;
@@ -212,6 +215,12 @@ public long getSettingsVersion() {
212215 return settingsVersion ;
213216 }
214217
218+ private long metadataVersion ;
219+
220+ public long getMetadataVersion () {
221+ return metadataVersion ;
222+ }
223+
215224 private long globalCheckpoint ;
216225
217226 public long getGlobalCheckpoint () {
@@ -248,6 +257,7 @@ public long getTookInMillis() {
248257 Response (
249258 final long mappingVersion ,
250259 final long settingsVersion ,
260+ final long metadataVersion ,
251261 final long globalCheckpoint ,
252262 final long maxSeqNo ,
253263 final long maxSeqNoOfUpdatesOrDeletes ,
@@ -256,6 +266,7 @@ public long getTookInMillis() {
256266
257267 this .mappingVersion = mappingVersion ;
258268 this .settingsVersion = settingsVersion ;
269+ this .metadataVersion = metadataVersion ;
259270 this .globalCheckpoint = globalCheckpoint ;
260271 this .maxSeqNo = maxSeqNo ;
261272 this .maxSeqNoOfUpdatesOrDeletes = maxSeqNoOfUpdatesOrDeletes ;
@@ -268,6 +279,11 @@ public void readFrom(final StreamInput in) throws IOException {
268279 super .readFrom (in );
269280 mappingVersion = in .readVLong ();
270281 settingsVersion = in .readVLong ();
282+ if (in .getVersion ().onOrAfter (Version .V_7_0_0 )) {
283+ metadataVersion = in .readVLong ();
284+ } else {
285+ metadataVersion = 0L ;
286+ }
271287 globalCheckpoint = in .readZLong ();
272288 maxSeqNo = in .readZLong ();
273289 maxSeqNoOfUpdatesOrDeletes = in .readZLong ();
@@ -280,6 +296,9 @@ public void writeTo(final StreamOutput out) throws IOException {
280296 super .writeTo (out );
281297 out .writeVLong (mappingVersion );
282298 out .writeVLong (settingsVersion );
299+ if (out .getVersion ().onOrAfter (Version .V_7_0_0 )) {
300+ out .writeVLong (metadataVersion );
301+ }
283302 out .writeZLong (globalCheckpoint );
284303 out .writeZLong (maxSeqNo );
285304 out .writeZLong (maxSeqNoOfUpdatesOrDeletes );
@@ -294,6 +313,7 @@ public boolean equals(final Object o) {
294313 final Response that = (Response ) o ;
295314 return mappingVersion == that .mappingVersion &&
296315 settingsVersion == that .settingsVersion &&
316+ metadataVersion == that .metadataVersion &&
297317 globalCheckpoint == that .globalCheckpoint &&
298318 maxSeqNo == that .maxSeqNo &&
299319 maxSeqNoOfUpdatesOrDeletes == that .maxSeqNoOfUpdatesOrDeletes &&
@@ -306,6 +326,7 @@ public int hashCode() {
306326 return Objects .hash (
307327 mappingVersion ,
308328 settingsVersion ,
329+ metadataVersion ,
309330 globalCheckpoint ,
310331 maxSeqNo ,
311332 maxSeqNoOfUpdatesOrDeletes ,
@@ -317,17 +338,20 @@ public int hashCode() {
317338 public static class TransportAction extends TransportSingleShardAction <Request , Response > {
318339
319340 private final IndicesService indicesService ;
341+ private final IndicesClusterStateService indicesClusterStateService ;
320342
321343 @ Inject
322344 public TransportAction (ThreadPool threadPool ,
323345 ClusterService clusterService ,
324346 TransportService transportService ,
325347 ActionFilters actionFilters ,
326348 IndexNameExpressionResolver indexNameExpressionResolver ,
327- IndicesService indicesService ) {
349+ IndicesService indicesService ,
350+ IndicesClusterStateService indicesClusterStateService ) {
328351 super (NAME , threadPool , clusterService , transportService , actionFilters ,
329352 indexNameExpressionResolver , Request ::new , ThreadPool .Names .SEARCH );
330353 this .indicesService = indicesService ;
354+ this .indicesClusterStateService = indicesClusterStateService ;
331355 }
332356
333357 @ Override
@@ -347,12 +371,14 @@ protected Response shardOperation(Request request, ShardId shardId) throws IOExc
347371 // must capture IndexMetaData after snapshotting operations to ensure the returned mapping version is at least as up-to-date
348372 // as the mapping version that these operations used. Here we must not use IndexMetaData from ClusterService for we expose
349373 // a new cluster state to ClusterApplier(s) before exposing it in the ClusterService.
350- final IndexMetaData indexMetaData = indexService .getMetaData ();
374+ final MetaData metaData = indicesClusterStateService .getClusterState ().metaData ();
375+ final IndexMetaData indexMetaData = metaData .getIndexSafe (shardId .getIndex ());
351376 final long mappingVersion = indexMetaData .getMappingVersion ();
352377 final long settingsVersion = indexMetaData .getSettingsVersion ();
353378 return getResponse (
354379 mappingVersion ,
355380 settingsVersion ,
381+ metaData .version (),
356382 seqNoStats ,
357383 maxSeqNoOfUpdatesOrDeletes ,
358384 operations ,
@@ -432,7 +458,8 @@ private void globalCheckpointAdvancementFailure(
432458 e );
433459 if (e instanceof TimeoutException ) {
434460 try {
435- final IndexMetaData indexMetaData = clusterService .state ().metaData ().index (shardId .getIndex ());
461+ final MetaData metaData = indicesClusterStateService .getClusterState ().metaData ();
462+ final IndexMetaData indexMetaData = metaData .getIndexSafe (shardId .getIndex ());
436463 final long mappingVersion = indexMetaData .getMappingVersion ();
437464 final long settingsVersion = indexMetaData .getSettingsVersion ();
438465 final SeqNoStats latestSeqNoStats = indexShard .seqNoStats ();
@@ -441,6 +468,7 @@ private void globalCheckpointAdvancementFailure(
441468 getResponse (
442469 mappingVersion ,
443470 settingsVersion ,
471+ metaData .version (),
444472 latestSeqNoStats ,
445473 maxSeqNoOfUpdatesOrDeletes ,
446474 EMPTY_OPERATIONS_ARRAY ,
@@ -532,6 +560,7 @@ static Translog.Operation[] getOperations(
532560 static Response getResponse (
533561 final long mappingVersion ,
534562 final long settingsVersion ,
563+ final long metadataVersion ,
535564 final SeqNoStats seqNoStats ,
536565 final long maxSeqNoOfUpdates ,
537566 final Translog .Operation [] operations ,
@@ -541,6 +570,7 @@ static Response getResponse(
541570 return new Response (
542571 mappingVersion ,
543572 settingsVersion ,
573+ metadataVersion ,
544574 seqNoStats .getGlobalCheckpoint (),
545575 seqNoStats .getMaxSeqNo (),
546576 maxSeqNoOfUpdates ,
0 commit comments