You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Asif Jan <as...@gmail.com> on 2010/09/07 17:20:00 UTC

connect to cassandra using java


> Hi
>
> I need to use the low level java API in order to test bulk ingestion  
> to cassandra. I have already looked at the code in contrib/ 
> bmt_example and contrib/client_only.
>
> When I try and run the following code, I get following exception ;  
> using cassandra-cli I am able to see the "Keyspace1' and column  
> family 'Standard1' .
>
> 10/09/07 17:13:30 INFO config.DatabaseDescriptor: DiskAccessMode  
> 'auto' determined to be mmap, indexAccessMode is mmap
> Exception in thread "main" java.lang.IllegalArgumentException:  
> Unknown ColumnFamily Standard1 in keyspace Keyspace1
> 	at  
> org 
> .apache 
> .cassandra 
> .config.DatabaseDescriptor.getComparator(DatabaseDescriptor.java:1009)
> 	at  
> org 
> .apache.cassandra.db.ColumnFamily.getComparatorFor(ColumnFamily.java: 
> 418)
> 	at gaia.cu7.cassandra.input.Ingestor.main(Ingestor.java:93)
>
> How can I ensure that my program is connecting to already running  
> cassandra and not starting one in process. My program (taken from  
> client_only/bmt examples) is follows:
>
>         	System.setProperty("cassandra.config","/user/test/apache- 
> cassandra-0.7.0-beta1/conf/cassandra.yaml");
>                 final AbstractType comp =  
> ColumnFamily.getComparatorFor("Keyspace1", "Standard1", null);
>             for (int i = 0; i < 100; i++)
>             {
>                 RowMutation change = new RowMutation("Keyspace1",  
> ("key" + i).getBytes());
>                 ColumnPath cp = new  
> ColumnPath("Standard1").setColumn(("colb").getBytes());
>                 change.add(new QueryPath(cp), ("value" +  
> i).getBytes(), new TimestampClock(0));
>
>                 // don't call change.apply().  The reason is that is  
> makes a static call into Table, which will perform
>                 // local storage initialization, which creates local  
> directories.
>                 // change.apply();
>
>                 StorageProxy.mutate(Arrays.asList(change));
>                 System.out.println("wrote key" + i);
>             }
>
>
>
> I am using 0.7.0-beta1. Thanks a lot for your reply,
>
> Asif
>
>
>
>
>
>
>
>
>


Re: connect to cassandra using java

Posted by Asif Jan <as...@gmail.com>.
Thanks

once I am using cli script, it is able to connect to the local server  
and see all keyspaces etc. Do I still need to load schemas when using  
the same local server ?

Asif
On Sep 7, 2010, at 8:58 PM, Peter Harrison wrote:

> On Wed, Sep 8, 2010 at 3:20 AM, Asif Jan <as...@gmail.com> wrote:
>>
>>
>> Hi
>> I need to use the low level java API in order to test bulk  
>> ingestion to
>> cassandra. I have already looked at the code in contrib/bmt_example  
>> and
>> contrib/client_only.
>> When I try and run the following code, I get following exception ;  
>> using
>> cassandra-cli I am able to see the "Keyspace1' and column family  
>> 'Standard1'
>> .
>
> On the server you need to load the schema from the yaml. To do this  
> you will
> need to use jconsole to connect and run the schema load method. You  
> only
> need to do this once on a single node.
>
> I have written some code to load and drop keyspaces and column  
> families
> for hector; but I'm not quite happy with it yet. This will enable you
> to do everything
> programatically.


Re: connect to cassandra using java

Posted by Asif Jan <as...@gmail.com>.
On Sep 7, 2010, at 8:58 PM, Peter Harrison wrote:

> On Wed, Sep 8, 2010 at 3:20 AM, Asif Jan <as...@gmail.com> wrote:
>>
>>
>> Hi
>> I need to use the low level java API in order to test bulk  
>> ingestion to
>> cassandra. I have already looked at the code in contrib/bmt_example  
>> and
>> contrib/client_only.
>> When I try and run the following code, I get following exception ;  
>> using
>> cassandra-cli I am able to see the "Keyspace1' and column family  
>> 'Standard1'
>> .
>
> On the server you need to load the schema from the yaml. To do this  
> you will
> need to use jconsole to connect and run the schema load method. You  
> only
> need to do this once on a single node.

using jconsole to load schemas results in the following exception  
being generated.

Uncaught exception in thread Thread[MIGRATION-STAGE:1,5,main]
java.util.concurrent.ExecutionException:  
org.apache.cassandra.config.ConfigurationException: Cannot load from  
XML on top of pre-existing schemas.
	at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
	at java.util.concurrent.FutureTask.get(FutureTask.java:83)
	at  
org 
.apache 
.cassandra 
.concurrent 
.DebuggableThreadPoolExecutor 
.afterExecute(DebuggableThreadPoolExecutor.java:87)
	at java.util.concurrent.ThreadPoolExecutor 
$Worker.runTask(ThreadPoolExecutor.java:888)
	at java.util.concurrent.ThreadPoolExecutor 
$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:637)
Caused by: org.apache.cassandra.config.ConfigurationException: Cannot  
load from XML on top of pre-existing schemas.
	at org.apache.cassandra.service.StorageService 
$5.call(StorageService.java:1678)
	at org.apache.cassandra.service.StorageService 
$5.call(StorageService.java:1673)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor 
$Worker.runTask(ThreadPoolExecutor.java:886)



I understand from FAQ

http://wiki.apache.org/cassandra/FAQ#no_keyspaces

that keyspaces are not loaded by default. What could explain that I am  
able to see the kepspaces via CLI and not able to see when connecting  
to same cassandra instance via java.


Thanks a lot





>
> I have written some code to load and drop keyspaces and column  
> families
> for hector; but I'm not quite happy with it yet. This will enable you
> to do everything
> programatically.


Re: connect to cassandra using java

Posted by Peter Harrison <ch...@gmail.com>.
On Wed, Sep 8, 2010 at 3:20 AM, Asif Jan <as...@gmail.com> wrote:
>
>
> Hi
> I need to use the low level java API in order to test bulk ingestion to
> cassandra. I have already looked at the code in contrib/bmt_example and
> contrib/client_only.
> When I try and run the following code, I get following exception ; using
> cassandra-cli I am able to see the "Keyspace1' and column family 'Standard1'
> .

On the server you need to load the schema from the yaml. To do this you will
need to use jconsole to connect and run the schema load method. You only
need to do this once on a single node.

I have written some code to load and drop keyspaces and column families
for hector; but I'm not quite happy with it yet. This will enable you
to do everything
programatically.