Is o.s.c.p.KeyspaceManager meant to be threadsafe?

8 views
Skip to first unread message

Andrew Swan

unread,
Oct 8, 2012, 10:14:47 PM10/8/12
to sca...@googlegroups.com
When I have multiple threads trying to use a single KeyspaceManager, I get Thrift errors such as:

org.apache.thrift.transport.TTransportException: Cannot write to null outputStream

If it's not threadsafe:
  • Could you please add that fact to its JavaDoc
  • Suggest how I can use it in a multi-threaded environment; at the moment I create a new instance for each invocation, which seems a little expensive given that the superclass constructor calls Cluster.getNodes(), which in turn uses locking.
Cheers,

Andrew

Dan Washusen

unread,
Oct 8, 2012, 10:47:10 PM10/8/12
to sca...@googlegroups.com
To my knowledge the code itself is thread safe but I haven't tested or used it in a multithreaded environment…

What's the use case? I'd avoid using it (or anything for that matter) to make concurrent changes to a cluster...

-- 
Dan Washusen
Make big files fly

Andrew Swan

unread,
Oct 10, 2012, 12:38:22 AM10/10/12
to sca...@googlegroups.com
My use case is that I'm writing a RESTful service for managing keyspaces and column families.

I hear what you say about making concurrent changes to a cluster, but the thread safety issue appears even when calling KeyspaceManager#getKeyspaceNames(), which is presumably a read-only operation.

Andrew

Dan Washusen

unread,
Oct 10, 2012, 12:45:08 AM10/10/12
to sca...@googlegroups.com
Interesting…each IManagerOperation opens a new connection (no pooling etc) so it doesn't look like any state is shared as far as Pelops is concerned… 

-- 
Dan Washusen
Make big files fly

Andrew Swan

unread,
Oct 10, 2012, 1:01:52 AM10/10/12
to sca...@googlegroups.com
But what about KeyspaceManager's inherited openClient() method, which uses a class-scoped IConnection instance? Wouldn't that create the potential for conflict between threads? It would certainly explain why my threading issue was fixed by switching from a single KeyspaceManager to a new one for each operation...

Andrew

Dan Washusen

unread,
Oct 10, 2012, 1:08:54 AM10/10/12
to sca...@googlegroups.com
Ah, sorry, yes you're right…KeyspaceManager extending ManagerOperand seems a bit…silly... 

-- 
Dan Washusen
Make big files fly

Andrew Swan

unread,
Oct 10, 2012, 1:18:33 AM10/10/12
to sca...@googlegroups.com
So should I open a ticket about making KeyspaceManager threadsafe?

Dan Washusen

unread,
Oct 10, 2012, 1:35:42 AM10/10/12
to sca...@googlegroups.com
I'm good with that...

-- 
Dan Washusen
Make big files fly

Andrew Swan

unread,
Oct 10, 2012, 4:07:21 AM10/10/12
to sca...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages