xirururu
xirururu

Reputation: 5508

How to recover deleted data in cassandra?

If I deleted a value in a cell from a table, but later, I want to recover it back, how can I do it?

I know that, cassandra doesn’t really delete data, it just mark it as deleted, so how can I recover the data?

Usecase for example: I want to delete all information from a user, so I first delete the information in cassandra database, then, I try to delete his information in somewhere else, but it comes to an error, so I have to stop the deletion process and recover the deleted data from cassandra database.

How can I do that?

Upvotes: 2

Views: 1720

Answers (1)

Horia
Horia

Reputation: 2982

Unfortunately not. You could however use sstabledump (Cassandra >= 3.0) to inspect sstable contents, but there are some drawbacks:

  • if the data was not flushed to disk (thus being in the memtable) it will be deleted before reaching to sstable
  • you need to find the sstable that the data belongs to

Probably there are some other drawbacks that I miss right now.

Some workarounds

  • first copy the data to another table and then perform the delete. After you delete the information from the other location, you can safely delete it from your backup table.
  • a new column ("pending_delete") where you would record the state. You would only query for your "live" data.
  • a new table where you would store the pk of the data to be deleted and delete it from the both tables after the operation on the other location is successful.

Choosing the right solution I guess depends on your use case and the size of your data.

Upvotes: 3

Related Questions