Fix Broken ExistingStoreRecoverySource Deserialization (#55657) (#55665)

We are using `FORCE_STALE_PRIMARY_INSTANCE` in instance equality checks `==`
but were creating new instances of `ExistingStoreRecoverySource` when reading
from the wire. This could break these checks in corner cases, causing
`org.elasticsearch.cluster.routing.allocation.IndexMetadataUpdater#shardStarted`
to not remove the force allocation fake id when starting a shard.

Closes #55513
This commit is contained in:
Armin Braun 2020-04-23 15:56:48 +02:00 committed by GitHub
parent 4b11adf074
commit dc899781f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 10 deletions

View File

@ -64,7 +64,7 @@ public abstract class RecoverySource implements Writeable, ToXContentObject {
Type type = Type.values()[in.readByte()];
switch (type) {
case EMPTY_STORE: return EmptyStoreRecoverySource.INSTANCE;
case EXISTING_STORE: return new ExistingStoreRecoverySource(in);
case EXISTING_STORE: return ExistingStoreRecoverySource.read(in);
case PEER: return PeerRecoverySource.INSTANCE;
case SNAPSHOT: return new SnapshotRecoverySource(in);
case LOCAL_SHARDS: return LocalShardsRecoverySource.INSTANCE;
@ -153,12 +153,8 @@ public abstract class RecoverySource implements Writeable, ToXContentObject {
this.bootstrapNewHistoryUUID = bootstrapNewHistoryUUID;
}
private ExistingStoreRecoverySource(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_6_5_0)) {
bootstrapNewHistoryUUID = in.readBoolean();
} else {
bootstrapNewHistoryUUID = false;
}
private static ExistingStoreRecoverySource read(StreamInput in) throws IOException {
return in.readBoolean() ? FORCE_STALE_PRIMARY_INSTANCE : INSTANCE;
}
@Override
@ -168,9 +164,7 @@ public abstract class RecoverySource implements Writeable, ToXContentObject {
@Override
protected void writeAdditionalFields(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_6_5_0)) {
out.writeBoolean(bootstrapNewHistoryUUID);
}
out.writeBoolean(bootstrapNewHistoryUUID);
}
@Override