mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-25 22:36:20 +00:00
Fix NPE when initializing replica shard has no unassignedInfo (#19491)
An initializing replica shard might not have an UnassignedInfo object, for example when it is a relocation target. The method allocatedPostIndexCreate does not account for this situation.
This commit is contained in:
parent
37d5bcb264
commit
79ab6d19af
@ -237,10 +237,9 @@ public final class ShardRouting implements Writeable, ToXContent {
|
||||
return true;
|
||||
}
|
||||
|
||||
// unassigned info is only cleared when a shard moves to started, so
|
||||
// for unassigned and initializing (we checked for active() before),
|
||||
// we can safely assume it is there
|
||||
if (unassignedInfo.getReason() == UnassignedInfo.Reason.INDEX_CREATED) {
|
||||
// initializing replica might not have unassignedInfo
|
||||
assert unassignedInfo != null || (primary == false && state == ShardRoutingState.INITIALIZING);
|
||||
if (unassignedInfo != null && unassignedInfo.getReason() == UnassignedInfo.Reason.INDEX_CREATED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing.allocation.decider;
|
||||
|
||||
import org.elasticsearch.cluster.routing.RoutingNode;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.ClusterSettings;
|
||||
@ -177,7 +178,12 @@ public class ThrottlingAllocationDecider extends AllocationDecider {
|
||||
if (shardRouting.unassigned()) {
|
||||
initializingShard = shardRouting.initialize(currentNodeId, null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
||||
} else if (shardRouting.initializing()) {
|
||||
initializingShard = shardRouting.moveToUnassigned(shardRouting.unassignedInfo())
|
||||
UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
|
||||
if (unassignedInfo == null) {
|
||||
// unassigned shards must have unassignedInfo (initializing shards might not)
|
||||
unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.ALLOCATION_FAILED, "fake");
|
||||
}
|
||||
initializingShard = shardRouting.moveToUnassigned(unassignedInfo)
|
||||
.initialize(currentNodeId, null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
||||
} else if (shardRouting.relocating()) {
|
||||
initializingShard = shardRouting.cancelRelocation()
|
||||
|
Loading…
x
Reference in New Issue
Block a user