Skip to content

Commit 79cfcec

Browse files
authored
Clarify the null check for retention leases (#114979)
`MetadataStateFormat.FORMAT.loadLatestState` can actually return null when the state directory hasn't been initialized yet, so we have to keep the null check when loading retention leases during the initialization of the engine. See #39359
1 parent ad9c5a0 commit 79cfcec

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

server/src/main/java/org/elasticsearch/gateway/MetadataStateFormat.java

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
2525
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
2626
import org.elasticsearch.core.IOUtils;
27+
import org.elasticsearch.core.Nullable;
2728
import org.elasticsearch.core.Tuple;
2829
import org.elasticsearch.transport.Transports;
2930
import org.elasticsearch.xcontent.NamedXContentRegistry;
@@ -485,6 +486,7 @@ public Tuple<T, Long> loadLatestStateWithGeneration(Logger logger, NamedXContent
485486
* @param dataLocations the data-locations to try.
486487
* @return the latest state or <code>null</code> if no state was found.
487488
*/
489+
@Nullable
488490
public T loadLatestState(Logger logger, NamedXContentRegistry namedXContentRegistry, Path... dataLocations) throws IOException {
489491
return loadLatestStateWithGeneration(logger, namedXContentRegistry, dataLocations).v1();
490492
}

server/src/main/java/org/elasticsearch/index/seqno/ReplicationTracker.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.common.io.stream.Writeable;
2323
import org.elasticsearch.common.util.Maps;
2424
import org.elasticsearch.core.SuppressForbidden;
25-
import org.elasticsearch.core.UpdateForV9;
2625
import org.elasticsearch.gateway.WriteStateException;
2726
import org.elasticsearch.index.IndexSettings;
2827
import org.elasticsearch.index.IndexVersions;
@@ -471,9 +470,9 @@ public RetentionLeases loadRetentionLeases(final Path path) throws IOException {
471470
return emptyIfNull(retentionLeases);
472471
}
473472

474-
@UpdateForV9(owner = UpdateForV9.Owner.DISTRIBUTED_INDEXING)
475473
private static RetentionLeases emptyIfNull(RetentionLeases retentionLeases) {
476-
// we expect never to see a null in 8.x, so adjust this to throw an exception from v9 onwards.
474+
// `MetadataStateFormat.FORMAT.loadLatestState` can actually return null when the state directory
475+
// on a node hasn't been initialized yet
477476
return retentionLeases == null ? RetentionLeases.EMPTY : retentionLeases;
478477
}
479478

0 commit comments

Comments
 (0)