What can be done to ensure atomicity in a business batch operation?
For example: Delete multiple articles, but in the middle one has been deleted, assuming there is an error, then how to let the whole operation rollback, and locate the error message.
The transaction of the database guarantees atomicity but cannot locate the error message, but encounters a scenario where the transaction cannot be used.
Reply content:
What can be done to ensure atomicity in a business batch operation?
For example: Delete multiple articles, but in the middle one has been deleted, assuming there is an error, then how to let the whole operation rollback, and locate the error message.
The transaction of the database guarantees atomicity but cannot locate the error message, but encounters a scenario where the transaction cannot be used.
- It is most reasonable to use the transaction of the database, the error message can record Ah, there is an operation failed to throw an error.
- Application logic to ensure that every operation to do the next record, the success of the failure to do the next record. In the middle of the error, you can roll back the success. Generally we remove is fake delete, so it's easy. If you delete it, log the full information when you record it.
Very good question, expect the master to answer.
It's really a good question.
I can think of the same way as @star001007;
1. Build a DB that supports transaction types
2, delete is not the real meaning of physical deletion, just set a flag bit, such as Status=1 to delete, 0 means normal.
3. Record delete log, these redundant information can help to recover the record.
Using the transaction features of MySQL's InnoDB table, you can see my case:
How to bulk Update, delete, insert data into a database or send a large volume of e-mails online?
How do I avoid a requirement being executed more than once? How can a colleague help me to work together?
The problem is actually very problematic, the deletion of the same table, there is an atom to say?
MySQL for exampledelete from table where xxx=xxx
When deleted, it is logically guaranteed to be completed with an SQL statement, and MySQL can protect
Delete multiple records from different tables that would require a transaction.