Skip to content

Commit

Permalink
ISPN-6432 Remove deprecated MurmurHash2
Browse files Browse the repository at this point in the history
Also remove the client ConsistentHashV1 that was using it,
but was not used itself since 5.0.
  • Loading branch information
danberindei authored and tristantarrant committed Mar 31, 2016
1 parent bd39c65 commit 126933c
Show file tree
Hide file tree
Showing 29 changed files with 262 additions and 603 deletions.
@@ -1,15 +1,5 @@
package org.infinispan.client.hotrod;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;

import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.configuration.NearCacheConfiguration;
Expand All @@ -29,13 +19,21 @@
import org.infinispan.client.hotrod.logging.Log;
import org.infinispan.client.hotrod.logging.LogFactory;
import org.infinispan.client.hotrod.near.NearCacheService;
import org.infinispan.commons.api.BasicCacheContainer;
import org.infinispan.commons.executors.ExecutorFactory;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.commons.util.FileLookupFactory;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.commons.util.Util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Factory for {@link org.infinispan.client.hotrod.RemoteCache}s. <p/> <p> <b>Lifecycle:</b> </p> In order to be able to
* use an {@link org.infinispan.client.hotrod.RemoteCache}, the {@link org.infinispan.client.hotrod.RemoteCacheManager}
Expand Down Expand Up @@ -125,8 +123,12 @@ public Properties getProperties() {
}
properties.setProperty(ConfigurationProperties.REQUEST_BALANCING_STRATEGY, configuration.balancingStrategyClass().getName());
properties.setProperty(ConfigurationProperties.CONNECT_TIMEOUT, Integer.toString(configuration.connectionTimeout()));
for (int i = 1; i <= configuration.consistentHashImpl().length; i++) {
properties.setProperty(ConfigurationProperties.HASH_FUNCTION_PREFIX + "." + i, configuration.consistentHashImpl()[i-1].getName());
for (int i = 0; i < configuration.consistentHashImpl().length; i++) {
int version = i + 1;
if (configuration.consistentHashImpl(version) != null) {
properties.setProperty(ConfigurationProperties.HASH_FUNCTION_PREFIX + "." + version,
configuration.consistentHashImpl(version).getName());
}
}
properties.setProperty(ConfigurationProperties.FORCE_RETURN_VALUES, Boolean.toString(configuration.forceReturnValues()));
properties.setProperty(ConfigurationProperties.KEY_SIZE_ESTIMATE, Integer.toString(configuration.keySizeEstimate()));
Expand Down
Expand Up @@ -126,7 +126,7 @@ public int connectionTimeout() {
}

public Class<? extends ConsistentHash>[] consistentHashImpl() {
return consistentHashImpl;
return Arrays.copyOf(consistentHashImpl, consistentHashImpl.length);
}

public Class<? extends ConsistentHash> consistentHashImpl(int version) {
Expand Down
@@ -1,20 +1,9 @@
package org.infinispan.client.hotrod.configuration;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.impl.ConfigurationProperties;
import org.infinispan.client.hotrod.impl.TypedProperties;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV2;
import org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash;
import org.infinispan.client.hotrod.impl.transport.TransportFactory;
Expand All @@ -28,6 +17,16 @@
import org.infinispan.commons.marshall.jboss.GenericJBossMarshaller;
import org.infinispan.commons.util.Util;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* ConfigurationBuilder used to generate immutable {@link Configuration} objects to pass to the
* {@link RemoteCacheManager#RemoteCacheManager(Configuration)} constructor.
Expand All @@ -51,7 +50,7 @@ public class ConfigurationBuilder implements ConfigurationChildBuilder, Builder<
private int connectionTimeout = ConfigurationProperties.DEFAULT_CONNECT_TIMEOUT;
@SuppressWarnings("unchecked")
private final Class<? extends ConsistentHash> consistentHashImpl[] = new Class[] {
ConsistentHashV1.class, ConsistentHashV2.class, SegmentConsistentHash.class
null, ConsistentHashV2.class, SegmentConsistentHash.class
};
private boolean forceReturnValues;
private int keySizeEstimate = ConfigurationProperties.DEFAULT_KEY_SIZE;
Expand Down Expand Up @@ -159,13 +158,21 @@ public ConfigurationBuilder connectionTimeout(int connectionTimeout) {

@Override
public ConfigurationBuilder consistentHashImpl(int version, Class<? extends ConsistentHash> consistentHashClass) {
this.consistentHashImpl[version - 1] = consistentHashClass;
if (version == 1) {
log.warn("Hash function version 1 is no longer supported.");
} else {
this.consistentHashImpl[version - 1] = consistentHashClass;
}
return this;
}

@Override
public ConfigurationBuilder consistentHashImpl(int version, String consistentHashClass) {
this.consistentHashImpl[version - 1] = Util.loadClass(consistentHashClass, classLoader());
if (version == 1) {
log.warn("Hash function version 1 is no longer supported.");
} else {
this.consistentHashImpl[version - 1] = Util.loadClass(consistentHashClass, classLoader());
}
return this;
}

Expand Down Expand Up @@ -267,8 +274,16 @@ public ConfigurationBuilder withProperties(Properties properties) {
this.balancingStrategy(typed.getProperty(ConfigurationProperties.REQUEST_BALANCING_STRATEGY, balancingStrategyClass.getName()));
this.connectionPool.withPoolProperties(typed);
this.connectionTimeout(typed.getIntProperty(ConfigurationProperties.CONNECT_TIMEOUT, connectionTimeout));
for (int i = 1; i <= consistentHashImpl.length; i++) {
this.consistentHashImpl(i, typed.getProperty(ConfigurationProperties.HASH_FUNCTION_PREFIX + "." + i, consistentHashImpl[i - 1].getName()));
if (typed.containsKey(ConfigurationProperties.HASH_FUNCTION_PREFIX + ".1")) {
log.warn("Hash function version 1 is no longer supported");
}
for (int i = 0; i < consistentHashImpl.length; i++) {
if (consistentHashImpl[i] != null) {
int version = i + 1;
this.consistentHashImpl(version,
typed.getProperty(ConfigurationProperties.HASH_FUNCTION_PREFIX + "." + version,
consistentHashImpl[i].getName()));
}
}
this.forceReturnValues(typed.getBooleanProperty(ConfigurationProperties.FORCE_RETURN_VALUES, forceReturnValues));
this.keySizeEstimate(typed.getIntProperty(ConfigurationProperties.KEY_SIZE_ESTIMATE, keySizeEstimate));
Expand Down Expand Up @@ -352,7 +367,7 @@ public ConfigurationBuilder read(Configuration template) {
this.connectionPool.read(template.connectionPool());
this.connectionTimeout = template.connectionTimeout();
for (int i = 0; i < consistentHashImpl.length; i++) {
this.consistentHashImpl[i] = template.consistentHashImpl()[i];
this.consistentHashImpl[i] = template.consistentHashImpl(i + 1);
}
this.forceReturnValues = template.forceReturnValues();
this.keySizeEstimate = template.keySizeEstimate();
Expand Down
Expand Up @@ -3,7 +3,6 @@
import java.util.Properties;

import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHash;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1;
import org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV2;
import org.infinispan.client.hotrod.impl.transport.TransportFactory;
import org.infinispan.client.hotrod.impl.transport.tcp.FailoverRequestBalancingStrategy;
Expand Down Expand Up @@ -75,13 +74,13 @@ public interface ConfigurationChildBuilder {

/**
* Defines the {@link ConsistentHash} implementation to use for the specified version. By default,
* {@link ConsistentHashV1} is used for version 1 and {@link ConsistentHashV2} is used for version 2.
* {@link ConsistentHashV2} is used for version 1 and {@link ConsistentHashV2} is used for version 2.
*/
ConfigurationBuilder consistentHashImpl(int version, Class<? extends ConsistentHash> consistentHashClass);

/**
* Defines the {@link ConsistentHash} implementation to use for the specified version. By default,
* {@link ConsistentHashV1} is used for version 1 and {@link ConsistentHashV2} is used for version 2.
* {@link ConsistentHashV2} is used for version 1 and {@link ConsistentHashV2} is used for version 2.
*/
ConfigurationBuilder consistentHashImpl(int version, String consistentHashClass);

Expand Down
Expand Up @@ -9,26 +9,30 @@
* into the configuration for consistent hash definitions as follows:
* consistent-hash.[version]=[fully qualified class implementing ConsistentHash]
* e.g.
* <code>infinispan.client.hotrod.hash_function_impl.1=org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1</code>
* <code>infinispan.client.hotrod.hash_function_impl.3=org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash</code>
* or if using the {@link Configuration} API,
* <code>configuration.consistentHashImpl(1, org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV1.class);</code>
* <code>configuration.consistentHashImpl(3, org.infinispan.client.hotrod.impl.consistenthash.SegmentConsistentHash.class);</code>
* <p/>
* If no CH function is defined for a certain version, then it will be defaulted to "org.infinispan.client.hotrod.impl.ConsistentHashV[version]".
* E.g. if the server indicates that in use CH is version 1, and it is not defined within the configuration, it will be defaulted to
* org.infinispan.client.hotrod.impl.ConsistentHashV1.
*
* <p>The defaults are:</p>
* <ol>
* <li>N/A (No longer used.)</li>
* <li>org.infinispan.client.hotrod.impl.ConsistentHashV2</li>
* <li>org.infinispan.client.hotrod.impl.SegmentConsistentHash</li>
* </ol>
*
* @author Mircea.Markus@jboss.com
* @since 4.1
*/
public class ConsistentHashFactory {
private Class<? extends ConsistentHash>[] version2ConsistentHash;
private Configuration configuration;

public void init(Configuration configuration) {
this.version2ConsistentHash = configuration.consistentHashImpl();
this.configuration = configuration;
}

public <T extends ConsistentHash> T newConsistentHash(int version) {
Class<? extends ConsistentHash> hashFunctionClass = version2ConsistentHash[version-1];
Class<? extends ConsistentHash> hashFunctionClass = configuration.consistentHashImpl(version);
// TODO: Why create a brand new instance via reflection everytime a new hash topology is received? Caching???
return (T) Util.getInstance(hashFunctionClass);
}
Expand Down

This file was deleted.

0 comments on commit 126933c

Please sign in to comment.