This is an old revision of the document!
This page is for sharing the design and progress of the project to add transaction support to FreeBSD.
Overview
The objective of this project is to allow a process to start a transaction that can be later committed or aborted. This would allow, for example, the painless rollback of a port installation that failed in the middle.
Design
Transactions are based on snapshots. Each process gets an additional field, its transaction id, which gets as its value the process id that begins a transaction, and is inherited when a process forks. Nested transactions are not allowed. When a transaction begins, a snapshot file named after the transaction id is created on each of the specified filesystems. The snapshot code is modified so that when a block is overwritten,
- if the process modifying the block is not part of a transaction, then
- if the block has already been copied in the transaction's snapshot then
- the corresponding call is blocked, waiting for the transaction to complete,
- otherwise (or when the call unblocks) the block is written to the live filesystem, without making a copy of the old contents to the snapshot file,
- otherwise, the old block is copied to the snapshot file as usual.
When the transaction terminates (through a commit or abort) the transaction id of all processes of that transaction is cleared. If the transaction is committed, the snapshot file is released and deleted and waiting processes are notified. If the transaction is aborted, then
- the snapshot is suspended,
- all the snapshot's blocks are copied to the live filesystem,
- the snapshot file is released, and
- then waiting processes are notified.
When a process whose process id is the same as its transaction id terminates, the process id of the first of the remaining transaction processes is selected as a new transaction id, and it is assigned to all remaining transaction processes. If not other transaction processes remain, then the transaction is aborted.
API
System Level
- int transaction(int request, …)
- TR_BEGIN, char **transacted_filesystems
- TR_COMMIT, int id
- TR_ABORT, int id
- All gated system calls can return E_TRVIOL (Transaction violation): a transaction attempted to modify data on a filesystem that is not under transaction control.
User level
transaction -b filesystem … | -a | -g
Progress
- Rough design overview (dds - 2007-06-22)
- API documentation, design refinement (dds - 2007-06-23)
TODO
- Any issues with deleted and allocated blocks?
References
- [http://doi.acm.org/10.1145/121132.121171 Experience with transactions in QuickSilver]
- Marshall Kirk McKusick and George V. Neville-Neil. The Design and Implementation of the FreeBSD Operating System. Addison-Wesley, Reading, MA, 2004. Section 8.7 (pp. 349-358).
- [http://www.usenix.org/events/fast05/wips/verma.pdf Transaction Support in the Windows NTFS File System]
- [http://www.usenix.org/events/usenix99/full_papers/evans/evans.ps Design and Implementation of a Transaction-Based Filesystem on FreeBSD]
- [http://www.usenix.org/events/fast05/wips/wright.pdf Amino: Extending ACID Semantics to the File System]