1919
2020package org .elasticsearch .gateway ;
2121
22- import org .apache .logging .log4j .message .ParameterizedMessage ;
2322import org .elasticsearch .Version ;
2423import org .elasticsearch .cluster .metadata .IndexMetaData ;
2524import org .elasticsearch .cluster .metadata .MetaData ;
@@ -56,7 +55,7 @@ public MetaStateService(Settings settings, NodeEnvironment nodeEnv, NamedXConten
5655 * Loads the full state, which includes both the global state and all the indices meta data. <br>
5756 * When loading, manifest file is consulted (represented by {@link MetaState} class), to load proper generations. <br>
5857 * If there is no manifest file on disk, this method fallbacks to BWC mode, where latest generation of global and indices
59- * metadata is loaded. Please note that currently where is no way to distinguish between manifest file being removed and manifest
58+ * metadata is loaded. Please note that currently there is no way to distinguish between manifest file being removed and manifest
6059 * file was not yet created. It means that this method always fallbacks to BWC mode, if there is no manifest file.
6160 *
6261 * @return tuple of {@link MetaState} and {@link MetaData} with global metadata and indices metadata. If there is no state on disk,
@@ -66,12 +65,6 @@ public MetaStateService(Settings settings, NodeEnvironment nodeEnv, NamedXConten
6665 Tuple <MetaState , MetaData > loadFullState () throws IOException {
6766 final MetaState metaState = loadMetaState ();
6867 if (metaState == null ) {
69- MetaData globalMetaData =
70- MetaData .FORMAT .loadLatestState (logger , namedXContentRegistry , nodeEnv .nodeDataPaths ());
71- boolean isFreshStartup = globalMetaData == null ;
72- if (isFreshStartup == false && Version .CURRENT .major >= 8 ) {
73- throw new IOException ("failed to find manifest file, which is mandatory staring with ElasticSearch version 8.0" );
74- }
7568 return loadFullStateBWC ();
7669 }
7770 final MetaData .Builder metaDataBuilder ;
@@ -107,6 +100,12 @@ private Tuple<MetaState, MetaData> loadFullStateBWC() throws IOException {
107100 MetaData .FORMAT .loadLatestStateWithGeneration (logger , namedXContentRegistry , nodeEnv .nodeDataPaths ());
108101 MetaData globalMetaData = metaDataAndGeneration .v1 ();
109102 long globalStateGeneration = metaDataAndGeneration .v2 ();
103+ boolean isFreshStartup = globalMetaData == null ;
104+
105+ if (isFreshStartup ) {
106+ assert Version .CURRENT .major < 8 : "failed to find manifest file, which is mandatory staring with Elasticsearch version 8.0" ;
107+ }
108+
110109 MetaData .Builder metaDataBuilder ;
111110 if (globalMetaData != null ) {
112111 metaDataBuilder = MetaData .builder (globalMetaData );
@@ -185,8 +184,7 @@ public long writeMetaState(String reason, MetaState metaState) throws WriteState
185184 logger .trace ("[_meta] state written (generation: {})" , generation );
186185 return generation ;
187186 } catch (WriteStateException ex ) {
188- logger .warn ("[_meta]: failed to write meta state" , ex );
189- throw ex ;
187+ throw new WriteStateException (ex .isDirty (), "[_meta]: failed to write meta state" , ex );
190188 }
191189 }
192190
@@ -207,9 +205,7 @@ public long writeIndex(String reason, IndexMetaData indexMetaData) throws WriteS
207205 logger .trace ("[{}] state written" , index );
208206 return generation ;
209207 } catch (WriteStateException ex ) {
210- logger .warn (() -> new ParameterizedMessage ("[{}]: failed to write index state" , index ), ex );
211- ex .resetDirty ();
212- throw ex ;
208+ throw new WriteStateException (false , "[" + index + "]: failed to write index state" , ex );
213209 }
214210 }
215211
@@ -226,9 +222,7 @@ long writeGlobalState(String reason, MetaData metaData) throws WriteStateExcepti
226222 logger .trace ("[_global] state written" );
227223 return generation ;
228224 } catch (WriteStateException ex ) {
229- logger .warn ("[_global]: failed to write global state" , ex );
230- ex .resetDirty ();
231- throw ex ;
225+ throw new WriteStateException (false , "[_global]: failed to write global state" , ex );
232226 }
233227 }
234228
0 commit comments