/** * the previous 7 may be too small to reduce the chance to get all down nodes * @param k * @return */ public Iterator<MemcachedNode> getSequence(String k) { // Seven searches gives us a 1 in 2^maxTry chance of hitting the // same dead node all of the time. int maxTry = config.getNodeRepetitions() + 1; if (maxTry < 20) { maxTry = 20; } return new KetamaIterator(k, maxTry, getKetamaNodes(), hashAlg); }
final int numReps = config.getNodeRepetitions(); for (MemcachedNode node : nodes) {
int numReps = config.getNodeRepetitions(); int nodeCount = nodes.size(); int totalWeight = 0; float percent = (totalWeight == 0 ? 0f : (float) thisWeight / (float) totalWeight); int pointerPerServer = (int) ((Math.floor( (float) (percent * (float) config.getNodeRepetitions() / 4 * (float) nodeCount + 0.0000000001))) * 4); for (int i = 0; i < pointerPerServer / 4; i++) {
/** * the previous 7 may be too small to reduce the chance to get all down nodes * @param k * @return */ public Iterator<MemcachedNode> getSequence(String k) { // Seven searches gives us a 1 in 2^maxTry chance of hitting the // same dead node all of the time. int maxTry = config.getNodeRepetitions() + 1; if (maxTry < 20) { maxTry = 20; } return new KetamaIterator(k, maxTry, getKetamaNodes(), hashAlg); }
public KetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm alg, KetamaNodeLocatorConfiguration conf) { super(); allNodes = nodes; hashAlg = alg; ketamaNodes = new TreeMap<Long, MemcachedNode>(); config = conf; int numReps = config.getNodeRepetitions(); for (MemcachedNode node : nodes) { // Ketama does some special work with md5 where it reuses chunks. if (alg == HashAlgorithm.KETAMA_HASH) { for (int i = 0; i < numReps / 4; i++) { byte[] digest = HashAlgorithm.computeMd5(config.getKeyForNode(node, i)); for (int h = 0; h < 4; h++) { Long k = ((long) (digest[3 + h * 4] & 0xFF) << 24) | ((long) (digest[2 + h * 4] & 0xFF) << 16) | ((long) (digest[1 + h * 4] & 0xFF) << 8) | (digest[h * 4] & 0xFF); ketamaNodes.put(k, node); } } } else { for (int i = 0; i < numReps; i++) { ketamaNodes.put(hashAlg.hash(config.getKeyForNode(node, i)), node); } } } assert ketamaNodes.size() == numReps * nodes.size(); }
public KetamaNodeLocator(List<MemcachedNode> nodes, HashAlgorithm alg, KetamaNodeLocatorConfiguration conf) { super(); allNodes = nodes; hashAlg = alg; ketamaNodes=new TreeMap<Long, MemcachedNode>(); config= conf; int numReps= config.getNodeRepetitions(); for(MemcachedNode node : nodes) { // Ketama does some special work with md5 where it reuses chunks. if(alg == HashAlgorithm.KETAMA_HASH) { for(int i=0; i<numReps / 4; i++) { byte[] digest=HashAlgorithm.computeMd5(config.getKeyForNode(node, i)); for(int h=0;h<4;h++) { Long k = ((long)(digest[3+h*4]&0xFF) << 24) | ((long)(digest[2+h*4]&0xFF) << 16) | ((long)(digest[1+h*4]&0xFF) << 8) | (digest[h*4]&0xFF); ketamaNodes.put(k, node); } } } else { for(int i=0; i<numReps; i++) { ketamaNodes.put(hashAlg.hash(config.getKeyForNode(node, i)), node); } } } assert ketamaNodes.size() == numReps * nodes.size(); }
/** * Setup the KetamaNodeLocator with the list of nodes it should use. * * @param nodes a List of MemcachedNodes for this KetamaNodeLocator to use in * its continuum */ protected void setKetamaNodes(List<MemcachedNode> nodes) { TreeMap<Long, MemcachedNode> newNodeMap = new TreeMap<Long, MemcachedNode>(); int numReps = config.getNodeRepetitions(); for (MemcachedNode node : nodes) { for (int i = 0; i < numReps / 4; i++) { byte[] digest = DefaultHashAlgorithm.computeMd5(config.getKeyForNode(node, i)); for (int h = 0; h < 4; h++) { Long k = ((long) (digest[3 + h * 4] & 0xFF) << 24) | ((long) (digest[2 + h * 4] & 0xFF) << 16) | ((long) (digest[1 + h * 4] & 0xFF) << 8) | (digest[h * 4] & 0xFF); newNodeMap.put(k, node); getLogger().debug("Adding node %s in position %d", node, k); } } } assert newNodeMap.size() == numReps * nodes.size(); ketamaNodes = newNodeMap; } }
int numReps= config.getNodeRepetitions(); for(MemcachedNode node : nodes) {
TreeMap<Long, MemcachedNode> newNodeMap = new TreeMap<Long, MemcachedNode>(); int numReps = config.getNodeRepetitions(); for (MemcachedNode node : nodes) {
TreeMap<Long, MemcachedNode> newNodeMap = new TreeMap<Long, MemcachedNode>(); int numReps = config.getNodeRepetitions(); int nodeCount = nodes.size(); int totalWeight = 0; int pointerPerServer = (int)((Math.floor((float)(percent * (float)config.getNodeRepetitions() / 4 * (float)nodeCount + 0.0000000001))) * 4); for (int i = 0; i < pointerPerServer / 4; i++) { for(long position : ketamaNodePositionsAtIteration(node, i)) {
TreeMap<Long, MemcachedNode> newNodeMap = new TreeMap<Long, MemcachedNode>(); int numReps = config.getNodeRepetitions(); int nodeCount = nodes.size(); int totalWeight = 0; int pointerPerServer = (int)((Math.floor((float)(percent * (float)config.getNodeRepetitions() / 4 * (float)nodeCount + 0.0000000001))) * 4); for (int i = 0; i < pointerPerServer / 4; i++) { for(long position : ketamaNodePositionsAtIteration(node, i)) {
int numReps = config.getNodeRepetitions(); int nodeCount = nodes.size(); int totalWeight = 0; float percent = (totalWeight == 0 ? 0f : (float) thisWeight / (float) totalWeight); int pointerPerServer = (int) ((Math.floor( (float) (percent * (float) config.getNodeRepetitions() / 4 * (float) nodeCount + 0.0000000001))) * 4); for (int i = 0; i < pointerPerServer / 4; i++) {