You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Andriy Kopachevsky <ko...@gmail.com> on 2010/07/08 10:44:41 UTC

How to stop Cassandra running in embeded mode

Hi, we are trying to set up intergation testing for Cassanrda, so we need to
run and stop it as embeded service. Don't have any problem to start
cassandra:

import
org.apache.cassandra.contrib.utils.service.CassandraServiceDataCleaner;

class SomeTestClass {

    @Before
    public void setup() throws TTransportException, IOException,
InterruptedException {


        // make a tmp dir and copy storag-conf.xml and log4j.properties to
it
        copy("/storage-conf.xml", TMP);
        copy("/log4j.properties", TMP);
        System.setProperty("storage-config", TMP);

        cassandra = new EmbeddedCassandraService();
        cassandra.init();
        t = new Thread(cassandra);
        t.setDaemon(true);
        t.start();
   }
}

But this is real problem to stop it, even if you execute t.stop() all other
threads started up internally still alive. Is there are any way to force
cassandra to stop? Maybe invoke some internal cassandra api function or
anything. Thanks.
Andrey.

Re: How to stop Cassandra running in embeded mode

Posted by Jesse McConnell <je...@gmail.com>.
separate jvm is the only mechanism to 'shutdown' in a test scenario
right now....and its unlikely to change in the short term so designing
around forking is your best bet

cheers,
jesse

--
jesse mcconnell
jesse.mcconnell@gmail.com



On Tue, Jul 20, 2010 at 05:47, Bjorn Borud <bb...@gmail.com> wrote:
> Jonathan Ellis <jb...@gmail.com> writes:
>
>> there's some support for this in 0.7 (see
>> http://issues.apache.org/jira/browse/CASSANDRA-1018) but fundamentally
>> it's not really designed to be started and stopped multiple times
>> within the same process.
>
> I am currently struggling with some of the same issues (on 0.6.3).
>
> I think there are very valid reasons for being able to start and stop
> Cassandra within the same JVM. in particular for various testing-related
> scenarios, but also when one wants to experiment with embedding
> Cassandra. (Having a single-node, embedded Cassandra can be great for
> testing Cassandra-based applications without forcing "casual users" to
> go through the ordeal of installing Cassandra).
>
> Right now I have an ungodly mess that attempts to embed Cassandra by
> wrapping the CassandraDaemon, generating a directory hierarchy for it
> and populating the storage-conf.xml by way of a templating system and
> then fires up Cassandra.
> It *sort of* works, except that I haven't found a way to shut Cassandra
> down reliably. the stop() method doesn't really do anything useful in
> this respect. (I'd prefer some way of being able to ask it to shut down
> and then have some way of blocking until it is down). I think some of
> the errors I am seeing (NPE at at
> org.apache.cassandra.db.commitlog.CommitLog.recover(CommitLog.java:166))
> are probably due to some race condition because of this, but I am
> guessing here.
>
> I'll have another stare at the source.
>
> -Bjørn
>
>
>

Re: How to stop Cassandra running in embeded mode

Posted by Bjorn Borud <bb...@gmail.com>.
Jonathan Ellis <jb...@gmail.com> writes:

> there's some support for this in 0.7 (see
> http://issues.apache.org/jira/browse/CASSANDRA-1018) but fundamentally
> it's not really designed to be started and stopped multiple times
> within the same process.

I am currently struggling with some of the same issues (on 0.6.3). 

I think there are very valid reasons for being able to start and stop
Cassandra within the same JVM. in particular for various testing-related
scenarios, but also when one wants to experiment with embedding
Cassandra. (Having a single-node, embedded Cassandra can be great for
testing Cassandra-based applications without forcing "casual users" to
go through the ordeal of installing Cassandra).

Right now I have an ungodly mess that attempts to embed Cassandra by
wrapping the CassandraDaemon, generating a directory hierarchy for it
and populating the storage-conf.xml by way of a templating system and
then fires up Cassandra. 
It *sort of* works, except that I haven't found a way to shut Cassandra
down reliably. the stop() method doesn't really do anything useful in
this respect. (I'd prefer some way of being able to ask it to shut down
and then have some way of blocking until it is down). I think some of
the errors I am seeing (NPE at at
org.apache.cassandra.db.commitlog.CommitLog.recover(CommitLog.java:166))
are probably due to some race condition because of this, but I am
guessing here.

I'll have another stare at the source.

-Bjørn



Re: How to stop Cassandra running in embeded mode

Posted by Ran Tavory <ra...@gmail.com>.
look at my pom. it has <forkMode>always</
http://github.com/rantav/hector/blob/master/pom.xml#L95

