Skip to content

Commit

Permalink
[HACK] Patch ReplicatedConsistentHash implementation directly to expe…
Browse files Browse the repository at this point in the history
…riment with affinity tagging
  • Loading branch information
Sanne committed Jan 20, 2015
1 parent 2ee4fd9 commit 45a3d9e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
@@ -0,0 +1,12 @@
package org.infinispan.distribution.ch;

public interface AffinityTaggedKey {

/**
* This numeric id is used exclusively for storage affinity in Infinispan.
*
* @return the segment id to be used for storage, or -1 to fall back to normal owner selection.
*/
int getAffinitySegmentId();

}
Expand Up @@ -2,6 +2,7 @@

import org.infinispan.commons.hash.Hash;
import org.infinispan.commons.marshall.InstanceReusingAdvancedExternalizer;
import org.infinispan.distribution.ch.AffinityTaggedKey;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.marshall.core.Ids;
import org.infinispan.remoting.transport.Address;
Expand Down Expand Up @@ -62,6 +63,15 @@ public Hash getHashFunction() {

@Override
public int getSegment(Object key) {
if (key instanceof AffinityTaggedKey) {
AffinityTaggedKey tagged = (AffinityTaggedKey) key;
int segment = tagged.getAffinitySegmentId();
//The check for [segment < numSegments] should generally not be needed, but let's be safe as the entry
//might have been stored when a different configuration or version of Infinispan was used
if (segment != -1 && segment < primaryOwners.length) {
return segment;
}//Else: use normal hashing, which is always safe as AffinityTaggedKey is meant only as performance boost
}
// The result must always be positive, so we make sure the dividend is positive first
return (hashFunction.hash(key) & Integer.MAX_VALUE) % primaryOwners.length;
}
Expand Down
@@ -1,12 +1,14 @@
package org.infinispan.lucene;

import org.infinispan.distribution.ch.AffinityTaggedKey;

/**
* Mostly used for internal abstraction: common type for all keys which need name scoping for different indexes.
*
* @author Sanne Grinovero
* @since 5.2
*/
public interface IndexScopedKey {
public interface IndexScopedKey extends AffinityTaggedKey {

/**
* Different indexes are required to use different names
Expand Down

0 comments on commit 45a3d9e

Please sign in to comment.