0
votes

I am pretty new to Cassandra so forgive me when I have some fundamental misunderstanding of the concept of keyspaces. What I am trying to do is to set up a multi datacenter ring in different regions with data replication NetworkTopologyStrategy endpoint_snitch set to GossipingPropertyFileSnitch hence as explained in the docs I need set the replication strategy for a keyspace

 CREATE KEYSPACE "mykey"
    WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 2, 'dc2' : 2};

i also read that in cql i can do "use mykey" to set the keyspace

would that be persistantly set then in the cassandra configurtation? As far as i understand each application client in a cluster uses its own keyspace right. Hence i would need to set this in the application??

The examples only show how to create a keyspace for configuring replication strategy options. I i think i managed to understand the basics behind it. What i am looking for is examples how i would tell cassandra to use a certain keyspace strategy (consistently and/or application dependent).

I digged some more in the cassandra docs and think i got a better aubderstanding about the use of keyspace. Am i correct in that for telling cassandra to use a certain keyspace i can create keyspace like so

CREATE KEYSPACE "MyKey" WITH replication = {'class':  
'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;

and then create tables in this keyspace like so

 CREATE TABLE "MyKey"."TableName" (
 ...

Would this make cassandra to always use the configured replication strategy in the "MyKey" keyspace for that table?

1

1 Answers

0
votes

"As far as i understand each application client in a cluster uses its own keyspace right. Hence i would need to set this in the application??"

No. You can think of a keyspace as just a collection of tables, which all your users would access. You would really only create multiple keyspaces if you had dramatically different replication needs for some reason, or if you had a multi-tenant application that required it for security purposes.

"Would this make cassandra to always use the configured replication strategy in the "MyKey" keyspace for that table?"

Yes. TableName table permanently lives in the MyKey keyspace and will inherit the properties of that keyspace.

Once you set your replication factor, you don't typically change it. You can but it would require a fairly IO intensive process in the background. Replication factor is used to determine how many copies of a singe piece of data lives in a particular datacenter and therefor will tell you how many nodes can fail before you have an outage. 3 is by far the most common setting here, but if you do not have 3 nodes in your data center, then a smaller number is fine.