Datastores11
Datastores11

Reputation: 123

cassandra how to handle failed inserts?

maybe a user registered into my app.

Then I do this things:

const query1 = INSERT INTO users_by_email ... values (...)
const query2 = INSERT INTO users_by_id ... VALUES (...)

Maybe query2 failed. What do I am then ? Or It cant failed if all datas are correctly ?

Upvotes: 1

Views: 184

Answers (1)

Manish Khandelwal
Manish Khandelwal

Reputation: 2310

Write can fail for multiple reasons in Cassandra. For example a node may go down or there may be network issues between nodes. So don't assume that writes will succeed if all the data is correct or your query is correct.

Coming back to your query, what should an application do. Simplest answer is to try the failed query again.

One more thing I would like to tell that if two tables are having same data which you want to sync, you should use batch

BEGIN BATCH
  INSERT INTO users_by_email ... values (...);
  INSERT INTO users_by_id ... VALUES (...);
APPLY BATCH ;

One more thing that batch doesn't guarantee that your changes will get rolled back. It will just inform the client that the set of query failed, so you as a client should retry your batch queries.

Upvotes: 1

Related Questions