I need to replicate a local node with a SimpleStrategy to a remote node in other Cassandra's DB. Does anyone have any idea where I begin?
-
Are they in different clusters? – Alex Ott May 21 '21 at 17:08
-
Yes, they are. One is running in a local machine and the other is running in the cloud. The Cassandras's cloud will receive more than cassandra's local node. Example, I have 2 application running with cassandra's local node and every month I nedd to replicate the node for the cassandra's cloud. – Luciana Oliveira May 21 '21 at 17:15
-
Do the cloud cassandra also receive writes? Or it’s read only? Do you have a TTL on data? – Alex Ott May 21 '21 at 17:37
-
The cloud cassandra receive writes and read beyond the local nodes datas replication. We don't have a TTL on data yet. – Luciana Oliveira May 21 '21 at 17:46
-
One more question - table structures are the same? Partition keys, etc.? – Alex Ott May 22 '21 at 07:16
-
@AlexOtt, sorry. Yes, everyting is the same. – Luciana Oliveira Jul 06 '21 at 20:12
1 Answers
The main complexity here, if you're writing data into both clusters is how to avoid overwriting the data that has changed in the cloud later than your local setup. There are several possibilities to do that:
If structure of the tables is the same (including the names of the keyspaces if user-defined types are used), then you can just copy SSTables from your local machine to the cloud, and use sstableloader to replay them - in this case, Cassandra will obey the actual writetime, and won't overwrite changed data. Also, if you're doing deletes from tables, then you need to copy SSTables before tombstones are expired. You may not copy all SSTables every time, just the files that has changed since last data upload. But you always need to copy SSTables from all nodes from which you're doing upload.
If structure isn't the same, then you can either look to using DSBulk or Spark Cassandra Connector. In both cases you'll need to export data with writetime as well, and then load it also with timestamp. Please note that in both cases if different columns have different writetime, then you will need to load that data separately because Cassandra allows to specify only one timestamp when updating/inserting data.
In case of DSBulk you can follow the example 19.4 for exporting of data from this blog post, and example 11.3 for loading (from another blog post). So this may require some shell scripting. Plus you'll need to have disk space to keep exported data (but you can use compression).
In case of Spark Cassandra Connector you can export data without intermediate storage if both nodes are accessible from Spark. But you'll need to write some Spark code for reading data using RDD or DataFrame APIs.

- 80,552
- 8
- 87
- 132
-
Thanks a lot for your explication! The structure is the same. I'll think a way to separate the datas from replication and the "normal" writes. – Luciana Oliveira May 22 '21 at 15:12
-
1if structure is the same, streaming using sstableloader could be the simplest way - just remember about copying data before tombstones expire – Alex Ott May 22 '21 at 16:38
-
Alex Ott, the replication worked well. One question. If I have two cassandra's DB, located in the differents places, to be load in the third cassandra's db (the master). Could I use the same master's keyspace ? – Luciana Oliveira Jul 06 '21 at 20:25
-
1Usually that doesn’t matter, until you use user defined types and sstableloader… – Alex Ott Jul 06 '21 at 20:37
-
Thanks! We have more places with the same structure and I thouthg that I could not use the same keyspace master repository to load all at the same time. – Luciana Oliveira Jul 06 '21 at 21:22
-
1
-
One more question. After run the command `cd /var/lib/cassandra/data/sspkeyspace/ && find /var/lib/cassandra/data/appkeyspace/ -maxdepth 5 -type d -exec sstableloader -v --nodes 172.18.0.2 {} \`, the new data does not apper. Do I need to "refresh" the keyspace? – Luciana Oliveira Oct 28 '21 at 12:17
-
1
-
I run an script that do the process automatically and I noted that one table was not update and the others was. Do I need to anything (like commit) before to zip the origin keyspace? – Luciana Oliveira Oct 28 '21 at 15:04
-
1I can see only one issue when data is not updated - the data in the destination timestamp is having newer timestamps – Alex Ott Oct 28 '21 at 16:13
-
Thank for your replay. It is a issue in my situation, because if the table is updated before the replication occurred, it will not update. What do you recommend? Because the schema is the same in both cassandra db. – Luciana Oliveira Oct 28 '21 at 16:40
-
1dump data from original database for example by using DSBulk & load into destination - this will overwrite timestamps. But it could lead to mixing old & new data – Alex Ott Oct 28 '21 at 16:47