On Wed, Jul 14, 2010 at 3:02 PM, Andriy Kopachevsky
<ko...@gmail.com>wrote:

> Ran, I do know to run jest in own thread with maven surefire plugin, but
> don't sure how can I do this with own JVM for each test. How are you doing
> this? Thanks.
>
>
> On Fri, Jul 9, 2010 at 10:33 PM, Ran Tavory <ra...@gmail.com> wrote:
>
>> The workaround I do is fork always. Each test pulls up its own jvm.
>>
>> On Jul 9, 2010 9:51 PM, "Jonathan Ellis" <jb...@gmail.com> wrote:
>>
>> there's some support for this in 0.7 (see
>> http://issues.apache.org/jira/browse/CASSANDRA-1018) but fundamentally
>> it's not really designed to be started and stopped multiple times
>> within the same process.
>>
>>
>> On Thu, Jul 8, 2010 at 3:44 AM, Andriy Kopachevsky
>> <ko...@gmail.com> wrote:
>> > Hi, we are tryi...
>>
>> --
>>
>> Jonathan Ellis
>> Project Chair, Apache Cassandra
>> co-founder of Riptano, the source for professional Cassandra support
>> http://riptano.com
>>
>>
>

Re: How to stop Cassandra running in embeded mode

Posted by Andriy Kopachevsky <ko...@gmail.com>.
Ran, I do know to run jest in own thread with maven surefire plugin, but
don't sure how can I do this with own JVM for each test. How are you doing
this? Thanks.

On Fri, Jul 9, 2010 at 10:33 PM, Ran Tavory <ra...@gmail.com> wrote:

> The workaround I do is fork always. Each test pulls up its own jvm.
>
> On Jul 9, 2010 9:51 PM, "Jonathan Ellis" <jb...@gmail.com> wrote:
>
> there's some support for this in 0.7 (see
> http://issues.apache.org/jira/browse/CASSANDRA-1018) but fundamentally
> it's not really designed to be started and stopped multiple times
> within the same process.
>
>
> On Thu, Jul 8, 2010 at 3:44 AM, Andriy Kopachevsky
> <ko...@gmail.com> wrote:
> > Hi, we are tryi...
> --
>
> Jonathan Ellis
> Project Chair, Apache Cassandra
> co-founder of Riptano, the source for professional Cassandra support
> http://riptano.com
>
>

Re: How to stop Cassandra running in embeded mode

Posted by Ran Tavory <ra...@gmail.com>.
The workaround I do is fork always. Each test pulls up its own jvm.

On Jul 9, 2010 9:51 PM, "Jonathan Ellis" <jb...@gmail.com> wrote:

there's some support for this in 0.7 (see
http://issues.apache.org/jira/browse/CASSANDRA-1018) but fundamentally
it's not really designed to be started and stopped multiple times
within the same process.


On Thu, Jul 8, 2010 at 3:44 AM, Andriy Kopachevsky
<ko...@gmail.com> wrote:
> Hi, we are tryi...
--
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of Riptano, the source for professional Cassandra support
http://riptano.com

Re: How to stop Cassandra running in embeded mode

Posted by Jonathan Ellis <jb...@gmail.com>.
there's some support for this in 0.7 (see
http://issues.apache.org/jira/browse/CASSANDRA-1018) but fundamentally
it's not really designed to be started and stopped multiple times
within the same process.

On Thu, Jul 8, 2010 at 3:44 AM, Andriy Kopachevsky
<ko...@gmail.com> wrote:
> Hi, we are trying to set up intergation testing for Cassanrda, so we need to
> run and stop it as embeded service. Don't have any problem to start
> cassandra:
>
> import
> org.apache.cassandra.contrib.utils.service.CassandraServiceDataCleaner;
>
> class SomeTestClass {
>
>     @Before
>     public void setup() throws TTransportException, IOException,
> InterruptedException {
>
>
>         // make a tmp dir and copy storag-conf.xml and log4j.properties to
> it
>         copy("/storage-conf.xml", TMP);
>         copy("/log4j.properties", TMP);
>         System.setProperty("storage-config", TMP);
>
>         cassandra = new EmbeddedCassandraService();
>         cassandra.init();
>         t = new Thread(cassandra);
>         t.setDaemon(true);
>         t.start();
>    }
> }
>
> But this is real problem to stop it, even if you execute t.stop() all other
> threads started up internally still alive. Is there are any way to force
> cassandra to stop? Maybe invoke some internal cassandra api function or
> anything. Thanks.
> Andrey.
>



-- 
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of Riptano, the source for professional Cassandra support
http://riptano.com