use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.
the class BalanceConfigurationTests method testReplicaBalance.
public void testReplicaBalance() {
/* Tests balance over replicas only */
final float indexBalance = 0.0f;
final float replicaBalance = 1.0f;
final float balanceTreshold = 1.0f;
Settings.Builder settings = Settings.builder();
settings.put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString());
settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), indexBalance);
settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), replicaBalance);
settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), balanceTreshold);
AllocationService strategy = createAllocationService(settings.build(), new NoopGatewayAllocator());
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);
clusterState = removeNodes(clusterState, strategy);
assertReplicaBalance(logger, clusterState.getRoutingNodes(), (numberOfNodes + 1) - (numberOfNodes + 1) / 2, numberOfIndices, numberOfReplicas, numberOfShards, balanceTreshold);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.
the class BalanceConfigurationTests method testPersistedSettings.
public void testPersistedSettings() {
Settings.Builder settings = Settings.builder();
settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.2);
settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 0.3);
settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), 2.0);
ClusterSettings service = new ClusterSettings(Settings.builder().build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
BalancedShardsAllocator allocator = new BalancedShardsAllocator(settings.build(), service);
assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.2f));
assertThat(allocator.getShardBalance(), Matchers.equalTo(0.3f));
assertThat(allocator.getThreshold(), Matchers.equalTo(2.0f));
settings = Settings.builder();
settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.2);
settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 0.3);
settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), 2.0);
settings.put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString());
service.applySettings(settings.build());
assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.2f));
assertThat(allocator.getShardBalance(), Matchers.equalTo(0.3f));
assertThat(allocator.getThreshold(), Matchers.equalTo(2.0f));
settings = Settings.builder();
settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.5);
settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 0.1);
settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), 3.0);
service.applySettings(settings.build());
assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.5f));
assertThat(allocator.getShardBalance(), Matchers.equalTo(0.1f));
assertThat(allocator.getThreshold(), Matchers.equalTo(3.0f));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.
the class BalancedSingleShardTests method executeRebalanceFor.
private MoveDecision executeRebalanceFor(final ShardRouting shardRouting, final ClusterState clusterState, final Set<String> noDecisionNodes, final float threshold) {
Settings settings = Settings.EMPTY;
if (Float.compare(-1.0f, threshold) != 0) {
settings = Settings.builder().put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), threshold).build();
}
AllocationDecider allocationDecider = new AllocationDecider(Settings.EMPTY) {
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
if (noDecisionNodes.contains(node.nodeId())) {
return Decision.NO;
}
return Decision.YES;
}
};
AllocationDecider rebalanceDecider = new AllocationDecider(Settings.EMPTY) {
@Override
public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation allocation) {
return Decision.YES;
}
};
BalancedShardsAllocator allocator = new BalancedShardsAllocator(settings);
RoutingAllocation routingAllocation = newRoutingAllocation(new AllocationDeciders(Settings.EMPTY, Arrays.asList(allocationDecider, rebalanceDecider)), clusterState);
return allocator.decideShardAllocation(shardRouting, routingAllocation).getMoveDecision();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.
the class RoutingBackwardCompatibilityTests method testBackwardCompatibility.
public void testBackwardCompatibility() throws Exception {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(RoutingBackwardCompatibilityTests.class.getResourceAsStream("/org/elasticsearch/cluster/routing/shard_routes.txt"), "UTF-8"))) {
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
if (line.startsWith("#")) {
// comment
continue;
}
String[] parts = line.split("\t");
assertEquals(Arrays.toString(parts), 7, parts.length);
final String index = parts[0];
final int numberOfShards = Integer.parseInt(parts[1]);
final String type = parts[2];
final String id = parts[3];
final String routing = "null".equals(parts[4]) ? null : parts[4];
// not needed anymore - old hashing is gone
final int pre20ExpectedShardId = Integer.parseInt(parts[5]);
final int currentExpectedShard = Integer.parseInt(parts[6]);
OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
for (Version version : VersionUtils.allReleasedVersions()) {
if (version.onOrAfter(Version.V_2_0_0) == false) {
// unsupported version, no need to test
continue;
}
final Settings settings = settings(version).build();
IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(settings).numberOfShards(numberOfShards).numberOfReplicas(randomInt(3)).build();
MetaData.Builder metaData = MetaData.builder().put(indexMetaData, false);
RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetaData).build();
ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
final int shardId = operationRouting.indexShards(clusterState, index, id, routing).shardId().getId();
assertEquals(currentExpectedShard, shardId);
}
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.settings.Settings in project elasticsearch by elastic.
the class UnassignedInfoTests method testRemainingDelayCalculation.
/**
* Verifies that delayed allocation calculation are correct.
*/
public void testRemainingDelayCalculation() throws Exception {
final long baseTime = System.nanoTime();
UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.NODE_LEFT, "test", null, 0, baseTime, System.currentTimeMillis(), randomBoolean(), AllocationStatus.NO_ATTEMPT);
final long totalDelayNanos = TimeValue.timeValueMillis(10).nanos();
final Settings indexSettings = Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueNanos(totalDelayNanos)).build();
long delay = unassignedInfo.getRemainingDelay(baseTime, indexSettings);
assertThat(delay, equalTo(totalDelayNanos));
long delta1 = randomIntBetween(1, (int) (totalDelayNanos - 1));
delay = unassignedInfo.getRemainingDelay(baseTime + delta1, indexSettings);
assertThat(delay, equalTo(totalDelayNanos - delta1));
delay = unassignedInfo.getRemainingDelay(baseTime + totalDelayNanos, indexSettings);
assertThat(delay, equalTo(0L));
delay = unassignedInfo.getRemainingDelay(baseTime + totalDelayNanos + randomIntBetween(1, 20), indexSettings);
assertThat(delay, equalTo(0L));
}
Aggregations