public static Iterable<GatewayMetaState.IndexMetaWriteInfo> resolveStatesToBeWritten(ImmutableSet<String> previouslyWrittenIndices,Set<String> potentiallyUnwrittenIndices,MetaData previousMetaData,MetaData newMetaData){
  List<GatewayMetaState.IndexMetaWriteInfo> indicesToWrite=new ArrayList<>();
  for (  String index : potentiallyUnwrittenIndices) {
    IndexMetaData newIndexMetaData=newMetaData.index(index);
    IndexMetaData previousIndexMetaData=previousMetaData == null ? null : previousMetaData.index(index);
    String writeReason=null;
    if (previouslyWrittenIndices.contains(index) == false || previousIndexMetaData == null) {
      writeReason="freshly created";
    }
 else     if (previousIndexMetaData.getVersion() != newIndexMetaData.getVersion()) {
      writeReason="version changed from [" + previousIndexMetaData.getVersion() + "] to ["+ newIndexMetaData.getVersion()+ "]";
    }
    if (writeReason != null) {
      indicesToWrite.add(new GatewayMetaState.IndexMetaWriteInfo(newIndexMetaData,previousIndexMetaData,writeReason));
    }
  }
  return indicesToWrite;
}

public static Iterable < GatewayMetaState . IndexMetaWriteInfo > resolveStatesToBeWritten ( ImmutableSet < String > previouslyWrittenIndices , Set < String > potentiallyUnwrittenIndices , MetaData previousMetaData , MetaData newMetaData ) { List < GatewayMetaState . IndexMetaWriteInfo > indicesToWrite = new ArrayList < > ( ) ; for ( String index : potentiallyUnwrittenIndices ) { IndexMetaData newIndexMetaData = newMetaData . index ( index ) ; IndexMetaData previousIndexMetaData = previousMetaData == null ? null : previousMetaData . index ( index ) ; String writeReason = null ; if ( previouslyWrittenIndices . contains ( index ) == false || previousIndexMetaData == null ) { writeReason = "freshly created" ; } else if ( previousIndexMetaData . getVersion ( ) != newIndexMetaData . getVersion ( ) ) { writeReason = "version changed from [" + previousIndexMetaData . getVersion ( ) + "] to [" + newIndexMetaData . getVersion ( ) + "]" ; } if ( writeReason != null ) { indicesToWrite . add ( new GatewayMetaState . IndexMetaWriteInfo ( newIndexMetaData , previousIndexMetaData , writeReason ) ) ; } } return indicesToWrite ; }
loads the current meta state for each index in the new cluster state and checks if it has to be persisted . each index state that should be written to disk will be returned . this is only run for data only nodes . it will return only the states for indices that actually have a shard allocated on the current node .
