I often create applications which are using multiple data stores. For example some files are stored in SharePoint and then proper metadata for this file is stored in additional database. The problem is there is no transaction, so when something goes wrong when saving to database, file is not rollbacked to previous state/deleted. How is it usually solved? I think it can be done like this:
- Simple solution - just reverse operations in catch block (some actions could be complex to rollback this way).
- Implement operations as commands with Execute and Undo methods - before executing previous state is saved some way and when something goes wrong, application call Undo method on all previously executed commands (if application crashes, there is risk of data incosistency).
Do you have any other ideas or examples? I know that one could also implement 2PC, but in this case it's probably too complex.
Aucun commentaire:
Enregistrer un commentaire