使用Hazelcast客户端部署选项部署Cassandra驱动程序时出现以下错误:

huangapple go评论67阅读模式
英文:

Deploying Cassandra driver using Hazelcast client deployment option giving following error

问题

我正在尝试使用由Cassandra支持的MapStore为此我将这些MapStore和MapLoader实现通过ClientUserCodeDeploymentConfig推送到Hazelcast成员如下所示

public class CassandraMapStoreFactory implements MapStoreFactory<String, Long> {

    @Override
    public MapLoader<String, Long> newMapStore(String mapName, Properties properties) {
        return new CassandraPersistence(buildSession());
    }

    private Session buildSession() {
        try {
            ConsistencyLevel consistencyLevel = ConsistencyLevel.LOCAL_QUORUM;

            PoolingOptions poolingOptions = new PoolingOptions()
                    .setMaxRequestsPerConnection(HostDistance.LOCAL, 1024)
                    .setMaxRequestsPerConnection(HostDistance.REMOTE, 256);

            Cluster cluster = Cluster.builder()
                    .addContactPoints("15.207.180.45")
                    .withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel))
                    .withSocketOptions(new SocketOptions().setReadTimeoutMillis(12000))
                    .withPoolingOptions(poolingOptions)
                    .withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(10000, 2))
                    .build();
            return cluster.connect("sample");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}

以下是将客户端代码推送到Hazelcast成员/服务器的代码

public static void main(String[] args) {
        ClientConfig config = new ClientConfig();
        ClientUserCodeDeploymentConfig codeDeploymentConfig = new ClientUserCodeDeploymentConfig().setEnabled(true)
                .addClass(CounterEntryProcessor.class).addClass(CassandraMapStoreFactory.class).addClass(CassandraPersistence.class).addJar("cassandra-driver-core-3.1.2.jar");
        config.setUserCodeDeploymentConfig(codeDeploymentConfig);
        config.setClassLoader(MapIdGeneratorWithClient.class.getClassLoader());

        HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config);

        // map processing logic
        
        hazelcastInstance.shutdown();
    }

**在初始化CassandraMapStoreFactory时我遇到了以下问题这似乎与Java 9模块特性有关而我正在使用Java 11请指导我如何在客户端/服务器部署方法中使用Hazelcast映射存储中的Cassandra驱动程序**

Caused by: java.lang.IllegalAccessError: class com.datastax.driver.core.AbstractAddressableByIndexData cannot access its abstract superclass com.datastax.driver.core.AbstractGettableByIndexData (com.datastax.driver.core.AbstractAddressableByIndexData在com.hazelcast.internal.usercodedeployment.impl.ClassSource @3614246c的未命名模块中com.datastax.driver.core.AbstractGettableByIndexData在com.hazelcast.internal.usercodedeployment.impl.ClassSource @4890c0d0的未命名模块中)
英文:

I am trying to use MapStore backed by Cassandra. For that pushing those MapStore and MapLoader implementations to Hazelcast member using ClientUserCodeDeploymentConfig as follows

public class CassandraMapStoreFactory implements MapStoreFactory&lt;String, Long&gt; {
@Override
public MapLoader&lt;String, Long&gt; newMapStore(String mapName, Properties properties) {
return new CassandraPersistence(buildSession());
}
private Session buildSession() {
try {
ConsistencyLevel consistencyLevel = ConsistencyLevel.LOCAL_QUORUM;
PoolingOptions poolingOptions = new PoolingOptions()
.setMaxRequestsPerConnection(HostDistance.LOCAL, 1024)
.setMaxRequestsPerConnection(HostDistance.REMOTE, 256);
Cluster cluster = Cluster.builder()
.addContactPoints(&quot;15.207.180.45&quot;)
.withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel))
.withSocketOptions(new SocketOptions().setReadTimeoutMillis(12000))
.withPoolingOptions(poolingOptions)
.withSpeculativeExecutionPolicy(new ConstantSpeculativeExecutionPolicy(10000, 2))
.build();
return cluster.connect(&quot;sample&quot;);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

And following is the code to push client code to Hazelcast member/server

public static void main(String[] args) {
ClientConfig config = new ClientConfig();
ClientUserCodeDeploymentConfig codeDeploymentConfig = new ClientUserCodeDeploymentConfig().setEnabled(true)
.addClass(CounterEntryProcessor.class).addClass(CassandraMapStoreFactory.class).addClass(CassandraPersistence.class).addJar(&quot;cassandra-driver-core-3.1.2.jar&quot;);
config.setUserCodeDeploymentConfig(codeDeploymentConfig);
config.setClassLoader(MapIdGeneratorWithClient.class.getClassLoader());
HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config);
// map processing logic
hazelcastInstance.shutdown();
}

