1

I have a function which deletes some nodes from Cassandra DB as follow:

public void deleteNodeDataFromSensordata2(String nodeId, long startTime, long endTime) {
    logger.info("Star : delete Sensordata2 of node [" + nodeId + "] " + "start [" + startTime + "] " + "end ["
            + endTime + "] data");
    try {
        BoundStatement stmt = sensordata2NodeDataDelete.bind();
        stmt.setList(DAYS, getDaysAsList(startTime, endTime));
        stmt.setString(NODEID, nodeId);
        session.execute(stmt);
    } catch (Exception e) {
        logger.error("Error from cassandra", e);
    }
    logger.info("End : delete of  [" + nodeId + "] Sensordata2 data");
}

the delete query would be as follow:

    sensordata2NodeDataDelete = session.prepare(
            "DELETE FROM "
            + "SENSOR_DATA_2 "
            + "WHERE NODEID = :NODEID AND YYYYMMDD IN :DAYS");

I want to get assured all above data is deleted after the execution of the next command. Does the above code give such reliability?

Luckylukee
  • 575
  • 2
  • 9
  • 27

1 Answers1

2

You have to set at least a QUORUM consistency level to your statement.

It means that you will get a positive answer to the execute command only if enough nodes accepted your request (more than half the number of replication factor).

Then if next commands read or update data with the same consistency level, you are sure to have always the latest data.

Thomas Arnaud
  • 448
  • 5
  • 16
  • but here(https://stackoverflow.com/questions/21442717/how-do-i-set-the-consistency-level-of-an-individual-cql-query-in-cql3) they suggest to not use consistency level. – Luckylukee Aug 15 '17 at 02:24
  • 1
    That SO answer is referring to the `USING CONSISTENCY` part of those queries, not setting consistency levels. They moved the CL into the protocol so its set by the driver not on the queries. You should definitely use the consistency levels for your usecase and Thomas' answer is correct. – Chris Lohfink Aug 16 '17 at 04:01