4

I am using apache-cassandra-3.10

I understand instead of kill -9 pid, the only way to stop cassandra gracefully is nodetool stopdaemon.

But I want to know if nodetool stopdaemon also flushes the data in the memtables to sstables before shutdown.

If it does not flush then it would lead to data loss, when I stop the node using nodetool stopdaemon.

Also after researching on this , I read about the DURABLE_WRITES. What does durable write actually do ?

Also , the datastax documentation states under the section Setting DURABLE_WRITES "Do not set this attribute on a keyspace using the SimpleStrategy"

reference : https://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_keyspace_r.html

What if my keyspace is configured with Simple Strategy , I still cannot benefit with DURABLE_WRITES in case it can help with data loss on shutdown ?

Is manually running nodetool flush before shutdown, the only way to make sure we do not lose data on shutdown ?

I read from https://issues.apache.org/jira/browse/CASSANDRA-3564 that the functionality to flush at shutdown has not been added.

Also there is a open ticket on the same issue https://issues.apache.org/jira/browse/CASSANDRA-12001

Intention is to avoid any data loss at shut down using nodetool stopdaemon. Basically flush all tables before shutdown , Considering Simple-strategy in use.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Syed Ammar Mustafa
  • 343
  • 1
  • 6
  • 17

2 Answers2

3

nodetool drain will suffice.
From Datastax Documentation about nodeool drain,

Flushes all memtables from the node to SSTables on disk. Cassandra stops listening for connections from the client and other nodes. You need to restart Cassandra after running nodetool drain.
link: nodetool drain

Then you can either kill or run nodetool stopdaemon.

observer
  • 106
  • 6
  • 1
    The documentation also say's " You typically use this command before upgrading a node to a new version of Cassandra". So why use nodetool drain ? – Syed Ammar Mustafa Mar 22 '17 at 07:49
1

Cassandra is very robust and crash-safe. Even if you kill/stop daemon you might not have data loss. But if you do safe shutdown, then you can save startup time for the Cassandra.

Follow the below steps to safe shutdown:

  1. nodetool disablegossip
  2. nodetool disablethrift
  3. nodetool disablebinary (In case of Cassandra 2.0 and above)
  4. nodetool drain

disabling gossip stops the communication to the other nodes, disabling thrift and binary stops communication with the clients.

Finally drain flushes all the tables.

Now stop Cassandra either by kill or stop daemon

Shoban Sundar
  • 493
  • 1
  • 9
  • 11
  • So basically your sure that Cassandra will not flush everything in memory to disk , if we do not do a manual flush/drain ? – Syed Ammar Mustafa Mar 22 '17 at 07:50
  • When you write data, Cassandra will store data in commitlog(for faster access). It will not have in memory data, when you flush/drain the commitlog data is written to db. That's why when you kill the process also the data is not lost. – Shoban Sundar Mar 22 '17 at 08:06
  • But there are is memtable in between commit log and sstable. I am concerned about the data held in memtable. Because the data in memtables is not shadowed in commitlog. Say if the memtable_cleanup_threshold is not yet reached and we are shutting down the node , then the data which is not flushed present in memtable is lost , Even If I do flush/drain I get back data which is there is commit log only. – Syed Ammar Mustafa Mar 22 '17 at 09:59
  • https://docs.datastax.com/en/cassandra/3.0/cassandra/configuration/configCassandra_yaml.html#configCassandra_yaml__memtable_cleanup_threshold check "memtable_cleanup_threshold" – Syed Ammar Mustafa Mar 22 '17 at 10:00
  • Yes you are correct, there is a memtable, But Cassandra writes data in commitlog and memtable simultaneously. When the Memtable limit is reached, then the data is flushed and corresponding data in commitlog is purged. The commit log thus recovers the data in memtable in the event of a failure. For more information see how it works https://teddyma.gitbooks.io/learncassandra/content/model/where_is_data_stored.html. – Shoban Sundar Mar 22 '17 at 11:33
  • Thanks for the source. I read that. So does that mean there is no way that in case of a shut down or failure there could be data loss ? Also I hope the content in the link you shared is up to date. – Syed Ammar Mustafa Mar 23 '17 at 14:05
  • Yes, that's why Cassandra is highly reliable. – Shoban Sundar Mar 23 '17 at 14:48
  • Actually commitlog would be persisted to disk every 10 seconds, so there is possibility to lose data that been inserted in last 0 seconds which is not persisted neither by commilog nor sstable, although if RF and CL > 1, another copy of data kept on another node – f.ald Nov 25 '19 at 05:28