clojurewerkz / cassaforte

Modern, high-level Clojure driver (client) for Cassandra build around CQL 3
http://clojurecassandra.info
123 stars 52 forks source link

Cassandra embedded daemon does not stop or deactivate #31

Closed alexkehayias closed 10 years ago

alexkehayias commented 10 years ago

In cassaforte.embedded, I noticed that stop-server! does not release the daemon created by start-server so you can't restart a daemon. Calling .deactivate and .stop does not stop the daemon. I'm doing some testing and it would be great to tear down a Cassandra daemon (start stop per test) as part of a fixture. Looking through your test code it looks like you start the daemon once for all tests and assume the jvm is shut down after (i.e lein test).

This issue seems to be further upstream http://cassandra-user-incubator-apache-org.3065146.n2.nabble.com/CassandraDaemon-deactivate-doesn-t-shutdown-Cassandra-td6882340.html, but was hoping there is a workaround that does not involve restarting the JVM.

ifesdjeen commented 10 years ago

Would you like to submit a pull request for it?)

alexkehayias commented 10 years ago

I'm looking for a workaround in CassandraDaemon as I believe that's where the issue is coming from. If I find a good workaround for restarting an embedded daemon within the same jvm session I'll send a PR.

Any other workarounds you can think of?

alexkehayias commented 10 years ago

After some more digging, the stop method of AbstractCassandraDaemon does not shutdown Cassandra, just the RPC server. It relies on jsvc to shut the rest down. http://svn.apache.org/repos/asf/cassandra/trunk/src/java/org/apache/cassandra/service/AbstractCassandraDaemon.java

This isn't a bug, just a feature request. Will need to experiment with an alternative way to starting/stopping c* for unittests.

ifesdjeen commented 10 years ago

May I ask you why you have to restart c* during test runs? I assumed that it's enough to shut it down once. Maybe we should just change an API to make it less confusing?

ifesdjeen commented 10 years ago

We can also wait for isRpcRunning to become true, and make this op synchronous. Also, we can add destroy call to make sure all allocated resources are freed.

alexkehayias commented 10 years ago

My intention was to do a clean build and tear down for unit tests that include cassandra. I would be able to start the db, run my tests, and tear it down (stop the server and get a new instance on subsequent start-server! calll). The current implementation means that the JVM needs to be stopped to kill the CassandraDaemon. If I were running the tests from the repl, I now have a c* hanging around and hope that I've cleaned up after the test properly. Developing at the repl would be confusing since I may be hitting c* which was created during a test.

ifesdjeen commented 10 years ago

Hm. I always run the embedded C* on a dedicated port, so i rarely run into that problem.

Although I can say that my embedded server is actually stopped... although can't start it back so far :/ trying to figure out what's going on.

ifesdjeen commented 10 years ago

Maybe there's a way to fork JVM and kill forked one..

alexkehayias commented 10 years ago

According to the code for CassandraDaemon, it is a decision to not shut down a daemon completely. Forking seems like a good solution. Maybe Runtime.exec or Process? Not sure how that works with the classpath of a project...

ifesdjeen commented 10 years ago

Yeah, trying to figure out some good way :) not sure so far, if you happen to run into something, let me know)

alexkehayias commented 10 years ago

Will do! Thanks

ifesdjeen commented 10 years ago

merged what I could :)