Andremoniy
Andremoniy

Reputation: 34900

Insert rows only in one datacenter in cassandra cluster

For some test purposes I want to break a consistency of data in my test cassandra cluster, consisting of two datacenters.

I assumed that if I use a consistency level equal to LOCAL_QUORUM, or LOCAL_ONE I will achieve this. Let us say I have a cassandra node node11 belonging to DC1:

cqlsh node11
CONSISTENCY LOCAL_QUORUM;
INSERT INTO test.test (...) VALUES (...) ;

But in fact, data appears in all nodes. I can read it from the node22 belonging to the DC2 even with the consistency level LOCAL_*. I've double checked: the nodetool shows me the two datacenters and node11 certainly belongs to the DC1, while node22 belongs to the DC2.

My keyspace test is configured as follows:

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

and I have two nodes in each DC respectively.

My questions:

  1. It seems to me that I wrongly understand the idea of these consistency level. In fact they do not prevent from writing data to the different DC's, but just ask for appearing of the data at least in the current datacenter. Is it correct understanding?

  2. More essentially: is any way to perform such a trick and achieve such a "broken" consistency, when I have a different data stored in two datacenters within one cluster?

(At the moment I think that the only one way to achieve that - is to break the ring and do not allow nodes from one DC know anything about nodes from another DC, but I don't like this solution).

Upvotes: 2

Views: 466

Answers (2)

Ashish
Ashish

Reputation: 21

This suggestion is to test scenario only to break data consistency between 2 DCs. (haven't tried but based on my understanding should work)

  • Write data in one DC (say DC1) with Local* consistency
  • Before write, keep nodes in DC2 down so DC1 will store hints as DC2 nodes are down.
  • Let max_hint_window_in_ms (3 hours by default - and you can reduce it) time pass so that DC1 coordinator will delete all the hints
  • Start DC2 nodes and query with LOCAL* query, the data from DC1 won't be present in DC2.

You can repeat these steps and insert data in DC2 with different values keeping DC1 down so same data will have different values in DC1 and DC2.

Upvotes: 0

Nicolas Henneaux
Nicolas Henneaux

Reputation: 12245

  1. LOCAL_QUORUM, this consistency level requires a quorum of acknoledgement received from the local DC but all the data are sent to all the nodes defined in the keyspace.

Even at low consistency levels, the write is still sent to all replicas for the written key, even replicas in other data centers. The consistency level just determines how many replicas are required to respond that they received the write.

https://docs.datastax.com/en/archived/cassandra/2.0/cassandra/dml/dml_config_consistency_c.html

  1. I don't think there is proper way to do that

Upvotes: 3

Related Questions