I see the following issue while initializing CassandraMapStoreFactory. It seems issue with Java 9 Modules features and I am using Java 11. Please guide me on what to do to make use of Cassandra driver in Hazelcast map store in the client/server deployment approach

Caused by: java.lang.IllegalAccessError: class com.datastax.driver.core.AbstractAddressableByIndexData cannot access its abstract superclass com.datastax.driver.core.AbstractGettableByIndexData (com.datastax.driver.core.AbstractAddressableByIndexData is in unnamed module of loader com.hazelcast.internal.usercodedeployment.impl.ClassSource @3614246c; com.datastax.driver.core.AbstractGettableByIndexData is in unnamed module of loader com.hazelcast.internal.usercodedeployment.impl.ClassSource @4890c0d0)

答案1

得分: 0

除非您绝对需要动态性,我建议不要使用用户代码部署。正常的做法是确保成员的类路径上实际上包含了所需的类。

添加JAR文件与设置CLASSPATH环境变量一样简单。它适用于ZIP分发版和Docker镜像。

以下是一个展示这一点的docker-compose.yaml文件片段:

version: '3'
services:
  server:
    container_name: hz
    image: hazelcast/hazelcast:4.0
    ports:
      - 5701:5701
    volumes:
      - /Users/nico/.m2/repository:/opt/hazelcast/classpath
    environment:
      - CLASSPATH=/opt/hazelcast/classpath/org/json/json/20200518/json-20200518.jar:/opt/hazelcast/classpath/org/jetbrains/kotlin/kotlin-stdlib/1.3.72/kotlin-stdlib-1.3.72.jar:/opt/hazelcast/classpath/com/github/kittinunf/fuel/fuel/2.2.3/fuel-2.2.3.jar:/opt/hazelcast/classpath/com/github/kittinunf/result/result/3.0.1/result-3.0.1.jar
英文:

Unless you absolutely need to be dynamic, I'd advise against using user code deployment. The nominal path is to actually start the member with the necessary classes on its class path.

Adding the JAR is just as easy as setting the CLASSPATH environment variable. It will work with both the ZIP distribution and the Docker image.

Here's an extract of a docker-compose.yaml file that showcases it:

version: &#39;3&#39;
services:
  server:
    container_name: hz
    image: hazelcast/hazelcast:4.0
    ports:
      - 5701:5701
    volumes:
      - /Users/nico/.m2/repository:/opt/hazelcast/classpath
    environment:
      - CLASSPATH=/opt/hazelcast/classpath/org/json/json/20200518/json-20200518.jar:/opt/hazelcast/classpath/org/jetbrains/kotlin/kotlin-stdlib/1.3.72/kotlin-stdlib-1.3.72.jar:/opt/hazelcast/classpath/com/github/kittinunf/fuel/fuel/2.2.3/fuel-2.2.3.jar:/opt/hazelcast/classpath/com/github/kittinunf/result/result/3.0.1/result-3.0.1.jar

huangapple
  • 本文由 发表于 2020年10月18日 04:29:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64407030.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定