NullPointException when trying to create index

28 views
Skip to first unread message

krakolas

unread,
Jan 20, 2017, 4:57:44 PM1/20/17
to Aurelius
Hello all, 

I have just started into Titan, and based on the Titan 1.0.0 documentation I have been trying to complete a simple Java program to create a graph, add a vertex to it and then create a index to it. 

Here is code in its entirety: 

package com.infor.titan.pizza;


import com.thinkaurelius.titan.core.PropertyKey;

import com.thinkaurelius.titan.core.TitanFactory;

import com.thinkaurelius.titan.core.TitanGraph;

import com.thinkaurelius.titan.core.VertexLabel;

import com.thinkaurelius.titan.core.schema.SchemaAction;

import com.thinkaurelius.titan.core.schema.TitanManagement.IndexBuilder;

import com.thinkaurelius.titan.graphdb.database.management.ManagementSystem;



import org.apache.tinkerpop.gremlin.structure.Vertex;




public class SimpleGraph {

public static final String PROPS_PATH = "config/titan-cassandra.properties";

public static void main(String[] args) {

ManagementSystem mgmt;


TitanGraph graph = TitanFactory.build().set("storage.backend", "cassandra")

        .set("storage.hostname", "127.0.0.1")

.open();

graph.addVertex("name", "stephen");

graph.tx().commit();

//

graph.tx().rollback();


mgmt =  (ManagementSystem) graph.openManagement();

PropertyKey name = mgmt.getPropertyKey("name");

VertexLabel restaurant = mgmt.getVertexLabel("restaurant");

IndexBuilder nameAndLabelmgmt.buildIndex("byNameAndLabel", Vertex.class).addKey(name).indexOnly(restaurant);

mgmt.commit();


try {

ManagementSystem.awaitGraphIndexStatus(graph, "byNameAndLabel" ).call();

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


mgmt = (ManagementSystem) graph.openManagement();

mgmt.updateIndex(mgmt.getGraphIndex("byNameAndLabel"), SchemaAction.REINDEX);

mgmt.commit();

 

}


}



However when I execute, I am getting a NPE on the line where I call for the index status (highlighted in yellow) above. Here is the complete stack trace that is being thrown out. 

16:18:37,903  INFO ConnectionPoolMBeanManager:53 - Registering mbean: com.netflix.MonitoredResources:type=ASTYANAX,name=ClusterTitanConnectionPool,ServiceType=connectionpool


16:18:37,919  INFO CountingConnectionPoolMonitor:194 - AddHost: 127.0.0.1


16:18:38,035  INFO ConnectionPoolMBeanManager:53 - Registering mbean: com.netflix.MonitoredResources:type=ASTYANAX,name=KeyspaceTitanConnectionPool,ServiceType=connectionpool


16:18:38,035  INFO CountingConnectionPoolMonitor:194 - AddHost: 127.0.0.1


16:18:38,216  INFO GraphDatabaseConfiguration:1518 - Generated unique-instance-id=0a27c83664433-usalnmdebarr04-infor-com1


16:18:38,228  INFO ConnectionPoolMBeanManager:53 - Registering mbean: com.netflix.MonitoredResources:type=ASTYANAX,name=ClusterTitanConnectionPool,ServiceType=connectionpool


16:18:38,229  INFO CountingConnectionPoolMonitor:194 - AddHost: 127.0.0.1


16:18:38,232  INFO ConnectionPoolMBeanManager:53 - Registering mbean: com.netflix.MonitoredResources:type=ASTYANAX,name=KeyspaceTitanConnectionPool,ServiceType=connectionpool


16:18:38,232  INFO CountingConnectionPoolMonitor:194 - AddHost: 127.0.0.1


16:18:38,246  INFO Backend:176 - Initiated backend operations thread pool of size 8


16:18:38,279  INFO Backend:254 - Configuring total store cache size: 1886412760


16:18:38,363  INFO KCVSLog:730 - Loaded unidentified ReadMarker start time 2017-01-20T21:18:38.350Z into com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLog$MessagePuller@6fa34d52


Exception in thread "main" java.lang.NullPointerException


        at com.thinkaurelius.titan.graphdb.database.management.GraphIndexStatusWatcher.call(GraphIndexStatusWatcher.java:52)


        at com.infor.titan.pizza.SimpleGraph.main(SimpleGraph.java:48)


I am not sure if it matters, but my titan server is running locally with both cassandra and elastic search embedded. I tried to debug and walk through the code, and both the graph and index objects are valid before that call. 

Any ideas, on what I may be missing? 

Thanks in advance for any suggestions or help. 

Regards, 

--MD. 



Jason Plurad

unread,
Jan 21, 2017, 11:35:52 AM1/21/17
to Aurelius
You only created the index builder, so you're missing the call to actually build the index. Try something like this:

IndexBuilder nameAndLabel =  mgmt.buildIndex("byNameAndLabel", Vertex.class).addKey(name).indexOnly(restaurant);
TitanGraphIndex byNameAndLabel = nameAndLabel.buildCompositeIndex();

-- Jason

krakolas

unread,
Jan 23, 2017, 9:54:59 AM1/23/17
to Aurelius
Hi Jason, 

Thank you for pointing that out. After I add the call to build the index, I still get the NPe, but not it gets thrown by something else:
09:52:13,096  INFO Backend:176 - Initiated backend operations thread pool of size 8

09:52:13,260  INFO KCVSLog:730 - Loaded unidentified ReadMarker start time 2017-01-23T14:52:13.237Z into com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLog$MessagePuller@5495333e

Exception in thread "main" java.lang.NullPointerException

at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210)

at com.thinkaurelius.titan.graphdb.database.management.ManagementSystem$IndexBuilder.indexOnly(ManagementSystem.java:613)

at com.infor.titan.pizza.SimpleGraph.main(SimpleGraph.java:41)



krakolas

unread,
Jan 23, 2017, 1:15:58 PM1/23/17
to Aurelius
I figured out the last problem later on my own. I had some confusion between the label and the property name when defining it on the graph schema. It turns out the property key "name" was not defined properly and it was indeed null when I was building the index. 
Reply all
Reply to author
Forward
0 new messages