Local Gateway: Allow to set gateway.local.initial_shards to `quorum-1`, closes #1160.

This commit is contained in:
Shay Banon 2011-07-26 10:55:53 +03:00
parent cc1415e281
commit 68868c4d3f
1 changed files with 22 additions and 12 deletions

View File

@ -76,6 +76,8 @@ public class LocalGatewayNodeAllocation extends NodeAllocation {
this.listTimeout = componentSettings.getAsTime("list_timeout", TimeValue.timeValueSeconds(30));
this.initialShards = componentSettings.get("initial_shards", "quorum");
logger.debug("using initial_shards [{}], list_timeout [{}]", initialShards, listTimeout);
}
@Override public void applyStartedShards(NodeAllocations nodeAllocations, StartedRerouteAllocation allocation) {
@ -142,19 +144,27 @@ public class LocalGatewayNodeAllocation extends NodeAllocation {
// check if the counts meets the minimum set
int requiredAllocation = 1;
IndexMetaData indexMetaData = routingNodes.metaData().index(shard.index());
if ("quorum".equals(initialShards)) {
if (indexMetaData.numberOfReplicas() > 1) {
requiredAllocation = ((1 + indexMetaData.numberOfReplicas()) / 2) + 1;
try {
IndexMetaData indexMetaData = routingNodes.metaData().index(shard.index());
if ("quorum".equals(initialShards)) {
if (indexMetaData.numberOfReplicas() > 1) {
requiredAllocation = ((1 + indexMetaData.numberOfReplicas()) / 2) + 1;
}
} else if ("quorum-1".equals(initialShards) || "half".equals(initialShards)) {
if (indexMetaData.numberOfReplicas() > 2) {
requiredAllocation = ((1 + indexMetaData.numberOfReplicas()) / 2);
}
} else if ("full".equals(initialShards)) {
requiredAllocation = indexMetaData.numberOfReplicas() + 1;
} else if ("full-1".equals(initialShards)) {
if (indexMetaData.numberOfReplicas() > 1) {
requiredAllocation = indexMetaData.numberOfReplicas();
}
} else {
requiredAllocation = Integer.parseInt(initialShards);
}
} else if ("full".equals(initialShards)) {
requiredAllocation = indexMetaData.numberOfReplicas() + 1;
} else if ("full-1".equals(initialShards)) {
if (indexMetaData.numberOfReplicas() > 1) {
requiredAllocation = indexMetaData.numberOfReplicas();
}
} else {
requiredAllocation = Integer.parseInt(initialShards);
} catch (Exception e) {
logger.warn("[{}][{}] failed to derived initial_shards from value {}, ignore allocation for {}", shard.index(), shard.id(), initialShards, shard);
}
// not enough found for this shard, continue...