JanusGraphFactory 无法制作 CQLStoreManager

问题描述 投票:0回答:1

问题

为什么在包含依赖项时出现此错误?

Could not find implementation class: org.janusgraph.diskstorage.cql.CQLStoreManager
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-cql</artifactId>

请注意,我对 JanusGraph 和 GraphDB 以及 Cassandra 都是新手。

复制

步骤

  1. 下载并安装 Docker
  2. 创建并启动JanusGraph 的 Cassandra [Docker 容器]
    docker run --name jg-cassandra -d -e CASSANDRA_START_RPC=true -p 9160:9160 -p 9042:9042 -p 7199:7199 -p 7001:7001 -p 7000:7000 cassandra:3.11
  3. 复制并粘贴
    janusgraph.cql.properties
    到 Cassandra [Docker 容器]
    1. 复制JanusGraph / janusgraph / blob / master / janusgraph-dist / src / assembly / cfilter / conf / janusgraph-cql.properties
    2. docker exec -i jg-cassandra mkdir -p /opt/janusgraph/conf
    3. docker cp janusgraph-cql.properties jq-cassandra:/opt/janusgraph/conf
  4. 编码并运行 测试项目
    JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
  5. 结果
    1. 预期:要运行的程序
    2. 实际:程序抛出错误
      Could not instantiate implementation: org.janusgraph.diskstorage.cql.CQLStoreManager

日志

2023-05-08 10:52:10,722 [INFO] [c.d.o.d.i.c.ContactPoints.main] ::   Contact point localhost:9042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1])
Exception in thread "main" java.lang.IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.cql.CQLStoreManager
    at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:79)
    at org.janusgraph.diskstorage.Backend.getImplementationClass(Backend.java:537)
    at org.janusgraph.diskstorage.Backend.getStorageManager(Backend.java:498)
    at org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder.build(GraphDatabaseConfigurationBuilder.java:64)
    at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:176)
    at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:147)
    at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:137)
    at org.janusgraph.core.JanusGraphFactory$Builder.open(JanusGraphFactory.java:277)
    at Main.main(Main.java:6)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:73)
    ... 8 more
Caused by: java.lang.NoClassDefFoundError: com/datastax/oss/protocol/internal/SegmentCodec
    at com.datastax.oss.driver.internal.core.context.DefaultDriverContext.<init>(DefaultDriverContext.java:170)
    at com.datastax.oss.driver.api.core.session.SessionBuilder.buildContext(SessionBuilder.java:968)
    at com.datastax.oss.driver.api.core.session.SessionBuilder.buildDefaultSessionAsync(SessionBuilder.java:904)
    at com.datastax.oss.driver.api.core.session.SessionBuilder.buildAsync(SessionBuilder.java:817)
    at com.datastax.oss.driver.api.core.session.SessionBuilder.build(SessionBuilder.java:835)
    at org.janusgraph.diskstorage.cql.builder.CQLSessionBuilder.build(CQLSessionBuilder.java:81)
    at org.janusgraph.diskstorage.cql.CQLStoreManager.<init>(CQLStoreManager.java:137)
    at org.janusgraph.diskstorage.cql.CQLStoreManager.<init>(CQLStoreManager.java:118)
    ... 14 more
Caused by: java.lang.ClassNotFoundException: com.datastax.oss.protocol.internal.SegmentCodec
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 22 more

Process finished with exit code 1

代码

│   pom.xml
│
├───src
│   ├───main
│   │   ├───java
│   │   │       Main.java
│   │   │
│   │   └───resources
│   │       │   log4j2.xml
│   │       │
│   │       ├───conf
│   │       │       remote-graph.properties
│   │       │       remote-objects.yaml 

Main.java

import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;

public class Main {
    public static void main(String[] args) {
        JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
        janusGraph.close();
    }
}

remote-graph.properties

gremlin.remote.remoteConnectionClass=org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection
gremlin.remote.driver.clusterFile=src/main/resources/conf/remote-objects.yaml
gremlin.remote.driver.sourceName=g

远程对象.yaml

hosts: [localhost]
port: 18182
serializer: {
  className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0,
  config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}

pom.xml

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <version>2.20.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.janusgraph/janusgraph-core -->
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-core</artifactId>
            <version>1.0.0-20230504-014643.988c094</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.janusgraph/janusgraph-cql -->
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-cql</artifactId>
            <version>1.0.0-20230504-014643.988c094</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-core</artifactId>
            <version>3.6.2</version>
        </dependency>
        <dependency>
            <groupId>com.esri.geometry</groupId>
            <artifactId>esri-geometry-api</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>com.datastax.dse</groupId>
            <artifactId>dse-java-driver-core</artifactId>
            <version>2.4.0</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.15.0</version>
        </dependency>
    </dependencies>

