Saturday, July 11, 2009

Document livecycle issue

The NaroCAD's document format stores a tree that is also save with the list of undo-redo steps. To make things clearer, the undo/redo steps are done in this way:
- before you change the document, you do a document.Transact(); meaning before you add a scene shape, before you change a property, etc.
- you do the changes till you find a state that your document can be saved as restore point
- you do a document.Commit(reason); meaning that the restore point will be set up to here.

This is close to transactional database model. This leads to a problem, that is like this: what if two scene elements wants to change the document? It should not happen but it happens in real life. For example the best case is the situation in that someone forgets to do a Commit after do it a Transact(), or do a Commit twice. This problem can lead to bad race document issues and the document may get wrong. The problem is that the document will not need to have any invalid states in the working of it. It should be guaranteed by design.

So right now doing a series of multiple transacts, without commits will transform like this:
Transact1, Transact2, ... TransactN to Transact1, Revert, Transact2, ... Revert, TransactN, so on TransactN it will get a valid state that continues from the last commit.

Also the Commit1, ... CommitN will be replaced internally to Commit1, Revert, Revert, ... Revert, so the stage of CommitN it will be the same with Commit1.

It is safe? Yes, because the Transact/Commit say that in-between the state of document is not safe. So you have to not be able to either consider a Transact state in between or outside of it a commit.

This makes also possible at least at the design level to make two work flows to be possible conceptually and if they override one each other's state, to make that only one to work. Also, it will force developers to make the changes in document more atomic to not break themselves the document.

The good thing is that if that if they will try do it, they will not break it, but only change for a moment the document in an invalid state, and afterward, everything it will revert.

No comments: