Can not connect to graph with Cassandra as backend

1,036 views
Skip to first unread message

代栋

unread,
Dec 17, 2015, 3:40:18 PM12/17/15
to Aurelius
Hi, all, I am writing a java client with Titan to connect to a Cassandra cluster as backend server. Things got broken and I can not figure out why. Thanks very much if you can help me here. 

I am trying the Remote Server Mode. I installed Cassandra cluster which operates well using cqlsh tool. It is 3.0.1.

After that, I created a maven project with dependencies including: titan-core(1.0.0) and titan-cassandra(1.0.0).

I follow the page:http://s3.thinkaurelius.com/docs/titan/1.0.0/cassandra.html to init the graph like this:
TitanGraph graph = TitanFactory.build().
set("storage.backend", "cassandra").
set("storage.hostname", "77.77.77.77").
open();

It replies me with this error:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
12:06:09.689 [main] DEBUG c.t.t.d.c.a.AstyanaxStoreManager - About to instantiate class public com.netflix.astyanax.connectionpool.impl.FixedRetryBackoffStrategy(int,int) with 2 arguments
12:06:09.692 [main] DEBUG c.t.t.d.c.a.AstyanaxStoreManager - Instantiated RetryBackoffStrategy object com.netflix.astyanax.connectionpool.impl.FixedRetryBackoffStrategy@543788f3 from config string "com.netflix.astyanax.connectionpool.impl.FixedRetryBackoffStrategy,1000,5000"
12:06:09.693 [main] DEBUG c.t.t.d.c.a.AstyanaxStoreManager - About to instantiate class public com.netflix.astyanax.retry.BoundedExponentialBackoff(long,long,int) with 3 arguments
12:06:09.694 [main] DEBUG c.t.t.d.c.a.AstyanaxStoreManager - Instantiated RetryPolicy object com.netflix.astyanax.retry.BoundedExponentialBackoff@15bfd87[maxSleepTimeMs=25000,MAX_SHIFT=30,random=java.util.Random@3d0f8e03,baseSleepTimeMs=100,maxAttempts=8,attempts=0] from config string "com.netflix.astyanax.retry.BoundedExponentialBackoff,100,25000,8"
12:06:09.705 [main] DEBUG c.t.t.d.c.a.AstyanaxStoreManager - Custom RetryBackoffStrategy com.netflix.astyanax.connectionpool.impl.FixedRetryBackoffStrategy@543788f3
12:06:09.906 [main] INFO  c.n.a.c.i.ConnectionPoolMBeanManager - Registering mbean: com.netflix.MonitoredResources:type=ASTYANAX,name=ClusterTitanConnectionPool,ServiceType=connectionpool
12:06:09.915 [main] INFO  c.n.a.c.i.CountingConnectionPoolMonitor - AddHost: 128.110.96.155
12:06:09.931 [pool-4-thread-1] DEBUG c.n.astyanax.thrift.ThriftConverter - java.net.ConnectException: Connection refused
12:06:19.924 [main] DEBUG c.t.t.d.c.a.AstyanaxStoreManager - Failed to describe keyspace titan
12:06:19.933 [main] DEBUG c.t.t.d.c.a.AstyanaxStoreManager - Creating keyspace titan...
12:06:19.957 [pool-4-thread-1] DEBUG c.n.astyanax.thrift.ThriftConverter - java.net.ConnectException: Connection refused

Is there any reason causing this connection refused?
After googling a while, i also tried cassandrathrift as the backend server, but it still fails, with a different error:

Exception in thread "main" java.lang.IllegalArgumentException: Could not instantiate implementation: com.thinkaurelius.titan.diskstorage.cassandra.thrift.CassandraThriftStoreManager
at com.thinkaurelius.titan.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:55)
at com.thinkaurelius.titan.diskstorage.Backend.getImplementationClass(Backend.java:473)
at com.thinkaurelius.titan.diskstorage.Backend.getStorageManager(Backend.java:407)
at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.<init>(GraphDatabaseConfiguration.java:1320)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:94)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:84)
at com.thinkaurelius.titan.core.TitanFactory$Builder.open(TitanFactory.java:139)
at edu.prism.TitanApp.initConnection(TitanApp.java:12)
at edu.prism.TitanApp.main(TitanApp.java:20)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.thinkaurelius.titan.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:44)
... 8 more
Caused by: com.thinkaurelius.titan.diskstorage.TemporaryBackendException: Temporary failure in storage backend
at com.thinkaurelius.titan.diskstorage.cassandra.thrift.CassandraThriftStoreManager.getCassandraPartitioner(CassandraThriftStoreManager.java:208)
at com.thinkaurelius.titan.diskstorage.cassandra.thrift.CassandraThriftStoreManager.<init>(CassandraThriftStoreManager.java:186)
... 13 more
Caused by: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused
at org.apache.thrift.transport.TSocket.open(TSocket.java:187)
at org.apache.thrift.transport.TFramedTransport.open(TFramedTransport.java:81)
at com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnectionFactory.makeRawConnection(CTConnectionFactory.java:88)
at com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnectionFactory.makeObject(CTConnectionFactory.java:52)
at com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnectionFactory.makeObject(CTConnectionFactory.java:21)
at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:1220)
at com.thinkaurelius.titan.diskstorage.cassandra.thrift.CassandraThriftStoreManager.getCassandraPartitioner(CassandraThriftStoreManager.java:205)
... 14 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.thrift.transport.TSocket.open(TSocket.java:182)
... 20 more


