What is the best way to roll back changes?

Ok, so I have a Spring application that accepts a network view and loads virtual machines to represent the transferred network.

It uses low level API to output virtual machines, no database.

I need to figure out how to do this - to handle the situation where the user sends the 10 node network model (or any number) and the application goes through and creates a network (starting virtual machines) if the node does not start. I want to respond to that. I would like to be able to undo my changes (i.e. Destroy all created nodes).

I was told that I need to learn "Transactions", but I'm not sure if this applies to this scenario when I am not using a database.

As a side note, I have the logic for deleting nodes if the user sends this request.

My question is: how can I handle this?

Also, is this the best stack overflow for this question?

+5
source share
1 answer

It seems that you are looking for transactional behavior and, in particular, for atomicity ("all or nothing"). But usually a “transaction” implies certain guarantees (especially with regard to ACID properties) that will be difficult or impossible to achieve when a person’s timeline is involved for an order of minutes.

The “error-compensated workflow” is probably more than what you would be looking for here.

I would do it manually, possibly with tool support (e.g. for workflows). Turn off the process of creating your network and keep track of current progress, such as created virtual machines, running virtual machines, etc. If there are errors that require rollback, try another process that performs the cleanup. The behavior of the cleaning process itself may fail, so it can repeat its various steps several times before creating a report that says "this cleaning step failed."

If shared resources are involved, you will also need to implement some kind of isolation mechanism. Sometimes it’s quite simple - for example, DHCP helps to avoid duplication of IP addresses. If you are updating a DNS zone file, you need to synchronize access to it to avoid simultaneous recording. Etc.

+4
source

Source: https://habr.com/ru/post/1207620/


All Articles