janusgraph-cql.properties

# Copyright 2019 JanusGraph Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# JanusGraph configuration sample: Cassandra over a socket
#
# This file connects to a Cassandra daemon running on localhost via
# CQL.  Cassandra must already be started before starting JanusGraph
# with this file.

# The implementation of graph factory that will be used by gremlin server
#
# Default:    org.janusgraph.core.JanusGraphFactory
# Data Type:  String
# Mutability: LOCAL
gremlin.graph=org.janusgraph.core.JanusGraphFactory

# The primary persistence provider used by JanusGraph.  This is required. 
# It should be set one of JanusGraph's built-in shorthand names for its
# standard storage backends (shorthands: berkeleyje, cql, hbase, inmemory)
# or to the full package and classname of a custom/third-party
# StoreManager implementation.
#
# Default:    (no default value)
# Data Type:  String
# Mutability: LOCAL
storage.backend=cql

# The hostname or comma-separated list of hostnames of storage backend
# servers.  This is only applicable to some storage backends, such as
# cassandra and hbase.
#
# Default:    127.0.0.1
# Data Type:  class java.lang.String[]
# Mutability: LOCAL
storage.hostname=127.0.0.1

# The name of JanusGraph's keyspace.  It will be created if it does not
# exist.
#
# Default:    janusgraph
# Data Type:  String
# Mutability: LOCAL
storage.cql.keyspace=janusgraph

# The name of the local or closest Cassandra datacenter. This value will
# be passed into CqlSessionBuilder.withLocalDatacenter.
#
# Default:    datacenter1
# Data Type:  String
# Mutability: MASKABLE
storage.cql.local-datacenter=datacenter1

# Whether to enable JanusGraph's database-level cache, which is shared
# across all transactions. Enabling this option speeds up traversals by
# holding hot graph elements in memory, but also increases the likelihood
# of reading stale data.  Disabling it forces each transaction to
# independently fetch graph elements from storage before reading/writing
# them.
#
# Default:    false
# Data Type:  Boolean
# Mutability: MASKABLE
cache.db-cache = true

# How long, in milliseconds, database-level cache will keep entries after
# flushing them.  This option is only useful on distributed storage
# backends that are capable of acknowledging writes without necessarily
# making them immediately visible.
#
# Default:    50
# Data Type:  Integer
# Mutability: GLOBAL_OFFLINE
#
# Settings with mutability GLOBAL_OFFLINE are centrally managed in
# JanusGraph's storage backend.  After starting the database for the first
# time, this file's copy of this setting is ignored.  Use JanusGraph's
# Management System to read or modify this value after bootstrapping.
cache.db-cache-clean-wait = 20

# Default expiration time, in milliseconds, for entries in the
# database-level cache. Entries are evicted when they reach this age even
# if the cache has room to spare. Set to 0 to disable expiration (cache
# entries live forever or until memory pressure triggers eviction when set
# to 0).
#
# Default:    10000
# Data Type:  Long
# Mutability: GLOBAL_OFFLINE
#
# Settings with mutability GLOBAL_OFFLINE are centrally managed in
# JanusGraph's storage backend.  After starting the database for the first
# time, this file's copy of this setting is ignored.  Use JanusGraph's
# Management System to read or modify this value after bootstrapping.
cache.db-cache-time = 180000

# Size of JanusGraph's database level cache.  Values between 0 and 1 are
# interpreted as a percentage of VM heap, while larger values are
# interpreted as an absolute size in bytes.
#
# Default:    0.3
# Data Type:  Double
# Mutability: MASKABLE
cache.db-cache-size = 0.5

更新

更新1

janusgraph-core
janusgraph-cql
更新为相同版本:
1.0.0-20230504-014643.988c094
。 这仍然会产生相同的错误。

更新2

@李博轩 谢谢!这确实解决了我的问题!
添加

JanusGraph-CQL
后,Datastax.dse 似乎可以自行修复。 我一直在尝试解决他们注销时的错误。而且,我没想到现在要删除它们,因为出现了不同的错误日志。

java-11 cassandra-3.0 docker-container janusgraph maven-package
1个回答
5
投票

看起来像是库冲突问题。不确定这是否能解决问题,但我的建议是:

  1. janusgraph-core
    janusgraph-cql
    使用相同版本。目前您正在使用不同的(可能是冲突的)版本。
  2. 不要包含
    dse-java-driver-core
    依赖性。您需要的驱动程序作为
    janusgraph-cql
    的依赖项包含在内。

pom.xml

    <dependencies>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <version>2.20.0</version>
        </dependency>
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-core</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-cql</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
© www.soinside.com 2019 - 2024. All rights reserved.