Bootstrap a new history_uuid when force allocating a stale primary (#33432)
This commit ensures that we bootstrap a new history_uuid when force allocating a stale primary. A stale primary should never be the source of an operation-based recovery to another shard which exists before the forced-allocation. Closes #26712
This commit is contained in:
parent
f27c3dcf88
commit
94e4cb64c2
|
@ -27,10 +27,11 @@ import org.elasticsearch.cluster.AbstractDiffable;
|
||||||
import org.elasticsearch.cluster.Diff;
|
import org.elasticsearch.cluster.Diff;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource.EmptyStoreRecoverySource;
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource.ExistingStoreRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.LocalShardsRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.LocalShardsRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource;
|
|
||||||
import org.elasticsearch.common.Randomness;
|
import org.elasticsearch.common.Randomness;
|
||||||
import org.elasticsearch.common.collect.ImmutableOpenIntMap;
|
import org.elasticsearch.common.collect.ImmutableOpenIntMap;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -386,7 +387,7 @@ public class IndexRoutingTable extends AbstractDiffable<IndexRoutingTable> imple
|
||||||
if (asNew && ignoreShards.contains(shardNumber)) {
|
if (asNew && ignoreShards.contains(shardNumber)) {
|
||||||
// This shards wasn't completely snapshotted - restore it as new shard
|
// This shards wasn't completely snapshotted - restore it as new shard
|
||||||
indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(shardId, primary,
|
indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(shardId, primary,
|
||||||
primary ? StoreRecoverySource.EMPTY_STORE_INSTANCE : PeerRecoverySource.INSTANCE, unassignedInfo));
|
primary ? EmptyStoreRecoverySource.INSTANCE : PeerRecoverySource.INSTANCE, unassignedInfo));
|
||||||
} else {
|
} else {
|
||||||
indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(shardId, primary,
|
indexShardRoutingBuilder.addShard(ShardRouting.newUnassigned(shardId, primary,
|
||||||
primary ? recoverySource : PeerRecoverySource.INSTANCE, unassignedInfo));
|
primary ? recoverySource : PeerRecoverySource.INSTANCE, unassignedInfo));
|
||||||
|
@ -410,13 +411,13 @@ public class IndexRoutingTable extends AbstractDiffable<IndexRoutingTable> imple
|
||||||
final RecoverySource primaryRecoverySource;
|
final RecoverySource primaryRecoverySource;
|
||||||
if (indexMetaData.inSyncAllocationIds(shardNumber).isEmpty() == false) {
|
if (indexMetaData.inSyncAllocationIds(shardNumber).isEmpty() == false) {
|
||||||
// we have previous valid copies for this shard. use them for recovery
|
// we have previous valid copies for this shard. use them for recovery
|
||||||
primaryRecoverySource = StoreRecoverySource.EXISTING_STORE_INSTANCE;
|
primaryRecoverySource = ExistingStoreRecoverySource.INSTANCE;
|
||||||
} else if (indexMetaData.getResizeSourceIndex() != null) {
|
} else if (indexMetaData.getResizeSourceIndex() != null) {
|
||||||
// this is a new index but the initial shards should merged from another index
|
// this is a new index but the initial shards should merged from another index
|
||||||
primaryRecoverySource = LocalShardsRecoverySource.INSTANCE;
|
primaryRecoverySource = LocalShardsRecoverySource.INSTANCE;
|
||||||
} else {
|
} else {
|
||||||
// a freshly created index with no restriction
|
// a freshly created index with no restriction
|
||||||
primaryRecoverySource = StoreRecoverySource.EMPTY_STORE_INSTANCE;
|
primaryRecoverySource = EmptyStoreRecoverySource.INSTANCE;
|
||||||
}
|
}
|
||||||
IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(shardId);
|
IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(shardId);
|
||||||
for (int i = 0; i <= indexMetaData.getNumberOfReplicas(); i++) {
|
for (int i = 0; i <= indexMetaData.getNumberOfReplicas(); i++) {
|
||||||
|
|
|
@ -34,7 +34,8 @@ import java.util.Objects;
|
||||||
/**
|
/**
|
||||||
* Represents the recovery source of a shard. Available recovery types are:
|
* Represents the recovery source of a shard. Available recovery types are:
|
||||||
*
|
*
|
||||||
* - {@link StoreRecoverySource} recovery from the local store (empty or with existing data)
|
* - {@link EmptyStoreRecoverySource} recovery from an empty store
|
||||||
|
* - {@link ExistingStoreRecoverySource} recovery from an existing store
|
||||||
* - {@link PeerRecoverySource} recovery from a primary on another node
|
* - {@link PeerRecoverySource} recovery from a primary on another node
|
||||||
* - {@link SnapshotRecoverySource} recovery from a snapshot
|
* - {@link SnapshotRecoverySource} recovery from a snapshot
|
||||||
* - {@link LocalShardsRecoverySource} recovery from other shards of another index on the same node
|
* - {@link LocalShardsRecoverySource} recovery from other shards of another index on the same node
|
||||||
|
@ -59,8 +60,8 @@ public abstract class RecoverySource implements Writeable, ToXContentObject {
|
||||||
public static RecoverySource readFrom(StreamInput in) throws IOException {
|
public static RecoverySource readFrom(StreamInput in) throws IOException {
|
||||||
Type type = Type.values()[in.readByte()];
|
Type type = Type.values()[in.readByte()];
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EMPTY_STORE: return StoreRecoverySource.EMPTY_STORE_INSTANCE;
|
case EMPTY_STORE: return EmptyStoreRecoverySource.INSTANCE;
|
||||||
case EXISTING_STORE: return StoreRecoverySource.EXISTING_STORE_INSTANCE;
|
case EXISTING_STORE: return new ExistingStoreRecoverySource(in);
|
||||||
case PEER: return PeerRecoverySource.INSTANCE;
|
case PEER: return PeerRecoverySource.INSTANCE;
|
||||||
case SNAPSHOT: return new SnapshotRecoverySource(in);
|
case SNAPSHOT: return new SnapshotRecoverySource(in);
|
||||||
case LOCAL_SHARDS: return LocalShardsRecoverySource.INSTANCE;
|
case LOCAL_SHARDS: return LocalShardsRecoverySource.INSTANCE;
|
||||||
|
@ -91,6 +92,10 @@ public abstract class RecoverySource implements Writeable, ToXContentObject {
|
||||||
|
|
||||||
public abstract Type getType();
|
public abstract Type getType();
|
||||||
|
|
||||||
|
public boolean shouldBootstrapNewHistoryUUID() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -107,25 +112,68 @@ public abstract class RecoverySource implements Writeable, ToXContentObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* recovery from an existing on-disk store or a fresh copy
|
* Recovery from a fresh copy
|
||||||
*/
|
*/
|
||||||
public abstract static class StoreRecoverySource extends RecoverySource {
|
public static final class EmptyStoreRecoverySource extends RecoverySource {
|
||||||
public static final StoreRecoverySource EMPTY_STORE_INSTANCE = new StoreRecoverySource() {
|
public static final EmptyStoreRecoverySource INSTANCE = new EmptyStoreRecoverySource();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Type.EMPTY_STORE;
|
return Type.EMPTY_STORE;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
public static final StoreRecoverySource EXISTING_STORE_INSTANCE = new StoreRecoverySource() {
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "new shard recovery";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recovery from an existing on-disk store
|
||||||
|
*/
|
||||||
|
public static final class ExistingStoreRecoverySource extends RecoverySource {
|
||||||
|
public static final ExistingStoreRecoverySource INSTANCE = new ExistingStoreRecoverySource(false);
|
||||||
|
public static final ExistingStoreRecoverySource FORCE_STALE_PRIMARY_INSTANCE = new ExistingStoreRecoverySource(true);
|
||||||
|
|
||||||
|
private final boolean bootstrapNewHistoryUUID;
|
||||||
|
|
||||||
|
private ExistingStoreRecoverySource(boolean bootstrapNewHistoryUUID) {
|
||||||
|
this.bootstrapNewHistoryUUID = bootstrapNewHistoryUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExistingStoreRecoverySource(StreamInput in) throws IOException {
|
||||||
|
if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
|
||||||
|
bootstrapNewHistoryUUID = in.readBoolean();
|
||||||
|
} else {
|
||||||
|
bootstrapNewHistoryUUID = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addAdditionalFields(XContentBuilder builder, Params params) throws IOException {
|
||||||
|
builder.field("bootstrap_new_history_uuid", bootstrapNewHistoryUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void writeAdditionalFields(StreamOutput out) throws IOException {
|
||||||
|
if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) {
|
||||||
|
out.writeBoolean(bootstrapNewHistoryUUID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldBootstrapNewHistoryUUID() {
|
||||||
|
return bootstrapNewHistoryUUID;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Type.EXISTING_STORE;
|
return Type.EXISTING_STORE;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getType() == Type.EMPTY_STORE ? "new shard recovery" : "existing recovery";
|
return "existing store recovery; bootstrap_history_uuid=" + bootstrapNewHistoryUUID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,13 @@
|
||||||
|
|
||||||
package org.elasticsearch.cluster.routing;
|
package org.elasticsearch.cluster.routing;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource.ExistingStoreRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource;
|
|
||||||
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
|
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent.Params;
|
|
||||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
|
@ -318,7 +317,7 @@ public final class ShardRouting implements Writeable, ToXContentObject {
|
||||||
final RecoverySource recoverySource;
|
final RecoverySource recoverySource;
|
||||||
if (active()) {
|
if (active()) {
|
||||||
if (primary()) {
|
if (primary()) {
|
||||||
recoverySource = StoreRecoverySource.EXISTING_STORE_INSTANCE;
|
recoverySource = ExistingStoreRecoverySource.INSTANCE;
|
||||||
} else {
|
} else {
|
||||||
recoverySource = PeerRecoverySource.INSTANCE;
|
recoverySource = PeerRecoverySource.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.cluster.routing.allocation.command;
|
||||||
|
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.EmptyStoreRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RoutingNode;
|
import org.elasticsearch.cluster.routing.RoutingNode;
|
||||||
import org.elasticsearch.cluster.routing.RoutingNodes;
|
import org.elasticsearch.cluster.routing.RoutingNodes;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
|
@ -136,7 +136,7 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeUnassignedShard(allocation, routingNodes, routingNode, shardRouting, unassignedInfoToUpdate,
|
initializeUnassignedShard(allocation, routingNodes, routingNode, shardRouting, unassignedInfoToUpdate,
|
||||||
StoreRecoverySource.EMPTY_STORE_INSTANCE);
|
EmptyStoreRecoverySource.INSTANCE);
|
||||||
|
|
||||||
return new RerouteExplanation(this, allocation.decision(Decision.YES, name() + " (allocation command)", "ignore deciders"));
|
return new RerouteExplanation(this, allocation.decision(Decision.YES, name() + " (allocation command)", "ignore deciders"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,8 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation
|
||||||
"trying to allocate an existing primary shard [" + index + "][" + shardId + "], while no such shard has ever been active");
|
"trying to allocate an existing primary shard [" + index + "][" + shardId + "], while no such shard has ever been active");
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeUnassignedShard(allocation, routingNodes, routingNode, shardRouting);
|
initializeUnassignedShard(allocation, routingNodes, routingNode, shardRouting, null,
|
||||||
|
RecoverySource.ExistingStoreRecoverySource.FORCE_STALE_PRIMARY_INSTANCE);
|
||||||
return new RerouteExplanation(this, allocation.decision(Decision.YES, name() + " (allocation command)", "ignore deciders"));
|
return new RerouteExplanation(this, allocation.decision(Decision.YES, name() + " (allocation command)", "ignore deciders"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -398,6 +398,9 @@ final class StoreRecovery {
|
||||||
indexShard.shardPath().resolveTranslog(), maxSeqNo, shardId, indexShard.getPendingPrimaryTerm());
|
indexShard.shardPath().resolveTranslog(), maxSeqNo, shardId, indexShard.getPendingPrimaryTerm());
|
||||||
store.associateIndexWithNewTranslog(translogUUID);
|
store.associateIndexWithNewTranslog(translogUUID);
|
||||||
} else if (indexShouldExists) {
|
} else if (indexShouldExists) {
|
||||||
|
if (recoveryState.getRecoverySource().shouldBootstrapNewHistoryUUID()) {
|
||||||
|
store.bootstrapNewHistory();
|
||||||
|
}
|
||||||
// since we recover from local, just fill the files and size
|
// since we recover from local, just fill the files and size
|
||||||
try {
|
try {
|
||||||
final RecoveryState.Index index = recoveryState.getIndex();
|
final RecoveryState.Index index = recoveryState.getIndex();
|
||||||
|
|
|
@ -377,7 +377,7 @@ public class SearchAsyncActionTests extends ESTestCase {
|
||||||
ArrayList<ShardRouting> unassigned = new ArrayList<>();
|
ArrayList<ShardRouting> unassigned = new ArrayList<>();
|
||||||
|
|
||||||
ShardRouting routing = ShardRouting.newUnassigned(new ShardId(new Index(index, "_na_"), i), true,
|
ShardRouting routing = ShardRouting.newUnassigned(new ShardId(new Index(index, "_na_"), i), true,
|
||||||
RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"));
|
RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"));
|
||||||
routing = routing.initialize(primaryNode.getId(), i + "p", 0);
|
routing = routing.initialize(primaryNode.getId(), i + "p", 0);
|
||||||
routing.started();
|
routing.started();
|
||||||
started.add(routing);
|
started.add(routing);
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.cluster.routing;
|
package org.elasticsearch.cluster.routing;
|
||||||
|
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.ExistingStoreRecoverySource;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
@ -37,7 +37,7 @@ import static org.hamcrest.Matchers.nullValue;
|
||||||
public class AllocationIdTests extends ESTestCase {
|
public class AllocationIdTests extends ESTestCase {
|
||||||
public void testShardToStarted() {
|
public void testShardToStarted() {
|
||||||
logger.info("-- create unassigned shard");
|
logger.info("-- create unassigned shard");
|
||||||
ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, StoreRecoverySource.EXISTING_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
||||||
assertThat(shard.allocationId(), nullValue());
|
assertThat(shard.allocationId(), nullValue());
|
||||||
|
|
||||||
logger.info("-- initialize the shard");
|
logger.info("-- initialize the shard");
|
||||||
|
@ -57,7 +57,7 @@ public class AllocationIdTests extends ESTestCase {
|
||||||
|
|
||||||
public void testSuccessfulRelocation() {
|
public void testSuccessfulRelocation() {
|
||||||
logger.info("-- build started shard");
|
logger.info("-- build started shard");
|
||||||
ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, StoreRecoverySource.EXISTING_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
||||||
shard = shard.initialize("node1", null, -1);
|
shard = shard.initialize("node1", null, -1);
|
||||||
shard = shard.moveToStarted();
|
shard = shard.moveToStarted();
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public class AllocationIdTests extends ESTestCase {
|
||||||
|
|
||||||
public void testCancelRelocation() {
|
public void testCancelRelocation() {
|
||||||
logger.info("-- build started shard");
|
logger.info("-- build started shard");
|
||||||
ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, StoreRecoverySource.EXISTING_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
||||||
shard = shard.initialize("node1", null, -1);
|
shard = shard.initialize("node1", null, -1);
|
||||||
shard = shard.moveToStarted();
|
shard = shard.moveToStarted();
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class AllocationIdTests extends ESTestCase {
|
||||||
|
|
||||||
public void testMoveToUnassigned() {
|
public void testMoveToUnassigned() {
|
||||||
logger.info("-- build started shard");
|
logger.info("-- build started shard");
|
||||||
ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, StoreRecoverySource.EXISTING_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null));
|
||||||
shard = shard.initialize("node1", null, -1);
|
shard = shard.initialize("node1", null, -1);
|
||||||
shard = shard.moveToStarted();
|
shard = shard.moveToStarted();
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class GroupShardsIteratorTests extends ESTestCase {
|
||||||
|
|
||||||
public ShardRouting newRouting(Index index, int id, boolean started) {
|
public ShardRouting newRouting(Index index, int id, boolean started) {
|
||||||
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, id), true,
|
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, id), true,
|
||||||
RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
||||||
shardRouting = ShardRoutingHelper.initialize(shardRouting, "some node");
|
shardRouting = ShardRoutingHelper.initialize(shardRouting, "some node");
|
||||||
if (started) {
|
if (started) {
|
||||||
shardRouting = ShardRoutingHelper.moveToStarted(shardRouting);
|
shardRouting = ShardRoutingHelper.moveToStarted(shardRouting);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.elasticsearch.common.collect.ImmutableOpenIntMap;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.set.Sets;
|
import org.elasticsearch.common.util.set.Sets;
|
||||||
import org.elasticsearch.gateway.GatewayAllocator;
|
import org.elasticsearch.gateway.GatewayAllocator;
|
||||||
|
import org.elasticsearch.index.engine.Engine;
|
||||||
import org.elasticsearch.index.engine.EngineTestCase;
|
import org.elasticsearch.index.engine.EngineTestCase;
|
||||||
import org.elasticsearch.index.shard.IndexShard;
|
import org.elasticsearch.index.shard.IndexShard;
|
||||||
import org.elasticsearch.index.shard.IndexShardTestCase;
|
import org.elasticsearch.index.shard.IndexShardTestCase;
|
||||||
|
@ -55,6 +56,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||||
|
@ -64,6 +66,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.empty;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.everyItem;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.isIn;
|
import static org.hamcrest.Matchers.isIn;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
|
@ -83,18 +86,9 @@ public class PrimaryAllocationIT extends ESIntegTestCase {
|
||||||
.put(TestZenDiscovery.USE_MOCK_PINGS.getKey(), false).build();
|
.put(TestZenDiscovery.USE_MOCK_PINGS.getKey(), false).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createStaleReplicaScenario() throws Exception {
|
private void createStaleReplicaScenario(String master) throws Exception {
|
||||||
logger.info("--> starting 3 nodes, 1 master, 2 data");
|
|
||||||
String master = internalCluster().startMasterOnlyNode(Settings.EMPTY);
|
|
||||||
internalCluster().startDataOnlyNodes(2);
|
|
||||||
|
|
||||||
assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder()
|
|
||||||
.put("index.number_of_shards", 1).put("index.number_of_replicas", 1)).get());
|
|
||||||
ensureGreen();
|
|
||||||
logger.info("--> indexing...");
|
|
||||||
client().prepareIndex("test", "type1").setSource(jsonBuilder().startObject().field("field", "value1").endObject()).get();
|
client().prepareIndex("test", "type1").setSource(jsonBuilder().startObject().field("field", "value1").endObject()).get();
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
ClusterState state = client().admin().cluster().prepareState().all().get().getState();
|
ClusterState state = client().admin().cluster().prepareState().all().get().getState();
|
||||||
List<ShardRouting> shards = state.routingTable().allShards("test");
|
List<ShardRouting> shards = state.routingTable().allShards("test");
|
||||||
assertThat(shards.size(), equalTo(2));
|
assertThat(shards.size(), equalTo(2));
|
||||||
|
@ -140,7 +134,13 @@ public class PrimaryAllocationIT extends ESIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDoNotAllowStaleReplicasToBePromotedToPrimary() throws Exception {
|
public void testDoNotAllowStaleReplicasToBePromotedToPrimary() throws Exception {
|
||||||
createStaleReplicaScenario();
|
logger.info("--> starting 3 nodes, 1 master, 2 data");
|
||||||
|
String master = internalCluster().startMasterOnlyNode(Settings.EMPTY);
|
||||||
|
internalCluster().startDataOnlyNodes(2);
|
||||||
|
assertAcked(client().admin().indices().prepareCreate("test")
|
||||||
|
.setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 1)).get());
|
||||||
|
ensureGreen();
|
||||||
|
createStaleReplicaScenario(master);
|
||||||
|
|
||||||
logger.info("--> starting node that reuses data folder with the up-to-date primary shard");
|
logger.info("--> starting node that reuses data folder with the up-to-date primary shard");
|
||||||
internalCluster().startDataOnlyNode(Settings.EMPTY);
|
internalCluster().startDataOnlyNode(Settings.EMPTY);
|
||||||
|
@ -176,9 +176,17 @@ public class PrimaryAllocationIT extends ESIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testForceStaleReplicaToBePromotedToPrimary() throws Exception {
|
public void testForceStaleReplicaToBePromotedToPrimary() throws Exception {
|
||||||
boolean useStaleReplica = randomBoolean(); // if true, use stale replica, otherwise a completely empty copy
|
logger.info("--> starting 3 nodes, 1 master, 2 data");
|
||||||
createStaleReplicaScenario();
|
String master = internalCluster().startMasterOnlyNode(Settings.EMPTY);
|
||||||
|
internalCluster().startDataOnlyNodes(2);
|
||||||
|
assertAcked(client().admin().indices().prepareCreate("test")
|
||||||
|
.setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 1)).get());
|
||||||
|
ensureGreen();
|
||||||
|
Set<String> historyUUIDs = Arrays.stream(client().admin().indices().prepareStats("test").clear().get().getShards())
|
||||||
|
.map(shard -> shard.getCommitStats().getUserData().get(Engine.HISTORY_UUID_KEY)).collect(Collectors.toSet());
|
||||||
|
createStaleReplicaScenario(master);
|
||||||
|
|
||||||
|
boolean useStaleReplica = randomBoolean(); // if true, use stale replica, otherwise a completely empty copy
|
||||||
logger.info("--> explicitly promote old primary shard");
|
logger.info("--> explicitly promote old primary shard");
|
||||||
final String idxName = "test";
|
final String idxName = "test";
|
||||||
ImmutableOpenIntMap<List<IndicesShardStoresResponse.StoreStatus>> storeStatuses = client().admin().indices().prepareShardStores(idxName).get().getStoreStatuses().get(idxName);
|
ImmutableOpenIntMap<List<IndicesShardStoresResponse.StoreStatus>> storeStatuses = client().admin().indices().prepareShardStores(idxName).get().getStoreStatuses().get(idxName);
|
||||||
|
@ -213,6 +221,11 @@ public class PrimaryAllocationIT extends ESIntegTestCase {
|
||||||
ClusterState state = client().admin().cluster().prepareState().get().getState();
|
ClusterState state = client().admin().cluster().prepareState().get().getState();
|
||||||
assertEquals(Collections.singleton(state.routingTable().index(idxName).shard(0).primary.allocationId().getId()),
|
assertEquals(Collections.singleton(state.routingTable().index(idxName).shard(0).primary.allocationId().getId()),
|
||||||
state.metaData().index(idxName).inSyncAllocationIds(0));
|
state.metaData().index(idxName).inSyncAllocationIds(0));
|
||||||
|
|
||||||
|
Set<String> newHistoryUUIds = Arrays.stream(client().admin().indices().prepareStats("test").clear().get().getShards())
|
||||||
|
.map(shard -> shard.getCommitStats().getUserData().get(Engine.HISTORY_UUID_KEY)).collect(Collectors.toSet());
|
||||||
|
assertThat(newHistoryUUIds, everyItem(not(isIn(historyUUIDs))));
|
||||||
|
assertThat(newHistoryUUIds, hasSize(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testForcePrimaryShardIfAllocationDecidersSayNoAfterIndexCreation() throws ExecutionException, InterruptedException {
|
public void testForcePrimaryShardIfAllocationDecidersSayNoAfterIndexCreation() throws ExecutionException, InterruptedException {
|
||||||
|
|
|
@ -399,7 +399,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
|
||||||
final boolean primary = randomBoolean();
|
final boolean primary = randomBoolean();
|
||||||
final ShardRouting unassigned = ShardRouting.newUnassigned(new ShardId(index, shard), primary,
|
final ShardRouting unassigned = ShardRouting.newUnassigned(new ShardId(index, shard), primary,
|
||||||
primary ?
|
primary ?
|
||||||
RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE :
|
RecoverySource.EmptyStoreRecoverySource.INSTANCE :
|
||||||
RecoverySource.PeerRecoverySource.INSTANCE,
|
RecoverySource.PeerRecoverySource.INSTANCE,
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test")
|
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test")
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,9 +29,9 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource.EmptyStoreRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.LocalShardsRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.LocalShardsRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource;
|
|
||||||
import org.elasticsearch.cluster.routing.RoutingNode;
|
import org.elasticsearch.cluster.routing.RoutingNode;
|
||||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
|
@ -69,7 +69,7 @@ public class DiskThresholdDeciderUnitTests extends ESAllocationTestCase {
|
||||||
|
|
||||||
final Index index = metaData.index("test").getIndex();
|
final Index index = metaData.index("test").getIndex();
|
||||||
|
|
||||||
ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), true, StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
||||||
DiscoveryNode node_0 = new DiscoveryNode("node_0", buildNewFakeTransportAddress(), Collections.emptyMap(),
|
DiscoveryNode node_0 = new DiscoveryNode("node_0", buildNewFakeTransportAddress(), Collections.emptyMap(),
|
||||||
new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);
|
new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);
|
||||||
DiscoveryNode node_1 = new DiscoveryNode("node_1", buildNewFakeTransportAddress(), Collections.emptyMap(),
|
DiscoveryNode node_1 = new DiscoveryNode("node_1", buildNewFakeTransportAddress(), Collections.emptyMap(),
|
||||||
|
@ -125,22 +125,22 @@ public class DiskThresholdDeciderUnitTests extends ESAllocationTestCase {
|
||||||
.build();
|
.build();
|
||||||
final IndexMetaData indexMetaData = metaData.index("test");
|
final IndexMetaData indexMetaData = metaData.index("test");
|
||||||
|
|
||||||
ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(indexMetaData.getIndex(), 0), true, StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(indexMetaData.getIndex(), 0), true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
||||||
test_0 = ShardRoutingHelper.initialize(test_0, node_0.getId());
|
test_0 = ShardRoutingHelper.initialize(test_0, node_0.getId());
|
||||||
test_0 = ShardRoutingHelper.moveToStarted(test_0);
|
test_0 = ShardRoutingHelper.moveToStarted(test_0);
|
||||||
shardRoutingMap.put(test_0, "/node0/least");
|
shardRoutingMap.put(test_0, "/node0/least");
|
||||||
|
|
||||||
ShardRouting test_1 = ShardRouting.newUnassigned(new ShardId(indexMetaData.getIndex(), 1), true, StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
ShardRouting test_1 = ShardRouting.newUnassigned(new ShardId(indexMetaData.getIndex(), 1), true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
||||||
test_1 = ShardRoutingHelper.initialize(test_1, node_1.getId());
|
test_1 = ShardRoutingHelper.initialize(test_1, node_1.getId());
|
||||||
test_1 = ShardRoutingHelper.moveToStarted(test_1);
|
test_1 = ShardRoutingHelper.moveToStarted(test_1);
|
||||||
shardRoutingMap.put(test_1, "/node1/least");
|
shardRoutingMap.put(test_1, "/node1/least");
|
||||||
|
|
||||||
ShardRouting test_2 = ShardRouting.newUnassigned(new ShardId(indexMetaData.getIndex(), 2), true, StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
ShardRouting test_2 = ShardRouting.newUnassigned(new ShardId(indexMetaData.getIndex(), 2), true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
||||||
test_2 = ShardRoutingHelper.initialize(test_2, node_1.getId());
|
test_2 = ShardRoutingHelper.initialize(test_2, node_1.getId());
|
||||||
test_2 = ShardRoutingHelper.moveToStarted(test_2);
|
test_2 = ShardRoutingHelper.moveToStarted(test_2);
|
||||||
shardRoutingMap.put(test_2, "/node1/most");
|
shardRoutingMap.put(test_2, "/node1/most");
|
||||||
|
|
||||||
ShardRouting test_3 = ShardRouting.newUnassigned(new ShardId(indexMetaData.getIndex(), 3), true, StoreRecoverySource.EMPTY_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
ShardRouting test_3 = ShardRouting.newUnassigned(new ShardId(indexMetaData.getIndex(), 3), true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
|
||||||
test_3 = ShardRoutingHelper.initialize(test_3, node_1.getId());
|
test_3 = ShardRoutingHelper.initialize(test_3, node_1.getId());
|
||||||
test_3 = ShardRoutingHelper.moveToStarted(test_3);
|
test_3 = ShardRoutingHelper.moveToStarted(test_3);
|
||||||
// Intentionally not in the shardRoutingMap. We want to test what happens when we don't know where it is.
|
// Intentionally not in the shardRoutingMap. We want to test what happens when we don't know where it is.
|
||||||
|
|
|
@ -637,7 +637,7 @@ public class IndexShardIT extends ESSingleNodeTestCase {
|
||||||
existingShardRouting.currentNodeId(), null, existingShardRouting.primary(), ShardRoutingState.INITIALIZING,
|
existingShardRouting.currentNodeId(), null, existingShardRouting.primary(), ShardRoutingState.INITIALIZING,
|
||||||
existingShardRouting.allocationId());
|
existingShardRouting.allocationId());
|
||||||
shardRouting = shardRouting.updateUnassigned(new UnassignedInfo(UnassignedInfo.Reason.INDEX_REOPENED, "fake recovery"),
|
shardRouting = shardRouting.updateUnassigned(new UnassignedInfo(UnassignedInfo.Reason.INDEX_REOPENED, "fake recovery"),
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE);
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE);
|
||||||
return shardRouting;
|
return shardRouting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,6 +178,7 @@ import static org.hamcrest.Matchers.hasToString;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.lessThan;
|
import static org.hamcrest.Matchers.lessThan;
|
||||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
|
||||||
|
@ -843,7 +844,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
randomAlphaOfLength(8),
|
randomAlphaOfLength(8),
|
||||||
true,
|
true,
|
||||||
ShardRoutingState.INITIALIZING,
|
ShardRoutingState.INITIALIZING,
|
||||||
RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE);
|
RecoverySource.EmptyStoreRecoverySource.INSTANCE);
|
||||||
final Settings settings = Settings.builder()
|
final Settings settings = Settings.builder()
|
||||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 2)
|
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 2)
|
||||||
|
@ -1199,7 +1200,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
public void testShardStatsWithFailures() throws IOException {
|
public void testShardStatsWithFailures() throws IOException {
|
||||||
allowShardFailures();
|
allowShardFailures();
|
||||||
final ShardId shardId = new ShardId("index", "_na_", 0);
|
final ShardId shardId = new ShardId("index", "_na_", 0);
|
||||||
final ShardRouting shardRouting = newShardRouting(shardId, "node", true, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE, ShardRoutingState.INITIALIZING);
|
final ShardRouting shardRouting = newShardRouting(shardId, "node", true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, ShardRoutingState.INITIALIZING);
|
||||||
final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(createTempDir());
|
final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(createTempDir());
|
||||||
|
|
||||||
|
|
||||||
|
@ -1659,7 +1660,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
final ShardRouting replicaRouting = shard.routingEntry();
|
final ShardRouting replicaRouting = shard.routingEntry();
|
||||||
IndexShard newShard = reinitShard(shard,
|
IndexShard newShard = reinitShard(shard,
|
||||||
newShardRouting(replicaRouting.shardId(), replicaRouting.currentNodeId(), true, ShardRoutingState.INITIALIZING,
|
newShardRouting(replicaRouting.shardId(), replicaRouting.currentNodeId(), true, ShardRoutingState.INITIALIZING,
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE));
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE));
|
||||||
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||||
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
||||||
assertTrue(newShard.recoverFromStore());
|
assertTrue(newShard.recoverFromStore());
|
||||||
|
@ -1684,6 +1685,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
flushShard(shard);
|
flushShard(shard);
|
||||||
translogOps = 0;
|
translogOps = 0;
|
||||||
}
|
}
|
||||||
|
String historyUUID = shard.getHistoryUUID();
|
||||||
IndexShard newShard = reinitShard(shard);
|
IndexShard newShard = reinitShard(shard);
|
||||||
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||||
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
||||||
|
@ -1698,6 +1700,29 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
assertThat(newShard.getReplicationTracker().getTrackedLocalCheckpointForShard(newShard.routingEntry().allocationId().getId())
|
assertThat(newShard.getReplicationTracker().getTrackedLocalCheckpointForShard(newShard.routingEntry().allocationId().getId())
|
||||||
.getLocalCheckpoint(), equalTo(totalOps - 1L));
|
.getLocalCheckpoint(), equalTo(totalOps - 1L));
|
||||||
assertDocCount(newShard, totalOps);
|
assertDocCount(newShard, totalOps);
|
||||||
|
assertThat(newShard.getHistoryUUID(), equalTo(historyUUID));
|
||||||
|
closeShards(newShard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testRecoverFromStalePrimaryForceNewHistoryUUID() throws IOException {
|
||||||
|
final IndexShard shard = newStartedShard(true);
|
||||||
|
int totalOps = randomInt(10);
|
||||||
|
for (int i = 0; i < totalOps; i++) {
|
||||||
|
indexDoc(shard, "_doc", Integer.toString(i));
|
||||||
|
}
|
||||||
|
if (randomBoolean()) {
|
||||||
|
shard.updateLocalCheckpointForShard(shard.shardRouting.allocationId().getId(), totalOps - 1);
|
||||||
|
flushShard(shard);
|
||||||
|
}
|
||||||
|
String historyUUID = shard.getHistoryUUID();
|
||||||
|
IndexShard newShard = reinitShard(shard, newShardRouting(shard.shardId(), shard.shardRouting.currentNodeId(), true,
|
||||||
|
ShardRoutingState.INITIALIZING, RecoverySource.ExistingStoreRecoverySource.FORCE_STALE_PRIMARY_INSTANCE));
|
||||||
|
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||||
|
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
||||||
|
assertTrue(newShard.recoverFromStore());
|
||||||
|
IndexShardTestCase.updateRoutingEntry(newShard, newShard.routingEntry().moveToStarted());
|
||||||
|
assertDocCount(newShard, totalOps);
|
||||||
|
assertThat(newShard.getHistoryUUID(), not(equalTo(historyUUID)));
|
||||||
closeShards(newShard);
|
closeShards(newShard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1734,7 +1759,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
|
|
||||||
final ShardRouting primaryShardRouting = shard.routingEntry();
|
final ShardRouting primaryShardRouting = shard.routingEntry();
|
||||||
IndexShard newShard = reinitShard(otherShard, ShardRoutingHelper.initWithSameId(primaryShardRouting,
|
IndexShard newShard = reinitShard(otherShard, ShardRoutingHelper.initWithSameId(primaryShardRouting,
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE));
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE));
|
||||||
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||||
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
||||||
assertTrue(newShard.recoverFromStore());
|
assertTrue(newShard.recoverFromStore());
|
||||||
|
@ -1760,7 +1785,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
newShard = reinitShard(newShard, ShardRoutingHelper.initWithSameId(primaryShardRouting,
|
newShard = reinitShard(newShard, ShardRoutingHelper.initWithSameId(primaryShardRouting,
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE));
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE));
|
||||||
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
||||||
assertTrue(newShard.recoverFromStore());
|
assertTrue(newShard.recoverFromStore());
|
||||||
try (Translog.Snapshot snapshot = getTranslog(newShard).newSnapshot()) {
|
try (Translog.Snapshot snapshot = getTranslog(newShard).newSnapshot()) {
|
||||||
|
@ -1778,7 +1803,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
}
|
}
|
||||||
final ShardRouting shardRouting = shard.routingEntry();
|
final ShardRouting shardRouting = shard.routingEntry();
|
||||||
IndexShard newShard = reinitShard(shard,
|
IndexShard newShard = reinitShard(shard,
|
||||||
ShardRoutingHelper.initWithSameId(shardRouting, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE)
|
ShardRoutingHelper.initWithSameId(shardRouting, RecoverySource.EmptyStoreRecoverySource.INSTANCE)
|
||||||
);
|
);
|
||||||
|
|
||||||
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||||
|
@ -1827,7 +1852,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
newShard = reinitShard(newShard,
|
newShard = reinitShard(newShard,
|
||||||
ShardRoutingHelper.initWithSameId(routing, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE));
|
ShardRoutingHelper.initWithSameId(routing, RecoverySource.EmptyStoreRecoverySource.INSTANCE));
|
||||||
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null));
|
||||||
assertTrue("recover even if there is nothing to recover", newShard.recoverFromStore());
|
assertTrue("recover even if there is nothing to recover", newShard.recoverFromStore());
|
||||||
|
|
||||||
|
@ -1865,7 +1890,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
final ShardRouting replicaRouting = shard.routingEntry();
|
final ShardRouting replicaRouting = shard.routingEntry();
|
||||||
IndexShard newShard = reinitShard(shard,
|
IndexShard newShard = reinitShard(shard,
|
||||||
newShardRouting(replicaRouting.shardId(), replicaRouting.currentNodeId(), true, ShardRoutingState.INITIALIZING,
|
newShardRouting(replicaRouting.shardId(), replicaRouting.currentNodeId(), true, ShardRoutingState.INITIALIZING,
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE));
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE));
|
||||||
newShard.pendingPrimaryTerm++;
|
newShard.pendingPrimaryTerm++;
|
||||||
newShard.operationPrimaryTerm++;
|
newShard.operationPrimaryTerm++;
|
||||||
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
|
||||||
|
@ -1905,7 +1930,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
assertDocs(target, "1");
|
assertDocs(target, "1");
|
||||||
flushShard(source); // only flush source
|
flushShard(source); // only flush source
|
||||||
ShardRouting routing = ShardRoutingHelper.initWithSameId(target.routingEntry(),
|
ShardRouting routing = ShardRoutingHelper.initWithSameId(target.routingEntry(),
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE);
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE);
|
||||||
final Snapshot snapshot = new Snapshot("foo", new SnapshotId("bar", UUIDs.randomBase64UUID()));
|
final Snapshot snapshot = new Snapshot("foo", new SnapshotId("bar", UUIDs.randomBase64UUID()));
|
||||||
routing = ShardRoutingHelper.newWithRestoreSource(routing,
|
routing = ShardRoutingHelper.newWithRestoreSource(routing,
|
||||||
new RecoverySource.SnapshotRecoverySource(snapshot, Version.CURRENT, "test"));
|
new RecoverySource.SnapshotRecoverySource(snapshot, Version.CURRENT, "test"));
|
||||||
|
@ -1974,7 +1999,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
};
|
};
|
||||||
closeShards(shard);
|
closeShards(shard);
|
||||||
IndexShard newShard = newShard(
|
IndexShard newShard = newShard(
|
||||||
ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE),
|
ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.ExistingStoreRecoverySource.INSTANCE),
|
||||||
shard.shardPath(),
|
shard.shardPath(),
|
||||||
shard.indexSettings().getIndexMetaData(),
|
shard.indexSettings().getIndexMetaData(),
|
||||||
null,
|
null,
|
||||||
|
@ -2127,7 +2152,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
|
|
||||||
closeShards(shard);
|
closeShards(shard);
|
||||||
IndexShard newShard = newShard(
|
IndexShard newShard = newShard(
|
||||||
ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE),
|
ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.ExistingStoreRecoverySource.INSTANCE),
|
||||||
shard.shardPath(),
|
shard.shardPath(),
|
||||||
shard.indexSettings().getIndexMetaData(),
|
shard.indexSettings().getIndexMetaData(),
|
||||||
null,
|
null,
|
||||||
|
@ -2625,7 +2650,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
assertThat("corruption marker should not be there", corruptedMarkerCount.get(), equalTo(0));
|
assertThat("corruption marker should not be there", corruptedMarkerCount.get(), equalTo(0));
|
||||||
|
|
||||||
final ShardRouting shardRouting = ShardRoutingHelper.initWithSameId(indexShard.routingEntry(),
|
final ShardRouting shardRouting = ShardRoutingHelper.initWithSameId(indexShard.routingEntry(),
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE
|
||||||
);
|
);
|
||||||
// start shard and perform index check on startup. It enforce shard to fail due to corrupted index files
|
// start shard and perform index check on startup. It enforce shard to fail due to corrupted index files
|
||||||
final IndexMetaData indexMetaData = IndexMetaData.builder(indexShard.indexSettings().getIndexMetaData())
|
final IndexMetaData indexMetaData = IndexMetaData.builder(indexShard.indexSettings().getIndexMetaData())
|
||||||
|
@ -2666,7 +2691,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
final ShardPath shardPath = indexShard.shardPath();
|
final ShardPath shardPath = indexShard.shardPath();
|
||||||
|
|
||||||
final ShardRouting shardRouting = ShardRoutingHelper.initWithSameId(indexShard.routingEntry(),
|
final ShardRouting shardRouting = ShardRoutingHelper.initWithSameId(indexShard.routingEntry(),
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE
|
||||||
);
|
);
|
||||||
final IndexMetaData indexMetaData = indexShard.indexSettings().getIndexMetaData();
|
final IndexMetaData indexMetaData = indexShard.indexSettings().getIndexMetaData();
|
||||||
|
|
||||||
|
@ -2751,7 +2776,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
closeShards(indexShard);
|
closeShards(indexShard);
|
||||||
|
|
||||||
final ShardRouting shardRouting = ShardRoutingHelper.initWithSameId(indexShard.routingEntry(),
|
final ShardRouting shardRouting = ShardRoutingHelper.initWithSameId(indexShard.routingEntry(),
|
||||||
isPrimary ? RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE
|
isPrimary ? RecoverySource.ExistingStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE
|
||||||
);
|
);
|
||||||
final IndexMetaData indexMetaData = IndexMetaData.builder(indexShard.indexSettings().getIndexMetaData())
|
final IndexMetaData indexMetaData = IndexMetaData.builder(indexShard.indexSettings().getIndexMetaData())
|
||||||
.settings(Settings.builder()
|
.settings(Settings.builder()
|
||||||
|
@ -3261,7 +3286,7 @@ public class IndexShardTests extends IndexShardTestCase {
|
||||||
.settings(settings)
|
.settings(settings)
|
||||||
.primaryTerm(0, 1).build();
|
.primaryTerm(0, 1).build();
|
||||||
ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(metaData.getIndex(), 0), "n1", true, ShardRoutingState
|
ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(metaData.getIndex(), 0), "n1", true, ShardRoutingState
|
||||||
.INITIALIZING, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE);
|
.INITIALIZING, RecoverySource.EmptyStoreRecoverySource.INSTANCE);
|
||||||
final ShardId shardId = shardRouting.shardId();
|
final ShardId shardId = shardRouting.shardId();
|
||||||
final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(createTempDir());
|
final NodeEnvironment.NodePath nodePath = new NodeEnvironment.NodePath(createTempDir());
|
||||||
ShardPath shardPath = new ShardPath(false, nodePath.resolve(shardId), nodePath.resolve(shardId), shardId);
|
ShardPath shardPath = new ShardPath(false, nodePath.resolve(shardId), nodePath.resolve(shardId), shardId);
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class IndicesLifecycleListenerSingleNodeTests extends ESSingleNodeTestCas
|
||||||
String nodeId = newRouting.currentNodeId();
|
String nodeId = newRouting.currentNodeId();
|
||||||
UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "boom");
|
UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "boom");
|
||||||
newRouting = newRouting.moveToUnassigned(unassignedInfo)
|
newRouting = newRouting.moveToUnassigned(unassignedInfo)
|
||||||
.updateUnassigned(unassignedInfo, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE);
|
.updateUnassigned(unassignedInfo, RecoverySource.EmptyStoreRecoverySource.INSTANCE);
|
||||||
newRouting = ShardRoutingHelper.initialize(newRouting, nodeId);
|
newRouting = ShardRoutingHelper.initialize(newRouting, nodeId);
|
||||||
IndexShard shard = index.createShard(newRouting, s -> {});
|
IndexShard shard = index.createShard(newRouting, s -> {});
|
||||||
IndexShardTestCase.updateRoutingEntry(shard, newRouting);
|
IndexShardTestCase.updateRoutingEntry(shard, newRouting);
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource;
|
|
||||||
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
|
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -186,7 +185,7 @@ public class IndexRecoveryIT extends ESIntegTestCase {
|
||||||
|
|
||||||
RecoveryState recoveryState = recoveryStates.get(0);
|
RecoveryState recoveryState = recoveryStates.get(0);
|
||||||
|
|
||||||
assertRecoveryState(recoveryState, 0, StoreRecoverySource.EXISTING_STORE_INSTANCE, true, Stage.DONE, null, node);
|
assertRecoveryState(recoveryState, 0, RecoverySource.ExistingStoreRecoverySource.INSTANCE, true, Stage.DONE, null, node);
|
||||||
|
|
||||||
validateIndexRecoveryState(recoveryState.getIndex());
|
validateIndexRecoveryState(recoveryState.getIndex());
|
||||||
}
|
}
|
||||||
|
@ -239,7 +238,7 @@ public class IndexRecoveryIT extends ESIntegTestCase {
|
||||||
|
|
||||||
// validate node A recovery
|
// validate node A recovery
|
||||||
RecoveryState nodeARecoveryState = nodeAResponses.get(0);
|
RecoveryState nodeARecoveryState = nodeAResponses.get(0);
|
||||||
assertRecoveryState(nodeARecoveryState, 0, StoreRecoverySource.EMPTY_STORE_INSTANCE, true, Stage.DONE, null, nodeA);
|
assertRecoveryState(nodeARecoveryState, 0, RecoverySource.EmptyStoreRecoverySource.INSTANCE, true, Stage.DONE, null, nodeA);
|
||||||
validateIndexRecoveryState(nodeARecoveryState.getIndex());
|
validateIndexRecoveryState(nodeARecoveryState.getIndex());
|
||||||
|
|
||||||
// validate node B recovery
|
// validate node B recovery
|
||||||
|
@ -295,7 +294,7 @@ public class IndexRecoveryIT extends ESIntegTestCase {
|
||||||
List<RecoveryState> nodeBRecoveryStates = findRecoveriesForTargetNode(nodeB, recoveryStates);
|
List<RecoveryState> nodeBRecoveryStates = findRecoveriesForTargetNode(nodeB, recoveryStates);
|
||||||
assertThat(nodeBRecoveryStates.size(), equalTo(1));
|
assertThat(nodeBRecoveryStates.size(), equalTo(1));
|
||||||
|
|
||||||
assertRecoveryState(nodeARecoveryStates.get(0), 0, StoreRecoverySource.EMPTY_STORE_INSTANCE, true, Stage.DONE, null, nodeA);
|
assertRecoveryState(nodeARecoveryStates.get(0), 0, RecoverySource.EmptyStoreRecoverySource.INSTANCE, true, Stage.DONE, null, nodeA);
|
||||||
validateIndexRecoveryState(nodeARecoveryStates.get(0).getIndex());
|
validateIndexRecoveryState(nodeARecoveryStates.get(0).getIndex());
|
||||||
|
|
||||||
assertOnGoingRecoveryState(nodeBRecoveryStates.get(0), 0, PeerRecoverySource.INSTANCE, true, nodeA, nodeB);
|
assertOnGoingRecoveryState(nodeBRecoveryStates.get(0), 0, PeerRecoverySource.INSTANCE, true, nodeA, nodeB);
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.repositories.blobstore;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.util.TestUtil;
|
import org.apache.lucene.util.TestUtil;
|
||||||
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.cluster.routing.ShardRoutingHelper;
|
import org.elasticsearch.cluster.routing.ShardRoutingHelper;
|
||||||
import org.elasticsearch.common.UUIDs;
|
import org.elasticsearch.common.UUIDs;
|
||||||
|
@ -49,7 +50,6 @@ import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE;
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,7 +99,8 @@ public class BlobStoreRepositoryRestoreTests extends IndexShardTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// build a new shard using the same store directory as the closed shard
|
// build a new shard using the same store directory as the closed shard
|
||||||
ShardRouting shardRouting = ShardRoutingHelper.initWithSameId(shard.routingEntry(), EXISTING_STORE_INSTANCE);
|
ShardRouting shardRouting = ShardRoutingHelper.initWithSameId(shard.routingEntry(),
|
||||||
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE);
|
||||||
shard = newShard(
|
shard = newShard(
|
||||||
shardRouting,
|
shardRouting,
|
||||||
shard.shardPath(),
|
shard.shardPath(),
|
||||||
|
|
|
@ -30,8 +30,8 @@ import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource;
|
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||||
import org.elasticsearch.common.Table;
|
import org.elasticsearch.common.Table;
|
||||||
|
@ -143,7 +143,7 @@ public class RestIndicesActionTests extends ESTestCase {
|
||||||
boolean primary = (i == primaryIdx);
|
boolean primary = (i == primaryIdx);
|
||||||
Path path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve(String.valueOf(i));
|
Path path = createTempDir().resolve("indices").resolve(index.getUUID()).resolve(String.valueOf(i));
|
||||||
ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, primary,
|
ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, primary,
|
||||||
primary ? StoreRecoverySource.EMPTY_STORE_INSTANCE : PeerRecoverySource.INSTANCE,
|
primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : PeerRecoverySource.INSTANCE,
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null)
|
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null)
|
||||||
);
|
);
|
||||||
shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE);
|
||||||
|
|
|
@ -88,8 +88,8 @@ public class TestShardRouting {
|
||||||
case UNASSIGNED:
|
case UNASSIGNED:
|
||||||
case INITIALIZING:
|
case INITIALIZING:
|
||||||
if (primary) {
|
if (primary) {
|
||||||
return ESTestCase.randomFrom(RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE,
|
return ESTestCase.randomFrom(RecoverySource.EmptyStoreRecoverySource.INSTANCE,
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE);
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE);
|
||||||
} else {
|
} else {
|
||||||
return RecoverySource.PeerRecoverySource.INSTANCE;
|
return RecoverySource.PeerRecoverySource.INSTANCE;
|
||||||
}
|
}
|
||||||
|
@ -130,8 +130,8 @@ public class TestShardRouting {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RecoverySource randomRecoverySource() {
|
public static RecoverySource randomRecoverySource() {
|
||||||
return ESTestCase.randomFrom(RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE,
|
return ESTestCase.randomFrom(RecoverySource.EmptyStoreRecoverySource.INSTANCE,
|
||||||
RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE,
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE,
|
||||||
RecoverySource.PeerRecoverySource.INSTANCE,
|
RecoverySource.PeerRecoverySource.INSTANCE,
|
||||||
RecoverySource.LocalShardsRecoverySource.INSTANCE,
|
RecoverySource.LocalShardsRecoverySource.INSTANCE,
|
||||||
new RecoverySource.SnapshotRecoverySource(
|
new RecoverySource.SnapshotRecoverySource(
|
||||||
|
|
|
@ -172,7 +172,7 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase
|
||||||
|
|
||||||
private ShardRouting createShardRouting(String nodeId, boolean primary) {
|
private ShardRouting createShardRouting(String nodeId, boolean primary) {
|
||||||
return TestShardRouting.newShardRouting(shardId, nodeId, primary, ShardRoutingState.INITIALIZING,
|
return TestShardRouting.newShardRouting(shardId, nodeId, primary, ShardRoutingState.INITIALIZING,
|
||||||
primary ? RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE);
|
primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EngineFactory getEngineFactory(ShardRouting routing) {
|
protected EngineFactory getEngineFactory(ShardRouting routing) {
|
||||||
|
|
|
@ -193,7 +193,7 @@ public abstract class IndexShardTestCase extends ESTestCase {
|
||||||
*/
|
*/
|
||||||
protected IndexShard newShard(boolean primary, Settings settings, EngineFactory engineFactory) throws IOException {
|
protected IndexShard newShard(boolean primary, Settings settings, EngineFactory engineFactory) throws IOException {
|
||||||
final RecoverySource recoverySource =
|
final RecoverySource recoverySource =
|
||||||
primary ? RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE;
|
primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE;
|
||||||
final ShardRouting shardRouting =
|
final ShardRouting shardRouting =
|
||||||
TestShardRouting.newShardRouting(
|
TestShardRouting.newShardRouting(
|
||||||
new ShardId("index", "_na_", 0), randomAlphaOfLength(10), primary, ShardRoutingState.INITIALIZING, recoverySource);
|
new ShardId("index", "_na_", 0), randomAlphaOfLength(10), primary, ShardRoutingState.INITIALIZING, recoverySource);
|
||||||
|
@ -244,7 +244,7 @@ public abstract class IndexShardTestCase extends ESTestCase {
|
||||||
protected IndexShard newShard(ShardId shardId, boolean primary, IndexingOperationListener... listeners) throws IOException {
|
protected IndexShard newShard(ShardId shardId, boolean primary, IndexingOperationListener... listeners) throws IOException {
|
||||||
ShardRouting shardRouting = TestShardRouting.newShardRouting(shardId, randomAlphaOfLength(5), primary,
|
ShardRouting shardRouting = TestShardRouting.newShardRouting(shardId, randomAlphaOfLength(5), primary,
|
||||||
ShardRoutingState.INITIALIZING,
|
ShardRoutingState.INITIALIZING,
|
||||||
primary ? RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE);
|
primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE);
|
||||||
return newShard(shardRouting, Settings.EMPTY, new InternalEngineFactory(), listeners);
|
return newShard(shardRouting, Settings.EMPTY, new InternalEngineFactory(), listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ public abstract class IndexShardTestCase extends ESTestCase {
|
||||||
protected IndexShard newShard(ShardId shardId, boolean primary, String nodeId, IndexMetaData indexMetaData,
|
protected IndexShard newShard(ShardId shardId, boolean primary, String nodeId, IndexMetaData indexMetaData,
|
||||||
@Nullable IndexSearcherWrapper searcherWrapper, Runnable globalCheckpointSyncer) throws IOException {
|
@Nullable IndexSearcherWrapper searcherWrapper, Runnable globalCheckpointSyncer) throws IOException {
|
||||||
ShardRouting shardRouting = TestShardRouting.newShardRouting(shardId, nodeId, primary, ShardRoutingState.INITIALIZING,
|
ShardRouting shardRouting = TestShardRouting.newShardRouting(shardId, nodeId, primary, ShardRoutingState.INITIALIZING,
|
||||||
primary ? RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE);
|
primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE);
|
||||||
return newShard(shardRouting, indexMetaData, searcherWrapper, new InternalEngineFactory(), globalCheckpointSyncer);
|
return newShard(shardRouting, indexMetaData, searcherWrapper, new InternalEngineFactory(), globalCheckpointSyncer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ public abstract class IndexShardTestCase extends ESTestCase {
|
||||||
protected IndexShard reinitShard(IndexShard current, IndexingOperationListener... listeners) throws IOException {
|
protected IndexShard reinitShard(IndexShard current, IndexingOperationListener... listeners) throws IOException {
|
||||||
final ShardRouting shardRouting = current.routingEntry();
|
final ShardRouting shardRouting = current.routingEntry();
|
||||||
return reinitShard(current, ShardRoutingHelper.initWithSameId(shardRouting,
|
return reinitShard(current, ShardRoutingHelper.initWithSameId(shardRouting,
|
||||||
shardRouting.primary() ? RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE
|
shardRouting.primary() ? RecoverySource.ExistingStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE
|
||||||
), listeners);
|
), listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -532,7 +532,7 @@ public class TransportOpenJobActionTests extends ESTestCase {
|
||||||
} else {
|
} else {
|
||||||
Index index = new Index(indexToRemove, "_uuid");
|
Index index = new Index(indexToRemove, "_uuid");
|
||||||
ShardId shardId = new ShardId(index, 0);
|
ShardId shardId = new ShardId(index, 0);
|
||||||
ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, true, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE,
|
ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, true, RecoverySource.EmptyStoreRecoverySource.INSTANCE,
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
||||||
shardRouting = shardRouting.initialize("node_id", null, 0L);
|
shardRouting = shardRouting.initialize("node_id", null, 0L);
|
||||||
routingTable.add(IndexRoutingTable.builder(index)
|
routingTable.add(IndexRoutingTable.builder(index)
|
||||||
|
@ -656,7 +656,7 @@ public class TransportOpenJobActionTests extends ESTestCase {
|
||||||
metaData.put(indexMetaData);
|
metaData.put(indexMetaData);
|
||||||
Index index = new Index(indexName, "_uuid");
|
Index index = new Index(indexName, "_uuid");
|
||||||
ShardId shardId = new ShardId(index, 0);
|
ShardId shardId = new ShardId(index, 0);
|
||||||
ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, true, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE,
|
ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, true, RecoverySource.EmptyStoreRecoverySource.INSTANCE,
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
||||||
shardRouting = shardRouting.initialize("node_id", null, 0L);
|
shardRouting = shardRouting.initialize("node_id", null, 0L);
|
||||||
shardRouting = shardRouting.moveToStarted();
|
shardRouting = shardRouting.moveToStarted();
|
||||||
|
|
|
@ -349,7 +349,7 @@ public class DatafeedNodeSelectorTests extends ESTestCase {
|
||||||
true, ShardRoutingState.RELOCATING);
|
true, ShardRoutingState.RELOCATING);
|
||||||
} else {
|
} else {
|
||||||
shardRouting = ShardRouting.newUnassigned(shardId, true,
|
shardRouting = ShardRouting.newUnassigned(shardId, true,
|
||||||
RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE,
|
RecoverySource.EmptyStoreRecoverySource.INSTANCE,
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
@ -60,7 +61,6 @@ import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.singleton;
|
import static java.util.Collections.singleton;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE;
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
@ -289,7 +289,8 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
|
||||||
|
|
||||||
final ShardId shardId = new ShardId("_index", "_index_id", 7);
|
final ShardId shardId = new ShardId("_index", "_index_id", 7);
|
||||||
final UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "_message");
|
final UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "_message");
|
||||||
final ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, true, EXISTING_STORE_INSTANCE, unassignedInfo);
|
final ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, true,
|
||||||
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE, unassignedInfo);
|
||||||
|
|
||||||
final ShardStats mockShardStats = mock(ShardStats.class);
|
final ShardStats mockShardStats = mock(ShardStats.class);
|
||||||
when(mockShardStats.getShardRouting()).thenReturn(shardRouting);
|
when(mockShardStats.getShardRouting()).thenReturn(shardRouting);
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||||
|
@ -55,7 +56,6 @@ import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE;
|
|
||||||
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.SECURITY_INDEX_NAME;
|
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.SECURITY_INDEX_NAME;
|
||||||
import static org.hamcrest.Matchers.arrayContaining;
|
import static org.hamcrest.Matchers.arrayContaining;
|
||||||
import static org.hamcrest.Matchers.contains;
|
import static org.hamcrest.Matchers.contains;
|
||||||
|
@ -267,8 +267,8 @@ public class NativeRolesStoreTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
Index index = new Index(securityIndexName, UUID.randomUUID().toString());
|
Index index = new Index(securityIndexName, UUID.randomUUID().toString());
|
||||||
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, 0), true, EXISTING_STORE_INSTANCE,
|
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, 0), true,
|
||||||
new UnassignedInfo(Reason.INDEX_CREATED, ""));
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(Reason.INDEX_CREATED, ""));
|
||||||
IndexShardRoutingTable table = new IndexShardRoutingTable.Builder(new ShardId(index, 0))
|
IndexShardRoutingTable table = new IndexShardRoutingTable.Builder(new ShardId(index, 0))
|
||||||
.addShard(shardRouting.initialize(randomAlphaOfLength(8), null, shardRouting.getExpectedShardSize()).moveToStarted())
|
.addShard(shardRouting.initialize(randomAlphaOfLength(8), null, shardRouting.getExpectedShardSize()).moveToStarted())
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
||||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
||||||
|
import org.elasticsearch.cluster.routing.RecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||||
|
@ -50,7 +51,6 @@ import org.elasticsearch.xpack.core.template.TemplateUtils;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import static org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE;
|
|
||||||
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.SECURITY_INDEX_NAME;
|
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.SECURITY_INDEX_NAME;
|
||||||
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.SECURITY_TEMPLATE_NAME;
|
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.SECURITY_TEMPLATE_NAME;
|
||||||
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.TEMPLATE_VERSION_PATTERN;
|
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.TEMPLATE_VERSION_PATTERN;
|
||||||
|
@ -106,8 +106,8 @@ public class SecurityIndexManagerTests extends ESTestCase {
|
||||||
|
|
||||||
final ClusterState.Builder clusterStateBuilder = createClusterState(INDEX_NAME, TEMPLATE_NAME);
|
final ClusterState.Builder clusterStateBuilder = createClusterState(INDEX_NAME, TEMPLATE_NAME);
|
||||||
Index index = new Index(INDEX_NAME, UUID.randomUUID().toString());
|
Index index = new Index(INDEX_NAME, UUID.randomUUID().toString());
|
||||||
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, 0), true, EXISTING_STORE_INSTANCE,
|
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, 0), true,
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
||||||
String nodeId = ESTestCase.randomAlphaOfLength(8);
|
String nodeId = ESTestCase.randomAlphaOfLength(8);
|
||||||
IndexShardRoutingTable table = new IndexShardRoutingTable.Builder(new ShardId(index, 0))
|
IndexShardRoutingTable table = new IndexShardRoutingTable.Builder(new ShardId(index, 0))
|
||||||
.addShard(shardRouting.initialize(nodeId, null, shardRouting.getExpectedShardSize())
|
.addShard(shardRouting.initialize(nodeId, null, shardRouting.getExpectedShardSize())
|
||||||
|
@ -165,7 +165,8 @@ public class SecurityIndexManagerTests extends ESTestCase {
|
||||||
clusterStateBuilder.routingTable(RoutingTable.builder()
|
clusterStateBuilder.routingTable(RoutingTable.builder()
|
||||||
.add(IndexRoutingTable.builder(prevIndex)
|
.add(IndexRoutingTable.builder(prevIndex)
|
||||||
.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(prevIndex, 0))
|
.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(prevIndex, 0))
|
||||||
.addShard(ShardRouting.newUnassigned(new ShardId(prevIndex, 0), true, EXISTING_STORE_INSTANCE,
|
.addShard(ShardRouting.newUnassigned(new ShardId(prevIndex, 0), true,
|
||||||
|
RecoverySource.ExistingStoreRecoverySource.INSTANCE,
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""))
|
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""))
|
||||||
.initialize(UUIDs.randomBase64UUID(random()), null, 0L)
|
.initialize(UUIDs.randomBase64UUID(random()), null, 0L)
|
||||||
.moveToUnassigned(new UnassignedInfo(UnassignedInfo.Reason.ALLOCATION_FAILED, "")))
|
.moveToUnassigned(new UnassignedInfo(UnassignedInfo.Reason.ALLOCATION_FAILED, "")))
|
||||||
|
|
|
@ -5,21 +5,17 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.security.test;
|
package org.elasticsearch.xpack.security.test;
|
||||||
|
|
||||||
import org.elasticsearch.core.internal.io.IOUtils;
|
|
||||||
import org.elasticsearch.Version;
|
|
||||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
|
||||||
import org.elasticsearch.cluster.health.ClusterIndexHealth;
|
|
||||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.RecoverySource;
|
import org.elasticsearch.cluster.routing.RecoverySource.ExistingStoreRecoverySource;
|
||||||
import org.elasticsearch.cluster.routing.RoutingTable;
|
import org.elasticsearch.cluster.routing.RoutingTable;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
||||||
import org.elasticsearch.common.io.Streams;
|
import org.elasticsearch.common.io.Streams;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.core.internal.io.IOUtils;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.shard.ShardId;
|
import org.elasticsearch.index.shard.ShardId;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
@ -39,9 +35,7 @@ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||||
import static java.nio.file.StandardOpenOption.CREATE;
|
import static java.nio.file.StandardOpenOption.CREATE;
|
||||||
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
|
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
|
||||||
import static java.nio.file.StandardOpenOption.WRITE;
|
import static java.nio.file.StandardOpenOption.WRITE;
|
||||||
import static org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE;
|
|
||||||
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.SECURITY_INDEX_NAME;
|
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.SECURITY_INDEX_NAME;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class SecurityTestUtils {
|
public class SecurityTestUtils {
|
||||||
|
|
||||||
|
@ -74,7 +68,7 @@ public class SecurityTestUtils {
|
||||||
|
|
||||||
public static RoutingTable buildIndexRoutingTable(String indexName) {
|
public static RoutingTable buildIndexRoutingTable(String indexName) {
|
||||||
Index index = new Index(indexName, UUID.randomUUID().toString());
|
Index index = new Index(indexName, UUID.randomUUID().toString());
|
||||||
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, 0), true, EXISTING_STORE_INSTANCE,
|
ShardRouting shardRouting = ShardRouting.newUnassigned(new ShardId(index, 0), true, ExistingStoreRecoverySource.INSTANCE,
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""));
|
||||||
String nodeId = ESTestCase.randomAlphaOfLength(8);
|
String nodeId = ESTestCase.randomAlphaOfLength(8);
|
||||||
IndexShardRoutingTable table = new IndexShardRoutingTable.Builder(new ShardId(index, 0))
|
IndexShardRoutingTable table = new IndexShardRoutingTable.Builder(new ShardId(index, 0))
|
||||||
|
@ -95,60 +89,4 @@ public class SecurityTestUtils {
|
||||||
metaDataBuilder.put(IndexMetaData.builder(indexMetaData).putAlias(aliasMetaData));
|
metaDataBuilder.put(IndexMetaData.builder(indexMetaData).putAlias(aliasMetaData));
|
||||||
return metaDataBuilder.build();
|
return metaDataBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClusterIndexHealth getClusterIndexHealth(ClusterHealthStatus status) {
|
|
||||||
IndexMetaData metaData = IndexMetaData.builder("foo").settings(Settings.builder()
|
|
||||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
|
||||||
.build())
|
|
||||||
.build();
|
|
||||||
final IndexRoutingTable routingTable;
|
|
||||||
switch (status) {
|
|
||||||
case RED:
|
|
||||||
routingTable = IndexRoutingTable.builder(metaData.getIndex())
|
|
||||||
.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(metaData.getIndex(), 0))
|
|
||||||
.addShard(ShardRouting.newUnassigned(new ShardId(metaData.getIndex(), 0), true, EXISTING_STORE_INSTANCE,
|
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""))
|
|
||||||
.initialize(ESTestCase.randomAlphaOfLength(8), null, 0L))
|
|
||||||
.addShard(ShardRouting.newUnassigned(new ShardId(metaData.getIndex(), 0), false,
|
|
||||||
RecoverySource.PeerRecoverySource.INSTANCE,
|
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""))
|
|
||||||
.initialize(ESTestCase.randomAlphaOfLength(8), null, 0L))
|
|
||||||
.build())
|
|
||||||
.build();
|
|
||||||
break;
|
|
||||||
case YELLOW:
|
|
||||||
routingTable = IndexRoutingTable.builder(metaData.getIndex())
|
|
||||||
.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(metaData.getIndex(), 0))
|
|
||||||
.addShard(ShardRouting.newUnassigned(new ShardId(metaData.getIndex(), 0), true, EXISTING_STORE_INSTANCE,
|
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""))
|
|
||||||
.initialize(ESTestCase.randomAlphaOfLength(8), null, 0L).moveToStarted())
|
|
||||||
.addShard(ShardRouting.newUnassigned(new ShardId(metaData.getIndex(), 0), false,
|
|
||||||
RecoverySource.PeerRecoverySource.INSTANCE,
|
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""))
|
|
||||||
.initialize(ESTestCase.randomAlphaOfLength(8), null, 0L))
|
|
||||||
.build())
|
|
||||||
.build();
|
|
||||||
break;
|
|
||||||
case GREEN:
|
|
||||||
routingTable = IndexRoutingTable.builder(metaData.getIndex())
|
|
||||||
.addIndexShard(new IndexShardRoutingTable.Builder(new ShardId(metaData.getIndex(), 0))
|
|
||||||
.addShard(ShardRouting.newUnassigned(new ShardId(metaData.getIndex(), 0), true, EXISTING_STORE_INSTANCE,
|
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""))
|
|
||||||
.initialize(ESTestCase.randomAlphaOfLength(8), null, 0L).moveToStarted())
|
|
||||||
.addShard(ShardRouting.newUnassigned(new ShardId(metaData.getIndex(), 0), false,
|
|
||||||
RecoverySource.PeerRecoverySource.INSTANCE,
|
|
||||||
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""))
|
|
||||||
.initialize(ESTestCase.randomAlphaOfLength(8), null, 0L).moveToStarted())
|
|
||||||
.build())
|
|
||||||
.build();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("unknown status: " + status);
|
|
||||||
}
|
|
||||||
ClusterIndexHealth health = new ClusterIndexHealth(metaData, routingTable);
|
|
||||||
assertEquals(status, health.getStatus());
|
|
||||||
return health;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue