MasterSlave consistency and old mode compatibility with shard names

This commit is contained in:
Dario Guzik
2011-05-15 18:22:34 -03:00
parent 5c9d516598
commit 37587df2b6
5 changed files with 153 additions and 5 deletions

View File

@@ -15,4 +15,6 @@ public abstract class ShardInfo<T> {
}
protected abstract T createResource();
public abstract String getName();
}

View File

@@ -56,7 +56,10 @@ public class Sharded<R, S extends ShardInfo<R>> {
for (int i = 0; i != shards.size(); ++i) {
final S shardInfo = shards.get(i);
for (int n = 0; n < 160 * shardInfo.getWeight(); n++) {
nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n), shardInfo);
if (shardInfo.getName() == null)
nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n), shardInfo);
else
nodes.put(this.algo.hash(shardInfo.getName() + "*" + shardInfo.getWeight() + n), shardInfo);
}
resources.put(shardInfo, shardInfo.createResource());
}