Any suggestion will be great! And, most importantly, I find it is very hard to find some example codes for Titan-1.0.0 using Java. There are all kinds of different APIs and ways to write Titan client codes. I am not sure which one will work and I am not sure whether they are good for the latest version of Titan. Could you please give me some reference implementation if you are aware of some?

thanks!
- Dong

David

unread,
Dec 17, 2015, 7:51:44 PM12/17/15
to Aurelius
package example.com;

import java.util.Iterator;

import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import org.apache.commons.configuration.BaseConfiguration;

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;

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

/**
* Basic Java Program For Titan 1.X on Cassandra 2.2.3
* NO idea if this runs on Cassandra 3.x
* Anything past 2.1.9 is a bit risky at the moment
*/
public class SampleTitanProgram
{
public static void main(String args[])
{
SampleTitanProgram me = new SampleTitanProgram();
me.doWork();
}

private void doWork()
{
TitanGraph tg = null;
try
{
// build up a configuration.
BaseConfiguration conf = new BaseConfiguration();
// or cassandra
conf.setProperty("storage.backend", "cassandrathrift");
conf.setProperty("storage.hostname", "11.95.61.231,11.95.61.230,11.95.61.238");
conf.setProperty("storage.cassandra.keyspace", "titan");

tg = TitanFactory.open(conf);
Vertex v1 = tg.addVertex("keyone", "valueone");
Vertex v2 = tg.addVertex("keytwo", "valuetwo");

Edge e1 = v1.addEdge("fromOneToTwo", v2, "weight", 1.0);

GraphTraversalSource gts = tg.traversal();
Vertex v3 = gts.V().has("keyone", "valueone").out().next();

Iterator<VertexProperty<String>> itr1 = v3.properties();
while (itr1.hasNext())
{
VertexProperty vp = itr1.next();
System.out.println("key value pair is: " + vp.key() + ": " + vp.value());
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
// should check if tg is null first
tg.close();
}
}
}

testit.jar in the execution line contains the compiled class above.

Put all jars in titan lib directory in your classpath in addition to testit.jar to run this:

java -cp /whateverpath/titanbuild/titan/lib/*:/whateverpath/testit.jar com.example.SampleTitanProgram

David

unread,
Dec 17, 2015, 7:53:35 PM12/17/15
to Aurelius
Error correction

java -cp /whateverpath/titanbuild/titan/lib/*:/whateverpath/testit.jar example.com.SampleTitanProgram

Jason Plurad

unread,
Dec 17, 2015, 10:31:27 PM12/17/15
to Aurelius
Hi Dong,

Your stack traces are showing ConnectionExceptions to Cassandra over thrift. You didn't mention what version of Cassandra you have, but make sure you enable thrift on your Cassandra nodes. It is disabled by default on Cassandra 2.2 and higher.

1. update ./conf/cassandra.yaml before starting the node


# Whether to start the thrift rpc server.
start_rpc
: true

# The address or interface to bind the Thrift RPC service and native transport
# server to.
#
# Set rpc_address OR rpc_interface, not both. Interfaces must correspond
# to a single address, IP aliasing is not supported.
#
rpc_address
: 77.77.77.77


2. or if the node is already running


./bin/nodetool enablethrift



-- Jason

Laxmikant Patil

unread,
Jan 18, 2016, 9:54:24 PM1/18/16
to Aurelius
Hi David,

Here in your code you are creating graph. But how does it actually stored in Cassandra? How do I retrieve it later if I just want to use it later?

Stephen Mallette

unread,
Jan 20, 2016, 7:03:30 AM1/20/16
to Aurelius
I'm not sure what you are asking, but a TitanGraph is an abstraction over databases like Cassandra.  When you make method calls on it, like addVertex(), to build your graph it stores that data there on commit.  You would only later access that data through a TitanGraph instance - the data is encoded in cassandra so you won't be able to easily make sense of it with CQL or anything like that.

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/d44eda09-3ebc-43ed-9890-fbaedaf19316%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages