JanusGraph-PropertyKey 不是用户定义的密钥

2024-01-09

Problem

当我试图创建索引时,为什么 JanusGraph 会抛出用户定义键问题?

Logs

2023-05-08 12:40:25,640 [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])
2023-05-08 12:40:25,731 [INFO] [c.d.o.d.i.c.DefaultMavenCoordinates.main] ::     DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.15.0
2023-05-08 12:40:26,173 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] ::   Using native clock for microsecond precision
2023-05-08 12:40:26,414 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] ::     [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/127.0.0.1:9042, hostId=null, hashCode=6415177b)=null; please provide the correct local DC, or check your contact points
2023-05-08 12:40:26,643 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] ::   Generated unique-instance-id=c0a8563c15928-rmt-lap-win201
2023-05-08 12:40:26,657 [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])
2023-05-08 12:40:26,684 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] ::   Using native clock for microsecond precision
2023-05-08 12:40:26,724 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] ::     [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/[0:0:0:0:0:0:0:1]:9042, hostId=null, hashCode=114c356b)=null; please provide the correct local DC, or check your contact points
2023-05-08 12:40:26,739 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] ::  Initiated fixed thread pool of size 40
2023-05-08 12:40:26,845 [INFO] [o.j.g.d.StandardJanusGraph.main] ::  Gremlin script evaluation is disabled
2023-05-08 12:40:26,872 [INFO] [o.j.d.l.k.KCVSLog.main] ::   Loaded unidentified ReadMarker start time 2023-05-08T17:40:26.872018Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@8d8f754
Exception in thread "main" java.lang.IllegalArgumentException: Key must be a user defined key: null
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:220)
    at org.janusgraph.graphdb.database.management.ManagementSystem$IndexBuilder.addKey(ManagementSystem.java:789)
    at Main.main(Main.java:15)

Process finished with exit code 130

再生产

Steps

  1. 创建并启动Cassandra [Docker 容器] https://hub.docker.com/_/cassandra
  2. 创建并启动JanusGraph [Docker 容器] https://hub.docker.com/r/janusgraph/janusgraph(选修的)
  3. 使用 Maven 创建一个 Java 项目POM.XML
  4. 创建并添加log4j2.xml, remote-graph.properties, and remote-objects.yaml(选修的)
  5. Create-and-Run Main.java https://docs.janusgraph.org/schema/index-management/index-performance/ for Indexing using JanusGraphManagement https://javadoc.io/doc/org.janusgraph/janusgraph-core/0.1.1/org/janusgraph/core/schema/JanusGraphManagement.html
    1. PropertyKey()似乎是正确的,因为它在最新索引文件 https://docs.janusgraph.org/schema/
    2. MapReduceIndexManagement()似乎是错误的,因为它最新文档中没有 https://docs.janusgraph.org/v0.2/advanced-topics/index-admin/
    3. JanusGraphManagement 他们的例子没有显示一个例子 https://docs.janusgraph.org/schema/index-management/index-performance/他们如何上课他们自己的界面 https://javadoc.io/doc/org.janusgraph/janusgraph-core/0.1.1/org/janusgraph/core/schema/JanusGraphManagement.html
  6. Results
    1. 预期:要运行的程序
    2. Actually: Runtime Error java.lang.IllegalArgumentException: Key must be a user defined key: null
      1. 删除所有可选步骤仍然会产生相同的错误

Code

│   pom.xml
│
├───src
│   ├───main
│   │   ├───java
│   │   │       Main.java
│   │   │
│   │   └───resources
│   │       │   log4j2.xml

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-cql</artifactId>
            <version>1.0.0-20230504-014643.988c094</version>
        </dependency>
    </dependencies>

Main.java

import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.schema.JanusGraphManagement;

public class Main {
    public static void main(String[] args) {
        JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
        JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
        PropertyKey propertyKey = janusGraphManagement.getPropertyKey("_id");
        janusGraphManagement.buildIndex("_id", Vertex.class).addKey(propertyKey).buildCompositeIndex();
        janusGraphManagement.commit();
        janusGraph.close();
    }
}

这是修复方法。

PropertyKey propertyKey = janusGraphManagement.getOrCreatePropertyKey("_id");
2023-05-09 08:46:38,617 [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])
2023-05-09 08:46:38,689 [INFO] [c.d.o.d.i.c.DefaultMavenCoordinates.main] ::     DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.15.0
2023-05-09 08:46:39,124 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] ::   Using native clock for microsecond precision
2023-05-09 08:46:39,385 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] ::     [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/[0:0:0:0:0:0:0:1]:9042, hostId=null, hashCode=7b9f753a)=null; please provide the correct local DC, or check your contact points
2023-05-09 08:46:39,610 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] ::   Generated unique-instance-id=c0a8563c11168-rmt-lap-win201
2023-05-09 08:46:39,625 [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])
2023-05-09 08:46:39,651 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] ::   Using native clock for microsecond precision
2023-05-09 08:46:39,693 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] ::     [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/[0:0:0:0:0:0:0:1]:9042, hostId=null, hashCode=1ce6602a)=null; please provide the correct local DC, or check your contact points
2023-05-09 08:46:39,707 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] ::  Initiated fixed thread pool of size 40
2023-05-09 08:46:39,818 [INFO] [o.j.g.d.StandardJanusGraph.main] ::  Gremlin script evaluation is disabled
2023-05-09 08:46:39,844 [INFO] [o.j.d.l.k.KCVSLog.main] ::   Loaded unidentified ReadMarker start time 2023-05-09T13:46:39.844155Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@ff23ae7

Process finished with exit code 0

可能没有任何JanusGraphManagement方法就像set(), create(), insert(), make(), or add()对于新的PropertyKeys。但是,他们将获取和创造结合在一起,就像制作一个SQL SELECT-or-CREATE/INSERT or a Java Getter-and-Setter作为一种方法。

发现并意识到这一点让我陷入了困境。

import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.schema.JanusGraphManagement;

public class Main {
    public static void main(String[] args) {
        JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
        JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
        PropertyKey propertyKey = janusGraphManagement.getOrCreatePropertyKey("_id");
        janusGraphManagement.buildIndex("_id", Vertex.class).addKey(propertyKey).buildCompositeIndex();
        janusGraphManagement.commit();
        janusGraph.close();
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JanusGraph-PropertyKey 不是用户定义的密钥 的相关文章

随机推荐