cleanup MetaData#Builder construction

have a better method name, and only allow to create a copy of the builder based on existing meta data when constructing the builder
This commit is contained in:
Shay Banon 2013-11-02 01:04:33 +01:00
parent acc5f584d4
commit d111e169a4
50 changed files with 341 additions and 409 deletions

View File

@ -225,7 +225,7 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOpe
return currentState;
}
MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData())
MetaData.Builder metaData = MetaData.builder(currentState.metaData())
.persistentSettings(persistentSettings.build())
.transientSettings(transientSettings.build());

View File

@ -34,7 +34,6 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
/**
*
@ -93,9 +92,11 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct
builder.blocks(currentState.blocks());
}
if (!request.filterMetaData()) {
MetaData.Builder mdBuilder = newMetaDataBuilder();
MetaData.Builder mdBuilder;
if (request.filteredIndices().length == 0 && request.filteredIndexTemplates().length == 0) {
mdBuilder.metaData(currentState.metaData());
mdBuilder = MetaData.builder(currentState.metaData());
} else {
mdBuilder = MetaData.builder();
}
if (request.filteredIndices().length > 0) {

View File

@ -125,7 +125,7 @@ public class TransportDeleteWarmerAction extends TransportMasterNodeOperationAct
@Override
public ClusterState execute(ClusterState currentState) {
MetaData.Builder mdBuilder = MetaData.builder().metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
boolean globalFoundAtLeastOne = false;
for (String index : request.indices()) {

View File

@ -144,7 +144,7 @@ public class TransportPutWarmerAction extends TransportMasterNodeOperationAction
}
// now replace it on the metadata
MetaData.Builder mdBuilder = MetaData.builder().metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
for (String index : concreteIndices) {
IndexMetaData indexMetaData = metaData.index(index);

View File

@ -99,7 +99,7 @@ public class MetaData implements Iterable<IndexMetaData> {
public static final ClusterBlock CLUSTER_READ_ONLY_BLOCK = new ClusterBlock(6, "cluster read-only (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA);
public static final MetaData EMPTY_META_DATA = newMetaDataBuilder().build();
public static final MetaData EMPTY_META_DATA = builder().build();
private final long version;
@ -920,9 +920,8 @@ public class MetaData implements Iterable<IndexMetaData> {
return new Builder();
}
public static Builder newMetaDataBuilder() {
return new Builder();
public static Builder builder(MetaData metaData) {
return new Builder(metaData);
}
public static class Builder {
@ -933,19 +932,20 @@ public class MetaData implements Iterable<IndexMetaData> {
private Settings persistentSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
private MapBuilder<String, IndexMetaData> indices = newMapBuilder();
private MapBuilder<String, IndexTemplateMetaData> templates = newMapBuilder();
private MapBuilder<String, Custom> customs = newMapBuilder();
public Builder metaData(MetaData metaData) {
public Builder() {
}
public Builder(MetaData metaData) {
this.transientSettings = metaData.transientSettings;
this.persistentSettings = metaData.persistentSettings;
this.version = metaData.version;
this.indices.putAll(metaData.indices);
this.templates.putAll(metaData.templates);
this.customs.putAll(metaData.customs);
return this;
}
public Builder put(IndexMetaData.Builder indexMetaDataBuilder) {

View File

@ -76,7 +76,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.*;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
/**
@ -311,8 +310,7 @@ public class MetaDataCreateIndexService extends AbstractComponent {
throw e;
}
MetaData newMetaData = newMetaDataBuilder()
.metaData(currentState.metaData())
MetaData newMetaData = MetaData.builder(currentState.metaData())
.put(indexMetaData, false)
.build();

View File

@ -44,7 +44,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
/**
*
@ -126,8 +125,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());
routingTableBuilder.remove(request.index);
MetaData newMetaData = newMetaDataBuilder()
.metaData(currentState.metaData())
MetaData newMetaData = MetaData.builder(currentState.metaData())
.remove(request.index)
.build();

View File

@ -48,7 +48,6 @@ import java.util.Map;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
/**
*
@ -103,7 +102,7 @@ public class MetaDataIndexAliasesService extends AbstractComponent {
}
boolean changed = false;
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder builder = MetaData.builder(currentState.metaData());
for (AliasAction aliasAction : request.actions) {
IndexMetaData indexMetaData = builder.get(aliasAction.index());
if (indexMetaData == null) {

View File

@ -113,8 +113,7 @@ public class MetaDataIndexStateService extends AbstractComponent {
logger.info("closing indices [{}]", indicesAsString);
MetaData.Builder mdBuilder = MetaData.builder()
.metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder()
.blocks(currentState.blocks());
for (String index : indicesToClose) {
@ -185,8 +184,7 @@ public class MetaDataIndexStateService extends AbstractComponent {
logger.info("opening indices [{}]", indicesAsString);
MetaData.Builder mdBuilder = MetaData.builder()
.metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder()
.blocks(currentState.blocks());
for (String index : indicesToOpen) {

View File

@ -85,7 +85,7 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
}
throw new IndexTemplateMissingException(request.name);
}
MetaData.Builder metaData = MetaData.builder().metaData(currentState.metaData());
MetaData.Builder metaData = MetaData.builder(currentState.metaData());
for (String templateName : templateNames) {
metaData.removeTemplate(templateName);
}
@ -161,8 +161,7 @@ public class MetaDataIndexTemplateService extends AbstractComponent {
if (request.create && currentState.metaData().templates().containsKey(request.name)) {
throw new IndexTemplateAlreadyExistsException(request.name);
}
MetaData.Builder builder = MetaData.builder().metaData(currentState.metaData())
.put(template);
MetaData.Builder builder = MetaData.builder(currentState.metaData()).put(template);
return ClusterState.builder().state(currentState).metaData(builder).build();
}

View File

@ -56,7 +56,6 @@ import java.util.concurrent.BlockingQueue;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.index.mapper.DocumentMapper.MergeFlags.mergeFlags;
/**
@ -142,7 +141,7 @@ public class MetaDataMappingService extends AbstractComponent {
}
boolean dirty = false;
MetaData.Builder mdBuilder = newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
for (Map.Entry<String, List<MappingTask>> entry : tasksPerIndex.entrySet()) {
String index = entry.getKey();
List<MappingTask> tasks = entry.getValue();
@ -334,7 +333,7 @@ public class MetaDataMappingService extends AbstractComponent {
throw new IndexMissingException(new Index("_all"));
}
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder builder = MetaData.builder(currentState.metaData());
boolean changed = false;
String latestIndexWithout = null;
for (String indexName : request.indices()) {
@ -492,7 +491,7 @@ public class MetaDataMappingService extends AbstractComponent {
return currentState;
}
MetaData.Builder builder = newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder builder = MetaData.builder(currentState.metaData());
for (String indexName : request.indices) {
IndexMetaData indexMetaData = currentState.metaData().index(indexName);
if (indexMetaData == null) {

View File

@ -232,7 +232,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
public ClusterState execute(ClusterState currentState) {
String[] actualIndices = currentState.metaData().concreteIndices(request.indices());
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());
MetaData.Builder metaDataBuilder = MetaData.newMetaDataBuilder().metaData(currentState.metaData());
MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData());
// allow to change any settings to a close index, and only allow dynamic settings to be changed
// on an open index

View File

@ -330,7 +330,7 @@ public class InternalClusterService extends AbstractLifecycleComponent<ClusterSe
builder.routingTable(RoutingTable.builder().routingTable(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1));
}
if (previousClusterState.metaData() != newClusterState.metaData()) {
builder.metaData(MetaData.builder().metaData(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
}
newClusterState = builder.build();
@ -356,7 +356,7 @@ public class InternalClusterService extends AbstractLifecycleComponent<ClusterSe
// have a fresh instances of routing and metadata to remove the chance that version might be the same
Builder builder = ClusterState.builder().state(newClusterState);
builder.routingTable(RoutingTable.builder().routingTable(newClusterState.routingTable()));
builder.metaData(MetaData.builder().metaData(newClusterState.metaData()));
builder.metaData(MetaData.builder(newClusterState.metaData()));
newClusterState = builder.build();
logger.debug("got first state from fresh master [{}]", newClusterState.nodes().masterNodeId());
} else if (newClusterState.version() < previousClusterState.version()) {

View File

@ -601,7 +601,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
builder.metaData(currentState.metaData());
} else {
// if its not the same version, only copy over new indices or ones that changed the version
MetaData.Builder metaDataBuilder = MetaData.builder().metaData(newState.metaData()).removeAllIndices();
MetaData.Builder metaDataBuilder = MetaData.builder(newState.metaData()).removeAllIndices();
for (IndexMetaData indexMetaData : newState.metaData()) {
IndexMetaData currentIndexMetaData = currentState.metaData().index(indexMetaData.index());
if (currentIndexMetaData == null || currentIndexMetaData.version() != indexMetaData.version()) {

View File

@ -43,7 +43,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
/**
*
@ -248,8 +247,7 @@ public class GatewayService extends AbstractLifecycleComponent<GatewayService> i
.blocks(recoveredState.blocks())
.removeGlobalBlock(STATE_NOT_RECOVERED_BLOCK);
MetaData.Builder metaDataBuilder = newMetaDataBuilder()
.metaData(recoveredState.metaData());
MetaData.Builder metaDataBuilder = MetaData.builder(recoveredState.metaData());
if (recoveredState.metaData().settings().getAsBoolean(MetaData.SETTING_READ_ONLY, false) || currentState.metaData().settings().getAsBoolean(MetaData.SETTING_READ_ONLY, false)) {
blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK);

View File

@ -135,7 +135,6 @@ public class LocalGateway extends AbstractLifecycleComponent<Gateway> implements
}
}
MetaData.Builder metaDataBuilder = MetaData.builder();
ObjectFloatOpenHashMap<String> indices = new ObjectFloatOpenHashMap<String>();
MetaData electedGlobalState = null;
int found = 0;
@ -158,7 +157,7 @@ public class LocalGateway extends AbstractLifecycleComponent<Gateway> implements
return;
}
// update the global state, and clean the indices, we elect them in the next phase
metaDataBuilder.metaData(electedGlobalState).removeAllIndices();
MetaData.Builder metaDataBuilder = MetaData.builder(electedGlobalState).removeAllIndices();
final boolean[] states = indices.allocated;
final Object[] keys = indices.keys;
for (int i = 0; i < states.length; i++) {

View File

@ -120,8 +120,7 @@ public class LocalAllocateDangledIndices extends AbstractComponent {
if (currentState.blocks().disableStatePersistence()) {
return currentState;
}
MetaData.Builder metaData = MetaData.builder()
.metaData(currentState.metaData());
MetaData.Builder metaData = MetaData.builder(currentState.metaData());
ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
RoutingTable.Builder routingTableBuilder = RoutingTable.builder().routingTable(currentState.routingTable());

View File

@ -387,7 +387,7 @@ public class LocalGatewayMetaState extends AbstractComponent implements ClusterS
private void writeGlobalState(String reason, MetaData metaData, @Nullable MetaData previousMetaData) throws Exception {
logger.trace("[_global] writing state, reason [{}]", reason);
// create metadata to write with just the global state
MetaData globalMetaData = MetaData.builder().metaData(metaData).removeAllIndices().build();
MetaData globalMetaData = MetaData.builder(metaData).removeAllIndices().build();
XContentBuilder builder = XContentFactory.contentBuilder(format);
builder.startObject();
@ -442,10 +442,12 @@ public class LocalGatewayMetaState extends AbstractComponent implements ClusterS
}
private MetaData loadState() throws Exception {
MetaData.Builder metaDataBuilder = MetaData.builder();
MetaData globalMetaData = loadGlobalState();
MetaData.Builder metaDataBuilder;
if (globalMetaData != null) {
metaDataBuilder.metaData(globalMetaData);
metaDataBuilder = MetaData.builder(globalMetaData);
} else {
metaDataBuilder = MetaData.builder();
}
Set<String> indices = nodeEnv.findAllIndices();
@ -618,7 +620,7 @@ public class LocalGatewayMetaState extends AbstractComponent implements ClusterS
logger.info("found old metadata state, loading metadata from [{}] and converting to new metadata location and strucutre...", metaDataFile.getAbsolutePath());
writeGlobalState("upgrade", MetaData.builder().metaData(metaData).version(version).build(), null);
writeGlobalState("upgrade", MetaData.builder(metaData).version(version).build(), null);
for (IndexMetaData indexMetaData : metaData) {
IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.newIndexMetaDataBuilder(indexMetaData).version(version);
// set the created version to 0.18

View File

@ -28,9 +28,7 @@ import java.io.IOException;
import static org.elasticsearch.cluster.metadata.AliasMetaData.newAliasMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -41,7 +39,7 @@ public class ToAndFromJsonMetaDataTests extends ElasticsearchTestCase {
@Test
public void testSimpleJsonFromAndTo() throws IOException {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1")
.numberOfShards(1)
.numberOfReplicas(2))

View File

@ -19,14 +19,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
public class AddIncrementallyTests extends ElasticsearchTestCase {
private final ESLogger logger = Loggers.getLogger(AddIncrementallyTests.class);
@ -53,7 +51,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertAtLeastOneIndexShardPerNode(clusterState);
clusterState = removeNodes(clusterState, service, 1);
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
clusterState = addIndex(clusterState, service, 3, 2, 3);
assertThat(clusterState.routingNodes().getUnassigned().size(), Matchers.equalTo(2));
assertNumIndexShardsPerNode(clusterState, "test3", Matchers.equalTo(2));
@ -74,12 +72,12 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().getUnassigned().size(), Matchers.equalTo(0));
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
}
@Test
public void testMinimalRelocations() {
ImmutableSettings.Builder settings = settingsBuilder();
settings.put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString())
.put("cluster.routing.allocation.node_concurrent_recoveries", 2);
.put("cluster.routing.allocation.node_concurrent_recoveries", 2);
AllocationService service = new AllocationService(settings.build());
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
@ -91,10 +89,10 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().node("node1").shardsWithState(STARTED).size(), Matchers.equalTo(9));
assertThat(clusterState.routingNodes().getUnassigned().size(), Matchers.equalTo(0));
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(3));
logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
DiscoveryNodes.Builder nodes = newNodesBuilder().putAll(clusterState.nodes());
nodes.put(newNode("node2"));
nodes.put(newNode("node2"));
clusterState = newClusterStateBuilder().state(clusterState).nodes(nodes.build()).build();
RoutingTable routingTable = service.reroute(clusterState).routingTable();
@ -115,7 +113,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(clusterState.routingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(prev, Matchers.not(Matchers.sameInstance(routingTable)));
prev = routingTable;
routingTable = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
@ -125,7 +123,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(clusterState.routingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(prev, Matchers.not(Matchers.sameInstance(routingTable)));
prev = routingTable;
routingTable = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
@ -135,7 +133,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(clusterState.routingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(prev, Matchers.not(Matchers.sameInstance(routingTable)));
prev = routingTable;
routingTable = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
@ -144,13 +142,13 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
}
@Test
public void testMinimalRelocationsNoLimit() {
ImmutableSettings.Builder settings = settingsBuilder();
settings.put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString())
.put("cluster.routing.allocation.node_concurrent_recoveries", 100)
.put("cluster.routing.allocation.node_initial_primaries_recoveries", 100);
.put("cluster.routing.allocation.node_concurrent_recoveries", 100)
.put("cluster.routing.allocation.node_initial_primaries_recoveries", 100);
AllocationService service = new AllocationService(settings.build());
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
@ -162,10 +160,10 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().node("node1").shardsWithState(STARTED).size(), Matchers.equalTo(9));
assertThat(clusterState.routingNodes().getUnassigned().size(), Matchers.equalTo(0));
assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(3));
logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
DiscoveryNodes.Builder nodes = newNodesBuilder().putAll(clusterState.nodes());
nodes.put(newNode("node2"));
nodes.put(newNode("node2"));
clusterState = newClusterStateBuilder().state(clusterState).nodes(nodes.build()).build();
RoutingTable routingTable = service.reroute(clusterState).routingTable();
@ -186,7 +184,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(clusterState.routingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(prev, Matchers.not(Matchers.sameInstance(routingTable)));
prev = routingTable;
routingTable = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
@ -196,7 +194,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(clusterState.routingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(prev, Matchers.not(Matchers.sameInstance(routingTable)));
prev = routingTable;
routingTable = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
@ -206,7 +204,7 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(clusterState.routingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
assertThat(prev, Matchers.not(Matchers.sameInstance(routingTable)));
prev = routingTable;
routingTable = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
@ -222,14 +220,14 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
assertNumIndexShardsPerNode(state, index, matcher);
}
}
private void assertNumIndexShardsPerNode(ClusterState state, String index, Matcher<Integer> matcher) {
for (RoutingNode node : state.routingNodes()) {
assertThat(node.shardsWithState(index, STARTED).size(), matcher);
}
}
private void assertAtLeastOneIndexShardPerNode(ClusterState state) {
for (String index : state.routingTable().indicesRouting().keySet()) {
@ -270,8 +268,8 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
}
private ClusterState initCluster(AllocationService service, int numberOfNodes, int numberOfIndices, int numberOfShards,
int numberOfReplicas) {
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
int numberOfReplicas) {
MetaData.Builder metaDataBuilder = MetaData.builder();
RoutingTable.Builder routingTableBuilder = routingTable();
for (int i = 0; i < numberOfIndices; i++) {
@ -323,16 +321,16 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
return clusterState;
}
private ClusterState addIndex(ClusterState clusterState, AllocationService service, int indexOrdinal, int numberOfShards,
int numberOfReplicas) {
MetaData.Builder metaDataBuilder = newMetaDataBuilder().metaData(clusterState.getMetaData());
int numberOfReplicas) {
MetaData.Builder metaDataBuilder = MetaData.builder(clusterState.getMetaData());
RoutingTable.Builder routingTableBuilder = routingTable().routingTable(clusterState.routingTable());
IndexMetaData.Builder index = newIndexMetaDataBuilder("test" + indexOrdinal).numberOfShards(numberOfShards).numberOfReplicas(
numberOfReplicas);
metaDataBuilder = metaDataBuilder.put(index);
routingTableBuilder.addAsNew(index.build());
IndexMetaData.Builder index = newIndexMetaDataBuilder("test" + indexOrdinal).numberOfShards(numberOfShards).numberOfReplicas(
numberOfReplicas);
metaDataBuilder = metaDataBuilder.put(index);
routingTableBuilder.addAsNew(index.build());
MetaData metaData = metaDataBuilder.build();
RoutingTable routingTable = routingTableBuilder.build();
@ -366,11 +364,11 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
return clusterState;
}
private ClusterState removeNodes(ClusterState clusterState, AllocationService service, int numNodes) {
logger.info("Removing [{}] nodes", numNodes);
DiscoveryNodes.Builder nodes = newNodesBuilder().putAll(clusterState.nodes());
for (DiscoveryNode node : clusterState.nodes()) {
nodes.remove(node.id());
numNodes--;
@ -399,15 +397,15 @@ public class AddIncrementallyTests extends ElasticsearchTestCase {
logger.info("complete rebalancing");
RoutingTable prev = routingTable;
while(true) {
while (true) {
routingTable = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
if (routingTable == prev)
if (routingTable == prev)
break;
prev = routingTable;
}
return clusterState;
}
}

View File

@ -29,13 +29,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -49,7 +47,7 @@ public class AllocatePostApiFlagTests extends ElasticsearchTestCase {
AllocationService allocation = new AllocationService(settingsBuilder().put("cluster.routing.allocation.concurrent_recoveries", 10).build());
logger.info("creating an index with 1 shard, no replica");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
RoutingTable routingTable = routingTable()

View File

@ -42,14 +42,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -63,7 +61,7 @@ public class AllocationCommandsTests extends ElasticsearchTestCase {
AllocationService allocation = new AllocationService(settingsBuilder().put("cluster.routing.allocation.concurrent_recoveries", 10).build());
logger.info("creating an index with 1 shard, no replica");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
RoutingTable routingTable = routingTable()
@ -110,7 +108,7 @@ public class AllocationCommandsTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()
@ -191,7 +189,7 @@ public class AllocationCommandsTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()

View File

@ -32,7 +32,6 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
@ -56,7 +55,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded1'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -125,7 +124,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded2'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -200,7 +199,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded3'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();
@ -298,7 +297,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded4'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(5).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(5).numberOfReplicas(1))
.build();
@ -381,6 +380,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("--> do another reroute, make sure nothing moves");
assertThat(strategy.reroute(clusterState).routingTable(), sameInstance(clusterState.routingTable()));
}
@Test
public void moveShardOnceNewNodeWithAttributeAdded5() {
AllocationService strategy = new AllocationService(settingsBuilder()
@ -391,7 +391,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded5'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(2))
.build();
@ -470,7 +470,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'moveShardOnceNewNodeWithAttributeAdded6'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(3))
.build();
@ -552,7 +552,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'fullAwareness1'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -620,7 +620,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'fullAwareness2'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -694,7 +694,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'fullAwareness3'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(5).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(5).numberOfReplicas(1))
.build();
@ -762,7 +762,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("--> do another reroute, make sure nothing moves");
assertThat(strategy.reroute(clusterState).routingTable(), sameInstance(clusterState.routingTable()));
}
@Test
public void testUnbalancedZones() {
AllocationService strategy = new AllocationService(settingsBuilder()
@ -776,7 +776,7 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table for 'testUnbalancedZones'");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();
@ -817,11 +817,11 @@ public class AwarenessAllocationTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(8));
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(2));
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("A-1"));
logger.info("--> starting inizializing shards on the new node");
logger.info("--> starting initializing shards on the new node");
routingTable = strategy.applyStartedShards(clusterState, clusterState.routingNodes().shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
assertThat(clusterState.getRoutingNodes().node("A-1").shards().size(), equalTo(2));
assertThat(clusterState.getRoutingNodes().node("A-0").shards().size(), equalTo(3));

View File

@ -44,14 +44,12 @@ import java.util.List;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
public class BalanceConfigurationTests extends ElasticsearchTestCase {
@ -61,7 +59,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
final int numberOfIndices = 12;
final int numberOfShards = 2;
final int numberOfReplicas = 2;
@Test
public void testIndexBalance() {
/* Tests balance over indices only */
@ -76,20 +74,20 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
settings.put(BalancedShardsAllocator.SETTING_SHARD_BALANCE_FACTOR, replicaBalance);
settings.put(BalancedShardsAllocator.SETTING_PRIMARY_BALANCE_FACTOR, primaryBalance);
settings.put(BalancedShardsAllocator.SETTING_THRESHOLD, balanceTreshold);
AllocationService strategy = new AllocationService(settings.build());
ClusterState clusterState = initCluster(strategy);
assertIndexBalance(logger, clusterState.getRoutingNodes(), numberOfNodes, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterState = addNode(clusterState, strategy);
assertIndexBalance(logger, clusterState.getRoutingNodes(), numberOfNodes+1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertIndexBalance(logger, clusterState.getRoutingNodes(), numberOfNodes + 1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterState = removeNodes(clusterState, strategy);
assertIndexBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes+1)-(numberOfNodes+1)/2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertIndexBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes + 1) - (numberOfNodes + 1) / 2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
}
@Test
public void testReplicaBalance() {
/* Tests balance over replicas only */
@ -97,27 +95,27 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
final float replicaBalance = 1.0f;
final float primaryBalance = 0.0f;
final float balanceTreshold = 1.0f;
ImmutableSettings.Builder settings = settingsBuilder();
settings.put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString());
settings.put(BalancedShardsAllocator.SETTING_INDEX_BALANCE_FACTOR, indexBalance);
settings.put(BalancedShardsAllocator.SETTING_SHARD_BALANCE_FACTOR, replicaBalance);
settings.put(BalancedShardsAllocator.SETTING_PRIMARY_BALANCE_FACTOR, primaryBalance);
settings.put(BalancedShardsAllocator.SETTING_THRESHOLD, balanceTreshold);
AllocationService strategy = new AllocationService(settings.build());
ClusterState clusterState = initCluster(strategy);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), numberOfNodes, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterState = addNode(clusterState, strategy);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), numberOfNodes+1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), numberOfNodes + 1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterState = removeNodes(clusterState, strategy);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes+1)-(numberOfNodes+1)/2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes + 1) - (numberOfNodes + 1) / 2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
}
@Test
public void testPrimaryBalance() {
/* Tests balance over primaries only */
@ -125,48 +123,48 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
final float replicaBalance = 0.0f;
final float primaryBalance = 1.0f;
final float balanceTreshold = 1.0f;
ImmutableSettings.Builder settings = settingsBuilder();
settings.put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString());
settings.put(BalancedShardsAllocator.SETTING_INDEX_BALANCE_FACTOR, indexBalance);
settings.put(BalancedShardsAllocator.SETTING_SHARD_BALANCE_FACTOR, replicaBalance);
settings.put(BalancedShardsAllocator.SETTING_PRIMARY_BALANCE_FACTOR, primaryBalance);
settings.put(BalancedShardsAllocator.SETTING_THRESHOLD, balanceTreshold);
AllocationService strategy = new AllocationService(settings.build());
ClusterState clusterstate = initCluster(strategy);
ClusterState clusterstate = initCluster(strategy);
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterstate = addNode(clusterstate, strategy);
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes+1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes + 1, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
clusterstate = removeNodes(clusterstate, strategy);
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes+1-(numberOfNodes+1)/2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
}
assertPrimaryBalance(logger, clusterstate.getRoutingNodes(), numberOfNodes + 1 - (numberOfNodes + 1) / 2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
}
private ClusterState initCluster(AllocationService strategy) {
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
MetaData.Builder metaDataBuilder = MetaData.builder();
RoutingTable.Builder routingTableBuilder = routingTable();
for (int i = 0; i < numberOfIndices; i++) {
IndexMetaData.Builder index = newIndexMetaDataBuilder("test"+i).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas);
IndexMetaData.Builder index = newIndexMetaDataBuilder("test" + i).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas);
metaDataBuilder = metaDataBuilder.put(index);
}
MetaData metaData = metaDataBuilder.build();
for (IndexMetaData index : metaData.indices().values()) {
routingTableBuilder.addAsNew(index);
}
RoutingTable routingTable = routingTableBuilder.build();
logger.info("start "+numberOfNodes+" nodes");
logger.info("start " + numberOfNodes + " nodes");
DiscoveryNodes.Builder nodes = newNodesBuilder();
for (int i = 0; i < numberOfNodes; i++) {
nodes.put(newNode("node"+i));
nodes.put(newNode("node" + i));
}
ClusterState clusterState = newClusterStateBuilder().nodes(nodes).metaData(metaData).routingTable(routingTable).build();
routingTable = strategy.reroute(clusterState).routingTable();
@ -184,25 +182,25 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
routingTable = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
logger.info("complete rebalancing");
RoutingTable prev = routingTable;
while(true) {
while (true) {
routingTable = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
if (routingTable == prev)
if (routingTable == prev)
break;
prev = routingTable;
}
return clusterState;
}
private ClusterState addNode(ClusterState clusterState, AllocationService strategy) {
logger.info("now, start 1 more node, check that rebalancing will happen because we set it to always");
clusterState = newClusterStateBuilder().state(clusterState).nodes(newNodesBuilder().putAll(clusterState.nodes())
.put(newNode("node"+numberOfNodes)))
.put(newNode("node" + numberOfNodes)))
.build();
RoutingTable routingTable = strategy.reroute(clusterState).routingTable();
@ -210,26 +208,26 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
RoutingNodes routingNodes = clusterState.routingNodes();
// move initializing to started
RoutingTable prev = routingTable;
while(true) {
while (true) {
routingTable = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
if (routingTable == prev)
if (routingTable == prev)
break;
prev = routingTable;
}
return clusterState;
}
private ClusterState removeNodes(ClusterState clusterState, AllocationService strategy) {
logger.info("Removing half the nodes ("+(numberOfNodes+1)/2+")");
logger.info("Removing half the nodes (" + (numberOfNodes + 1) / 2 + ")");
DiscoveryNodes.Builder nodes = newNodesBuilder().putAll(clusterState.nodes());
for(int i=(numberOfNodes+1)/2; i<=numberOfNodes; i++){
nodes.remove("node"+i);
for (int i = (numberOfNodes + 1) / 2; i <= numberOfNodes; i++) {
nodes.remove("node" + i);
}
clusterState = newClusterStateBuilder().state(clusterState).nodes(nodes.build()).build();
@ -252,25 +250,25 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
logger.info("complete rebalancing");
RoutingTable prev = routingTable;
while(true) {
while (true) {
routingTable = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
if (routingTable == prev)
if (routingTable == prev)
break;
prev = routingTable;
}
return clusterState;
}
private void assertReplicaBalance(ESLogger logger, RoutingNodes nodes, int numberOfNodes, int numberOfIndices, int numberOfReplicas, int numberOfShards, float treshold) {
final int numShards = numberOfIndices * numberOfShards * (numberOfReplicas+1);
final float avgNumShards = (float)(numShards) / (float)(numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards-treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards+treshold)));
final int numShards = numberOfIndices * numberOfShards * (numberOfReplicas + 1);
final float avgNumShards = (float) (numShards) / (float) (numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards - treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards + treshold)));
for (RoutingNode node : nodes) {
// logger.info(node.nodeId() + ": " + node.shardsWithState(INITIALIZING, STARTED).size() + " shards ("+minAvgNumberOfShards+" to "+maxAvgNumberOfShards+")");
assertThat(node.shardsWithState(STARTED).size(), Matchers.greaterThanOrEqualTo(minAvgNumberOfShards));
@ -279,13 +277,13 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
}
private void assertIndexBalance(ESLogger logger, RoutingNodes nodes, int numberOfNodes, int numberOfIndices, int numberOfReplicas, int numberOfShards, float treshold) {
final int numShards = numberOfShards * (numberOfReplicas+1);
final float avgNumShards = (float)(numShards) / (float)(numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards-treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards+treshold)));
for(String index : nodes.getRoutingTable().indicesRouting().keySet()) {
final int numShards = numberOfShards * (numberOfReplicas + 1);
final float avgNumShards = (float) (numShards) / (float) (numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards - treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards + treshold)));
for (String index : nodes.getRoutingTable().indicesRouting().keySet()) {
for (RoutingNode node : nodes) {
// logger.info(node.nodeId() +":"+index+ ": " + node.shardsWithState(index, INITIALIZING, STARTED).size() + " shards ("+minAvgNumberOfShards+" to "+maxAvgNumberOfShards+")");
assertThat(node.shardsWithState(index, STARTED).size(), Matchers.greaterThanOrEqualTo(minAvgNumberOfShards));
@ -293,19 +291,19 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
}
}
}
private void assertPrimaryBalance(ESLogger logger, RoutingNodes nodes, int numberOfNodes, int numberOfIndices, int numberOfReplicas, int numberOfShards, float treshold) {
final int numShards = numberOfShards;
final float avgNumShards = (float)(numShards) / (float)(numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards-treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards+treshold)));
for(String index : nodes.getRoutingTable().indicesRouting().keySet()) {
private void assertPrimaryBalance(ESLogger logger, RoutingNodes nodes, int numberOfNodes, int numberOfIndices, int numberOfReplicas, int numberOfShards, float treshold) {
final int numShards = numberOfShards;
final float avgNumShards = (float) (numShards) / (float) (numberOfNodes);
final int minAvgNumberOfShards = Math.round(Math.round(Math.floor(avgNumShards - treshold)));
final int maxAvgNumberOfShards = Math.round(Math.round(Math.ceil(avgNumShards + treshold)));
for (String index : nodes.getRoutingTable().indicesRouting().keySet()) {
for (RoutingNode node : nodes) {
int primaries = 0;
for(ShardRouting shard : node.shardsWithState(index, STARTED)) {
primaries += shard.primary()?1:0;
for (ShardRouting shard : node.shardsWithState(index, STARTED)) {
primaries += shard.primary() ? 1 : 0;
}
// logger.info(node.nodeId() + ": " + primaries + " primaries ("+minAvgNumberOfShards+" to "+maxAvgNumberOfShards+")");
assertThat(primaries, Matchers.greaterThanOrEqualTo(minAvgNumberOfShards));
@ -313,7 +311,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
}
}
}
@Test
public void testPersistedSettings() {
ImmutableSettings.Builder settings = settingsBuilder();
@ -327,16 +325,16 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
@Override
public void addListener(Listener listener) {
assert listeners[0] == null;
listeners[0] = listener;
listeners[0] = listener;
}
};
BalancedShardsAllocator allocator = new BalancedShardsAllocator(settings.build(), service);
assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.2f));
assertThat(allocator.getShardBalance(), Matchers.equalTo(0.3f));
assertThat(allocator.getPrimaryBalance(), Matchers.equalTo(0.5f));
assertThat(allocator.getThreshold(), Matchers.equalTo(2.0f));
settings = settingsBuilder();
settings.put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString());
listeners[0].onRefreshSettings(settings.build());
@ -344,7 +342,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
assertThat(allocator.getShardBalance(), Matchers.equalTo(0.3f));
assertThat(allocator.getPrimaryBalance(), Matchers.equalTo(0.5f));
assertThat(allocator.getThreshold(), Matchers.equalTo(2.0f));
settings = settingsBuilder();
settings.put(BalancedShardsAllocator.SETTING_INDEX_BALANCE_FACTOR, 0.5);
settings.put(BalancedShardsAllocator.SETTING_SHARD_BALANCE_FACTOR, 0.1);
@ -356,7 +354,7 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
assertThat(allocator.getPrimaryBalance(), Matchers.equalTo(0.4f));
assertThat(allocator.getThreshold(), Matchers.equalTo(3.0f));
}
@Test
public void testNoRebalanceOnPrimaryOverload() {
@ -365,96 +363,96 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
new NodeSettingsService(ImmutableSettings.Builder.EMPTY_SETTINGS)), new ShardsAllocators(settings.build(),
new NoneGatewayAllocator(), new ShardsAllocator() {
@Override
public boolean rebalance(RoutingAllocation allocation) {
return false;
}
@Override
public boolean rebalance(RoutingAllocation allocation) {
return false;
}
@Override
public boolean move(MutableShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
return false;
}
@Override
public boolean move(MutableShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
return false;
}
@Override
public void applyStartedShards(StartedRerouteAllocation allocation) {
}
@Override
public void applyStartedShards(StartedRerouteAllocation allocation) {
@Override
public void applyFailedShards(FailedRerouteAllocation allocation) {
}
/*
* // this allocator tries to rebuild this scenario where a rebalance is
* // triggered solely by the primary overload on node [1] where a shard
* // is rebalanced to node 0
routing_nodes:
-----node_id[0][V]
--------[test][0], node[0], [R], s[STARTED]
--------[test][4], node[0], [R], s[STARTED]
-----node_id[1][V]
--------[test][0], node[1], [P], s[STARTED]
--------[test][1], node[1], [P], s[STARTED]
--------[test][3], node[1], [R], s[STARTED]
-----node_id[2][V]
--------[test][1], node[2], [R], s[STARTED]
--------[test][2], node[2], [R], s[STARTED]
--------[test][4], node[2], [P], s[STARTED]
-----node_id[3][V]
--------[test][2], node[3], [P], s[STARTED]
--------[test][3], node[3], [P], s[STARTED]
---- unassigned
*/
@Override
public boolean allocateUnassigned(RoutingAllocation allocation) {
List<MutableShardRouting> unassigned = allocation.routingNodes().unassigned();
boolean changed = !unassigned.isEmpty();
for (MutableShardRouting sr : unassigned) {
switch (sr.id()) {
case 0:
if (sr.primary()) {
allocation.routingNodes().node("node1").add(sr);
} else {
allocation.routingNodes().node("node0").add(sr);
}
break;
case 1:
if (sr.primary()) {
allocation.routingNodes().node("node1").add(sr);
} else {
allocation.routingNodes().node("node2").add(sr);
}
break;
case 2:
if (sr.primary()) {
allocation.routingNodes().node("node3").add(sr);
} else {
allocation.routingNodes().node("node2").add(sr);
}
break;
case 3:
if (sr.primary()) {
allocation.routingNodes().node("node3").add(sr);
} else {
allocation.routingNodes().node("node1").add(sr);
}
break;
case 4:
if (sr.primary()) {
allocation.routingNodes().node("node2").add(sr);
} else {
allocation.routingNodes().node("node0").add(sr);
}
break;
}
@Override
public void applyFailedShards(FailedRerouteAllocation allocation) {
}
/*
* // this allocator tries to rebuild this scenario where a rebalance is
* // triggered solely by the primary overload on node [1] where a shard
* // is rebalanced to node 0
routing_nodes:
-----node_id[0][V]
--------[test][0], node[0], [R], s[STARTED]
--------[test][4], node[0], [R], s[STARTED]
-----node_id[1][V]
--------[test][0], node[1], [P], s[STARTED]
--------[test][1], node[1], [P], s[STARTED]
--------[test][3], node[1], [R], s[STARTED]
-----node_id[2][V]
--------[test][1], node[2], [R], s[STARTED]
--------[test][2], node[2], [R], s[STARTED]
--------[test][4], node[2], [P], s[STARTED]
-----node_id[3][V]
--------[test][2], node[3], [P], s[STARTED]
--------[test][3], node[3], [P], s[STARTED]
---- unassigned
*/
@Override
public boolean allocateUnassigned(RoutingAllocation allocation) {
List<MutableShardRouting> unassigned = allocation.routingNodes().unassigned();
boolean changed = !unassigned.isEmpty();
for (MutableShardRouting sr : unassigned) {
switch (sr.id()) {
case 0:
if (sr.primary()) {
allocation.routingNodes().node("node1").add(sr);
} else {
allocation.routingNodes().node("node0").add(sr);
}
}
unassigned.clear();
return changed;
break;
case 1:
if (sr.primary()) {
allocation.routingNodes().node("node1").add(sr);
} else {
allocation.routingNodes().node("node2").add(sr);
}
break;
case 2:
if (sr.primary()) {
allocation.routingNodes().node("node3").add(sr);
} else {
allocation.routingNodes().node("node2").add(sr);
}
break;
case 3:
if (sr.primary()) {
allocation.routingNodes().node("node3").add(sr);
} else {
allocation.routingNodes().node("node1").add(sr);
}
break;
case 4:
if (sr.primary()) {
allocation.routingNodes().node("node2").add(sr);
} else {
allocation.routingNodes().node("node0").add(sr);
}
break;
}
}), ClusterInfoService.EMPTY);
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
}
unassigned.clear();
return changed;
}
}), ClusterInfoService.EMPTY);
MetaData.Builder metaDataBuilder = MetaData.builder();
RoutingTable.Builder routingTableBuilder = routingTable();
IndexMetaData.Builder indexMeta = newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1);
metaDataBuilder = metaDataBuilder.put(indexMeta);
@ -465,15 +463,15 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
RoutingTable routingTable = routingTableBuilder.build();
DiscoveryNodes.Builder nodes = newNodesBuilder();
for (int i = 0; i < 4; i++) {
DiscoveryNode node = newNode("node"+i);
DiscoveryNode node = newNode("node" + i);
nodes.put(node);
}
ClusterState clusterState = newClusterStateBuilder().nodes(nodes).metaData(metaData).routingTable(routingTable).build();
routingTable = strategy.reroute(clusterState).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
RoutingNodes routingNodes = clusterState.routingNodes();
for (RoutingNode routingNode : routingNodes) {
for (MutableShardRouting mutableShardRouting : routingNode) {
assertThat(mutableShardRouting.state(), Matchers.equalTo(ShardRoutingState.INITIALIZING));
@ -491,12 +489,12 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
assertThat(mutableShardRouting.state(), Matchers.equalTo(ShardRoutingState.STARTED));
}
}
logger.info("start the replica shards");
routingTable = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
for (RoutingNode routingNode : routingNodes) {
for (MutableShardRouting mutableShardRouting : routingNode) {
assertThat(mutableShardRouting.state(), Matchers.equalTo(ShardRoutingState.STARTED));
@ -507,13 +505,13 @@ public class BalanceConfigurationTests extends ElasticsearchTestCase {
routingTable = strategy.reroute(clusterState).routingTable();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
routingNodes = clusterState.routingNodes();
for (RoutingNode routingNode : routingNodes) {
for (MutableShardRouting mutableShardRouting : routingNode) {
assertThat(mutableShardRouting.state(), Matchers.equalTo(ShardRoutingState.STARTED));
}
}
}
}

View File

@ -31,13 +31,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
@ -48,7 +46,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testAlways() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -134,7 +132,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterPrimariesActive1() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -238,7 +236,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterPrimariesActive2() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_PRIMARIES_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -322,7 +320,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterAllActive1() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_ALL_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -445,7 +443,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterAllActive2() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_ALL_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -529,7 +527,7 @@ public class ClusterRebalanceRoutingTests extends ElasticsearchTestCase {
public void testClusterAllActive3() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.INDICES_ALL_ACTIVE.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -30,13 +30,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -53,7 +51,7 @@ public class ConcurrentRebalanceRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();

View File

@ -31,13 +31,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -54,7 +52,7 @@ public class DeadNodesAllocationTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()
@ -106,7 +104,7 @@ public class DeadNodesAllocationTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()
@ -181,7 +179,7 @@ public class DeadNodesAllocationTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()

View File

@ -31,14 +31,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -56,7 +54,7 @@ public class DisableAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -85,7 +83,7 @@ public class DisableAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -116,7 +114,7 @@ public class DisableAllocationTests extends ElasticsearchTestCase {
AllocationService strategy = new AllocationService(settingsBuilder()
.build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("disabled").settings(ImmutableSettings.builder().put(DisableAllocationDecider.INDEX_ROUTING_ALLOCATION_DISABLE_ALLOCATION, true).put(DisableAllocationDecider.INDEX_ROUTING_ALLOCATION_DISABLE_NEW_ALLOCATION, true)).numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("enabled").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -31,14 +31,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -54,7 +52,7 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ElasticsearchTes
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();

View File

@ -32,14 +32,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class FailedNodeRoutingTests extends ElasticsearchTestCase {
@ -50,7 +48,7 @@ public class FailedNodeRoutingTests extends ElasticsearchTestCase {
public void simpleFailedNodeTest() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -110,7 +108,7 @@ public class FailedNodeRoutingTests extends ElasticsearchTestCase {
public void simpleFailedNodeTestNoReassign() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -34,13 +34,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -58,7 +56,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
.build());
logger.info("--> building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
RoutingTable routingTable = routingTable()
@ -148,7 +146,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -229,7 +227,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -286,7 +284,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -343,7 +341,7 @@ public class FailedShardsRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();

View File

@ -35,13 +35,11 @@ import java.util.List;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -59,7 +57,7 @@ public class FilterRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();
@ -103,7 +101,7 @@ public class FilterRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").settings(settingsBuilder()
.put("index.number_of_shards", 2)
.put("index.number_of_replicas", 1)
@ -146,7 +144,7 @@ public class FilterRoutingTests extends ElasticsearchTestCase {
logger.info("--> switch between value2 and value4, shards should be relocating");
metaData = newMetaDataBuilder()
metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").settings(settingsBuilder()
.put("index.number_of_shards", 2)
.put("index.number_of_replicas", 1)

View File

@ -32,13 +32,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -59,7 +57,7 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1))
MetaData metaData = MetaData.builder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test1").numberOfShards(3).numberOfReplicas(1)).build();
RoutingTable routingTable = routingTable().addAsNew(metaData.index("test")).addAsNew(metaData.index("test1")).build();
@ -190,7 +188,7 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1))
MetaData metaData = MetaData.builder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test1").numberOfShards(3).numberOfReplicas(1)).build();
RoutingTable routingTable = routingTable().addAsNew(metaData.index("test")).addAsNew(metaData.index("test1")).build();
@ -353,7 +351,7 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1)).build();
MetaData metaData = MetaData.builder().put(newIndexMetaDataBuilder("test").numberOfShards(3).numberOfReplicas(1)).build();
RoutingTable routingTable = routingTable().addAsNew(metaData.index("test")).build();
@ -451,7 +449,7 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
logger.info("Add new index 3 shards 1 replica");
prevRoutingTable = routingTable;
metaData = newMetaDataBuilder().metaData(metaData)
metaData = MetaData.builder(metaData)
.put(newIndexMetaDataBuilder("test1").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
@ -461,8 +459,8 @@ public class IndexBalanceTests extends ElasticsearchTestCase {
.addAsNew(metaData.index("test1"))
.build();
clusterState = newClusterStateBuilder().state(clusterState).metaData(metaData).routingTable(routingTable).build();
assertThat(routingTable.index("test1").shards().size(), equalTo(3));
prevRoutingTable = routingTable;

View File

@ -29,7 +29,6 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@ -53,7 +52,7 @@ public class PreferPrimaryAllocationTests extends ElasticsearchTestCase {
logger.info("create several indices with no replicas, and wait till all are allocated");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(10).numberOfReplicas(0))
.put(newIndexMetaDataBuilder("test2").numberOfShards(10).numberOfReplicas(0))
.build();
@ -77,7 +76,7 @@ public class PreferPrimaryAllocationTests extends ElasticsearchTestCase {
logger.info("increasing the number of replicas to 1, and perform a reroute (to get the replicas allocation going)");
routingTable = RoutingTable.builder().routingTable(routingTable).updateNumberOfReplicas(1).build();
metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(1).build();
metaData = MetaData.builder(clusterState.metaData()).updateNumberOfReplicas(1).build();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
routingTable = strategy.reroute(clusterState).routingTable();
@ -87,7 +86,7 @@ public class PreferPrimaryAllocationTests extends ElasticsearchTestCase {
assertThat(clusterState.routingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
logger.info("create a new index");
metaData = newMetaDataBuilder().metaData(clusterState.metaData())
metaData = MetaData.builder(clusterState.metaData())
.put(newIndexMetaDataBuilder("new_index").numberOfShards(4).numberOfReplicas(0))
.build();

View File

@ -30,14 +30,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -54,7 +52,7 @@ public class PrimaryElectionRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -105,7 +103,7 @@ public class PrimaryElectionRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();

View File

@ -30,14 +30,12 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -57,7 +55,7 @@ public class PrimaryNotRelocatedWhileBeingRecoveredTests extends ElasticsearchTe
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();

View File

@ -44,7 +44,6 @@ import java.util.Random;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@ -60,20 +59,20 @@ public class RandomAllocationDeciderTests extends ElasticsearchTestCase {
* already allocated on a node and balances the cluster to gain optimal
* balance.*/
@Test
public void testRandomDecicions() {
public void testRandomDecisions() {
RandomAllocationDecider randomAllocationDecider = new RandomAllocationDecider(getRandom());
AllocationService strategy = new AllocationService(settingsBuilder().build(), new AllocationDeciders(ImmutableSettings.EMPTY,
new HashSet<AllocationDecider>(Arrays.asList(new SameShardAllocationDecider(ImmutableSettings.EMPTY),
randomAllocationDecider))), new ShardsAllocators(), ClusterInfoService.EMPTY);
int indices = between(1, 20);
Builder metaBuilder = newMetaDataBuilder();
Builder metaBuilder = MetaData.builder();
int maxNumReplicas = 1;
int totalNumShards = 0;
for (int i = 0; i < indices; i++) {
int replicas = between(0, 6);
maxNumReplicas = Math.max(maxNumReplicas, replicas+1);
maxNumReplicas = Math.max(maxNumReplicas, replicas + 1);
int numShards = between(1, 20);
totalNumShards += numShards * (replicas+1);
totalNumShards += numShards * (replicas + 1);
metaBuilder.put(newIndexMetaDataBuilder("INDEX_" + i).numberOfShards(numShards).numberOfReplicas(replicas));
}
@ -94,7 +93,7 @@ public class RandomAllocationDeciderTests extends ElasticsearchTestCase {
DiscoveryNodes.Builder newNodesBuilder = newNodesBuilder();
newNodesBuilder.putAll(clusterState.nodes());
if (clusterState.nodes().size() <= atMostNodes &&
if (clusterState.nodes().size() <= atMostNodes &&
(nodeIdCounter == 0 || (frequentNodes ? frequently() : rarely()))) {
int numNodes = atLeast(1);
for (int j = 0; j < numNodes; j++) {
@ -124,14 +123,14 @@ public class RandomAllocationDeciderTests extends ElasticsearchTestCase {
ClusterState.Builder stateBuilder = newClusterStateBuilder().state(clusterState);
DiscoveryNodes.Builder newNodesBuilder = newNodesBuilder();
newNodesBuilder.putAll(clusterState.nodes());
for (int j = 0; j < (maxNumReplicas-clusterState.nodes().size()); j++) {
for (int j = 0; j < (maxNumReplicas - clusterState.nodes().size()); j++) {
logger.info("adding node [{}]", nodeIdCounter);
newNodesBuilder.put(newNode("NODE_" + (nodeIdCounter++)));
}
stateBuilder.nodes(newNodesBuilder.build());
clusterState = stateBuilder.build();
}
randomAllocationDecider.allwaysSayYes = true;
logger.info("now say YES to everything");
@ -146,11 +145,11 @@ public class RandomAllocationDeciderTests extends ElasticsearchTestCase {
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).build();
}
} while (clusterState.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size() != 0 ||
} while (clusterState.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size() != 0 ||
clusterState.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size() != 0 && iterations < 200);
logger.info("Done Balancing after [{}] iterations", iterations);
// we stop after 200 iterations if it didn't stabelize by then something is likely to be wrong
assertThat("max num iteration exceeded", iterations, Matchers.lessThan(200));
assertThat("max num iteration exceeded", iterations, Matchers.lessThan(200));
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(0));
assertThat(clusterState.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(0));
int shards = clusterState.routingNodes().shardsWithState(ShardRoutingState.STARTED).size();
@ -189,20 +188,20 @@ public class RandomAllocationDeciderTests extends ElasticsearchTestCase {
return Decision.YES;
}
switch (random.nextInt(10)) {
case 9:
case 8:
case 7:
case 6:
case 5:
return Decision.NO;
case 4:
return Decision.THROTTLE;
case 3:
case 2:
case 1:
return Decision.YES;
default:
return Decision.ALWAYS;
case 9:
case 8:
case 7:
case 6:
case 5:
return Decision.NO;
case 4:
return Decision.THROTTLE;
case 3:
case 2:
case 1:
return Decision.YES;
default:
return Decision.ALWAYS;
}
}

View File

@ -31,13 +31,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -58,7 +56,7 @@ public class RebalanceAfterActiveTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();

View File

@ -30,13 +30,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -53,7 +51,7 @@ public class ReplicaAllocatedAfterPrimaryTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -14,7 +14,6 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@ -32,7 +31,7 @@ public class SameShardRoutingTests extends ElasticsearchTestCase {
public void sameHost() {
AllocationService strategy = new AllocationService(settingsBuilder().put(SameShardAllocationDecider.SAME_HOST_SETTING, true).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(2).numberOfReplicas(1))
.build();

View File

@ -31,13 +31,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class ShardVersioningTests extends ElasticsearchTestCase {
@ -48,7 +46,7 @@ public class ShardVersioningTests extends ElasticsearchTestCase {
public void simple() {
AllocationService strategy = new AllocationService(settingsBuilder().put("cluster.routing.allocation.allow_rebalance", ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString()).build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -35,13 +35,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -56,7 +54,7 @@ public class ShardsLimitAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
@ -106,7 +104,7 @@ public class ShardsLimitAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
@ -131,7 +129,7 @@ public class ShardsLimitAllocationTests extends ElasticsearchTestCase {
assertThat(clusterState.readOnlyRoutingNodes().numberOfShardsOfType(STARTED), equalTo(5));
logger.info("add another index with 5 shards");
metaData = newMetaDataBuilder().metaData(metaData)
metaData = MetaData.builder(metaData)
.put(newIndexMetaDataBuilder("test1").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
@ -162,7 +160,7 @@ public class ShardsLimitAllocationTests extends ElasticsearchTestCase {
}
logger.info("update " + ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE + " for test, see that things move");
metaData = newMetaDataBuilder().metaData(metaData)
metaData = MetaData.builder(metaData)
.put(newIndexMetaDataBuilder("test").settings(ImmutableSettings.settingsBuilder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)

View File

@ -39,13 +39,11 @@ import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -61,7 +59,7 @@ public class SingleShardNoReplicasRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
@ -163,7 +161,7 @@ public class SingleShardNoReplicasRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
@ -218,7 +216,7 @@ public class SingleShardNoReplicasRoutingTests extends ElasticsearchTestCase {
final int numberOfIndices = 50;
logger.info("Building initial routing table with " + numberOfIndices + " indices");
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
MetaData.Builder metaDataBuilder = MetaData.builder();
for (int i = 0; i < numberOfIndices; i++) {
metaDataBuilder.put(newIndexMetaDataBuilder("test" + i).numberOfShards(1).numberOfReplicas(0));
}
@ -331,7 +329,7 @@ public class SingleShardNoReplicasRoutingTests extends ElasticsearchTestCase {
final int numberOfIndices = 10;
logger.info("Building initial routing table with " + numberOfIndices + " indices");
MetaData.Builder metaDataBuilder = newMetaDataBuilder();
MetaData.Builder metaDataBuilder = MetaData.builder();
for (int i = 0; i < numberOfIndices; i++) {
metaDataBuilder.put(newIndexMetaDataBuilder("test" + i).numberOfShards(1).numberOfReplicas(0));
}

View File

@ -30,13 +30,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
@ -53,7 +51,7 @@ public class SingleShardOneReplicaRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();

View File

@ -30,13 +30,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -60,7 +58,7 @@ public class TenShardsOneReplicaRoutingTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(10).numberOfReplicas(1))
.build();

View File

@ -29,13 +29,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -54,7 +52,7 @@ public class ThrottlingAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(10).numberOfReplicas(1))
.build();
@ -115,7 +113,7 @@ public class ThrottlingAllocationTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();

View File

@ -11,13 +11,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
/**
@ -33,7 +31,7 @@ public class UpdateNumberOfReplicasTests extends ElasticsearchTestCase {
logger.info("Building initial routing table");
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -85,7 +83,7 @@ public class UpdateNumberOfReplicasTests extends ElasticsearchTestCase {
routingNodes = clusterState.routingNodes();
prevRoutingTable = routingTable;
routingTable = RoutingTable.builder().routingTable(routingTable).updateNumberOfReplicas(2).build();
metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(2).build();
metaData = MetaData.builder(clusterState.metaData()).updateNumberOfReplicas(2).build();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
assertThat(clusterState.metaData().index("test").numberOfReplicas(), equalTo(2));
@ -137,7 +135,7 @@ public class UpdateNumberOfReplicasTests extends ElasticsearchTestCase {
routingNodes = clusterState.routingNodes();
prevRoutingTable = routingTable;
routingTable = RoutingTable.builder().routingTable(routingTable).updateNumberOfReplicas(1).build();
metaData = MetaData.newMetaDataBuilder().metaData(clusterState.metaData()).updateNumberOfReplicas(1).build();
metaData = MetaData.builder(clusterState.metaData()).updateNumberOfReplicas(1).build();
clusterState = newClusterStateBuilder().state(clusterState).routingTable(routingTable).metaData(metaData).build();
assertThat(clusterState.metaData().index("test").numberOfReplicas(), equalTo(1));

View File

@ -41,7 +41,6 @@ import java.util.Map;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.*;
@ -88,7 +87,7 @@ public class DiskThresholdDeciderTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, new ShardsAllocators(), cis);
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -277,7 +276,7 @@ public class DiskThresholdDeciderTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, new ShardsAllocators(), cis);
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -463,7 +462,7 @@ public class DiskThresholdDeciderTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, new ShardsAllocators(), cis);
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();
@ -525,7 +524,7 @@ public class DiskThresholdDeciderTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, new ShardsAllocators(), cis);
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(0))
.build();

View File

@ -34,9 +34,7 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
/**
@ -46,7 +44,7 @@ public class ClusterSerializationTests extends ElasticsearchTestCase {
@Test
public void testClusterStateSerialization() throws Exception {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(10).numberOfReplicas(1))
.build();
@ -69,7 +67,7 @@ public class ClusterSerializationTests extends ElasticsearchTestCase {
@Test
public void testRoutingTableSerialization() throws Exception {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(10).numberOfReplicas(1))
.build();

View File

@ -35,13 +35,11 @@ import org.junit.Test;
import static org.elasticsearch.cluster.ClusterState.newClusterStateBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.newIndexMetaDataBuilder;
import static org.elasticsearch.cluster.metadata.MetaData.newMetaDataBuilder;
import static org.elasticsearch.cluster.node.DiscoveryNodes.newNodesBuilder;
import static org.elasticsearch.cluster.routing.RoutingBuilders.routingTable;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.allocation.RoutingAllocationTests.newNode;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
public class RoutingIteratorTests extends ElasticsearchTestCase {
@ -87,7 +85,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
@Test
public void testIterator1() {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(2))
.build();
RoutingTable routingTable = routingTable()
@ -121,7 +119,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
@Test
public void testIterator2() {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -224,7 +222,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
@Test
public void testRandomRouting() {
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test1").numberOfShards(1).numberOfReplicas(1))
.put(newIndexMetaDataBuilder("test2").numberOfShards(1).numberOfReplicas(1))
.build();
@ -258,7 +256,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.awareness.attributes", "rack_id,zone")
.build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(1).numberOfReplicas(1))
.build();
@ -307,7 +305,7 @@ public class RoutingIteratorTests extends ElasticsearchTestCase {
.put("cluster.routing.allocation.concurrent_recoveries", 10)
.build());
MetaData metaData = newMetaDataBuilder()
MetaData metaData = MetaData.builder()
.put(newIndexMetaDataBuilder("test").numberOfShards(5).numberOfReplicas(1))
.build();