MasterSlave consistency and old mode compatibility with shard names
This commit is contained in:
@@ -15,4 +15,6 @@ public abstract class ShardInfo<T> {
|
||||
}
|
||||
|
||||
protected abstract T createResource();
|
||||
|
||||
public abstract String getName();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user