cassandra-cql
cassandra-cql copied to clipboard
Set CQL3 consistency per connection
Not thread-safe as the assumption is you'll use one connection per thread.
Adapted from https://github.com/outoftime/cassandra-cql/pull/3
@ottbot Finally sending this upstream... sorry to let it lie fallow!
Can we mutex the with_consistency call so that this becomes thread safe again?
My initial assumption was that connections would not be shared between threads, but realistically one would probably be using some sort of connection pooling which makes this particular approach pretty bad.
How about as an alternative, #execute_cql_query
takes an options hash as its second argument, which allows :compression
and :consistency
? We could just raise an ArgumentError
if consistency were specified for a CQL2 connection. And it should be easy enough to check if the second argument is just a consistency argument directly for backwards compatibility.
If this seems reasonable I'd be glad to code it up and update this PR.
I think that makes a lot more sense. Its a breaking change but we can just bump the minor version and if you could slightly alter the README to let people know about the new API, that'd be fantastic.
Great! Although I don't think it has to be a breaking change if we just check the type of the second argument?
I suppose, but I prefer to minimize the overhead per query as much as possible and adding hash munging to it already makes me unhappy, though thats just how ruby rolls. We could write multiple methods and have RUBY_VERSION >= 2 use named keywords :)
OK, no strong objection here if you're down for a breaking change – do you think it's worth providing an alternate implementation for Ruby 2?
I know that hash setup/teardown is pretty gross for GC/CPU in ruby, but I've not specifically benchmarked the difference between using keyword arguments and a hash ... I don't know what ruby does under the hood for that. For now don't bother, maybe just add a TODO note or something.
Will do!