Skip to content

Commit

Permalink
Clarify the null check for retention leases (elastic#114979)
Browse files Browse the repository at this point in the history
`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 elastic#39359
  • Loading branch information
arteam authored and georgewallace committed Oct 25, 2024
1 parent ed53e82 commit 477bcb6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.transport.Transports;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -485,6 +486,7 @@ public Tuple<T, Long> loadLatestStateWithGeneration(Logger logger, NamedXContent
* @param dataLocations the data-locations to try.
* @return the latest state or <code>null</code> if no state was found.
*/
@Nullable
public T loadLatestState(Logger logger, NamedXContentRegistry namedXContentRegistry, Path... dataLocations) throws IOException {
return loadLatestStateWithGeneration(logger, namedXContentRegistry, dataLocations).v1();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.gateway.WriteStateException;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersions;
Expand Down Expand Up @@ -471,9 +470,9 @@ public RetentionLeases loadRetentionLeases(final Path path) throws IOException {
return emptyIfNull(retentionLeases);
}

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

Expand Down

0 comments on commit 477bcb6

Please sign in to comment.