Cassandra Datastax Node.js driver can't find keyspace - node.js

Just installed Cassandra (3.11.1) and Datastax node.js driver (3.3.0).
Created a simple structure:
CREATE KEYSPACE CaseBox
WITH REPLICATION={
'class': 'SimpleStrategy',
'replication_factor': 1};
USE CaseBox;
CREATE TABLE Regions (
regionId int,
name varchar,
PRIMARY KEY ((regionId))
);
Trying connect to the keyspace with no success:
const client = new cassandra.Client({
contactPoints: ['localhost'],
keyspace: 'CaseBox'
});
await client.connect();
Error: Keyspace 'CaseBox' does not exist.
If I change the desired kayspace to system it works.
What's wrong? Please assist.
You can find my full Cassandra config, CQL and js scripts here.

Keyspace names are forced lower case when unquoted in CQL.
Use CREATE KEYSPACE "CaseBox" in CQL or keyspace: 'casebox' in Node.
Generally just use snake_case names as you won't get trapped like this as often.

Related

Creating keyspace on Cassandra

I am new to Cassandra, I wrote a blog in French that narrate all the unpleasant experiences that I have because of him (like always having Unable to find java executable when launching it after rebooting or the 7199 always already in use...). I created a github repository to share my cassandra directory.
But until now I can manage them unti this new one that didn't appeared last time I tried to launch Cassandra.
I try to create a keyspace about Cassandra with the help of the tutorialspoint tutorial but there is a problem: When I make the command to create a Keyspace:
;CREATE KEYSPACE k1 WITH
strategy_class = 'SimpleStrategy'
AND trategy_otpions:replication_factor = '1';
...
Or even :
cqlsh> CREATE KEYSPACE k1 WITH
... replication = {'class': 'strategy_class = 'SimpleStrategy'
... AND trategy_otpions:replication_factor = '1';
...
It just won't compile even after a semicolon ...
Do you have an idea ?
Do you have a good tutorial on Cassandra ?
Edit 28/11
I don't know why but this command worked :
cqlsh> CREATE KEYSPACE IF NOT EXISTS k1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
My next question will be on how to import a very large csv file one can found on the open platform of French public data there is at least 150 column which can all have the vartext type but the first one which is numeric.
I think your syntax for cqlsh it's wrong, if the one that you pasted is the one that you used.
The correct syntax for cqlsh is CREATE KEYSPACE test WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 3};.
For importing data from a csv file you should read on this https://docs.datastax.com/en/cql/3.3/cql/cql_using/useInsertCopyCSV.html

"Drop keyspace" command in cassandra

i created a key space named 'hello' in Cassandra and started using it(use command). so the commands were typed after cqlsh:hello> in the cql. i then dropped the key space hello, but still it is showing cqlsh:hello> at beginning of each command. why so ?
The keyspace is gone, but you need to reset your session context with the 'use' command.
cqlsh:test> create keyspace xyz with replication = {'class':'SimpleStrategy', 'replication_factor':1} ;
cqlsh:test> use xyz;
cqlsh:xyz> drop keyspace xyz;
cqlsh:xyz> describe keyspace
Keyspace 'xyz' not found.
cqlsh:xyz>

Cassandra NoHostAvailable: error in CQLSH

I just finished creating my table in cassandra. I attempted to insert data into the table and I was given this error:
cqlsh:test> INSERT into qw (id, user, pass, email, phoneNum) VALUES (1, 'scman', '123','sc#gmaail.com','123-456-7890');
NoHostAvailable:
I checked that my server was running. What could be causing this problem.
This is too late to answer. But I wanted to share my experience.
If you have a single node cluster and use NetworkTopologyStrategy, then it throws this error. Check your keyspace configuration.
Error during inserting data: NoHostAvailable:
My CQL command to update the replication
ALTER KEYSPACE my_keyspace WITH replication = {'class' : 'NetworkTopologyStrategy', 'DC1' : 1 ,'DC2' :2 };
was slightly different from the config files : conf/cassandra-rackdc.properties
# These properties are used with GossipingPropertyFileSnitch and will
# indicate the rack and dc for this node
dc=dc1
rack=rack1
resulting in a
cqlsh: my_keyspace> select * from world where message_id = 'hello_world';
NoHostAvailable:
the replication strategy is case sensitive and copy/paste from documentation may lead you to a mistake.
Fix : Changing the replication info so that it match the config files
ALTER KEYSPACE my_keyspace WITH replication = {'class' : 'NetworkTopologyStrategy', 'dc1' : 1 ,'dc2' :2 };
And execute on each node :
bin/nodetool repair --full my_keyspace
Got replication set on every node

Altering keyspace to change strategy class is not working in cassandra-cli

I have tried to alter the keypace with strategy class and options using below command in cassandra-cli of version cassandra 1.1.6 but it says 'Syntax error at position 0: no viable alternative at input 'ALTER'.
ALTER KEYSPACE system_auth WITH REPLICATION =
{'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2};
What is wrong here?
What is happening, is that you are using CQL syntax to update a keyspace from within the (deprecated) cassandra-cli tool. If you were using the cqlsh tool, your command would work just fine. But with cassandra-cli, that's not going to work. As Yasmeen indicated, the correct syntax that you will want to use is UPDATE KEYSPACE:
UPDATE KEYSPACE system_auth with placement_strategy = 'NetworkTopologyStrategy'
and strategy_options = {'dc1' : 3, 'dc2' : 2};
I do recommend that you use cqlsh in the future. The cassandra-cli is deprecated, and will not receive any further updates.
Also, you should also see about upgrading your cluster to a more recent version of Cassandra. While you are missing out on several new features, there have been many bugs fixed since 1.1.6 (bugs that you are probably running into).
UPDATE KEYSPACE demo
WITH placement_strategy = 'NetworkTopologyStrategy'
AND strategy_options = {'dc1' : 3, 'dc2' : 2};

Create a Cassandra keyspace with 'network topology' using Hector?

I want to create a Cassandra keyspace with 'network topology'. I can do it using CLI like this.
CREATE KEYSPACE test
WITH placement_strategy = 'NetworkTopologyStrategy'
AND strategy_options={us-east:6,us-west:3};
How can I achieve the same using Hector?
Thanks,
Bhathiya
You shouldn't do that. Back when Hector was the primary choice for a client driver, the recommendations were that you create your keyspace via the cassandra-CLI
Having said that, I would suggest that you use an up-to-date driver and recomend the DataStax binary protocol driver.
For the record, this works.
Map<String,String> options = new HashMap<String,String>();
options.put("dc1", "3");
options.put("dc2", "1");
ThriftKsDef kd = (ThriftKsDef) HFactory.createKeyspaceDefinition(keyspaceName,
strategyClass, replicationFactor, cfDefs);
if(options != null){
kd.setStrategyOptions(options);
}
getCluster().addKeyspace(kd, true);

Resources