import org.apache.commons.configuration.BaseConfiguration;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.Cardinality;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.schema.JanusGraphIndex;
import org.janusgraph.core.schema.JanusGraphManagement;
import org.janusgraph.core.schema.SchemaAction;
import org.janusgraph.core.schema.SchemaStatus;
import org.janusgraph.graphdb.database.management.ManagementSystem;
/**
* Created by 苦苦奋斗的渣渣 on 2017/7/18.
*/
public class GraphTest {
public static void main(String[] args) throws Exception {
BaseConfiguration baseConfiguration = new BaseConfiguration();
baseConfiguration.setProperty("storage.backend", "hbase");
baseConfiguration.setProperty("storage.hostname", "192.168.1.108");
baseConfiguration.setProperty("gremlin.graph", "org.janusgraph.core.JanusGraphFactory");
JanusGraph janusGraph = JanusGraphFactory.open(baseConfiguration);
GraphTraversalSource g = janusGraph.traversal();
JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
janusGraphManagement.makePropertyKey("phone").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
janusGraphManagement.commit();
g.tx().commit();
janusGraph.tx().rollback();
janusGraphManagement = janusGraph.openManagement();
janusGraphManagement.buildIndex("phoneIndex", Vertex.class).addKey(janusGraphManagement.getPropertyKey("phone")).unique().buildCompositeIndex();
janusGraphManagement.commit();
g.tx().commit();
ManagementSystem.awaitGraphIndexStatus(janusGraph, "phoneIndex")
.status(SchemaStatus.REGISTERED)
.call();
janusGraphManagement = janusGraph.openManagement();
JanusGraphIndex phoneIndex = janusGraphManagement.getGraphIndex("phoneIndex");
janusGraphManagement.updateIndex(phoneIndex, SchemaAction.REINDEX);
janusGraphManagement.commit();
janusGraph.tx().commit();
System.out.println("---------------------rebuldindexsucess...");
}
}
with this code, when i clean all data in hbase, and then try to build index, the index status can change to enable, but second time to build other index, it cant change to enable. why this problem have beset me few days, please help me
Kind of the same issue here:
When I build an index on a new propertykey the index is immediately ENABLED as it should but when I build an index on an existing propertykey the index gets stuck on INSTALLED and won't go to REGISTERED.
I used the example code from the docs at chapter 8.2.1.1. Index Uniqueness. Tried it for existing and non-existing indexes and executed it in both Gremlin Console and in Scala/Java. My JanusGraph version is a 0.2.0-SNAPSHOT which I build about 8 days ago.
UPDATE:
I was using JanusGraph from within a ScalaNotebook which is a bit of a playground for my projects. I can test blocks of code quickly but blocks can get bugged. I am trying to use a notebook to manage my indexes but I am not always able to close the graphs nicely when I shutdown or restart my notebooks.
I had a bug on creating an index and the status got stuck at "INSTALLED". While having this instance running and also connecting from Gremlin Console I was not able to REGISTER_INDEX because it seemed locked. graph.close() is able to resolved this lock but sometimes my graph objects were deleted or lost before I 'closed' them.
So.. I had to search for openInstances to list all registered instances (of which some are lost / not resumable) and manually close those instances. After this I was able to nudge the index to registered (SchemaAction.REGISTER_INDEX).
To prevent confusion we have recently added a default template for new issues containing the guidelines as to what belongs in issues. Usage, configuration, and general questions should be asked in gitter, stackoverflow, or the janusgraph-users google group. Github issues are for reporting bugs, requesting new features, and tracking the development of JanusGraph. If your issue is still outstanding please consult one of the communities mentioned. If you still feel like your issue belongs here and was closed in error please feel free to repoen it.
Most helpful comment
Kind of the same issue here:
When I build an index on a new propertykey the index is immediately ENABLED as it should but when I build an index on an existing propertykey the index gets stuck on INSTALLED and won't go to REGISTERED.
I used the example code from the docs at chapter 8.2.1.1. Index Uniqueness. Tried it for existing and non-existing indexes and executed it in both Gremlin Console and in Scala/Java. My JanusGraph version is a 0.2.0-SNAPSHOT which I build about 8 days ago.
UPDATE:
I was using JanusGraph from within a ScalaNotebook which is a bit of a playground for my projects. I can test blocks of code quickly but blocks can get bugged. I am trying to use a notebook to manage my indexes but I am not always able to close the graphs nicely when I shutdown or restart my notebooks.
I had a bug on creating an index and the status got stuck at "INSTALLED". While having this instance running and also connecting from Gremlin Console I was not able to REGISTER_INDEX because it seemed locked. graph.close() is able to resolved this lock but sometimes my graph objects were deleted or lost before I 'closed' them.
So.. I had to search for openInstances to list all registered instances (of which some are lost / not resumable) and manually close those instances. After this I was able to nudge the index to registered (SchemaAction.REGISTER_INDEX).