Information Technology Reference
In-Depth Information
updates to a new, temporary file such as #design.txt# . Then it renames the
temporary file to atomically replace the previously stored file.
14.1.2
The transaction abstraction
Transactions provide a way to atomically update multiple pieces of persistent
state.
For example, suppose you are updating a web site and you want to replace
the current collection of documents in /server/live with a new collection of
documents you have created in /development/ready . You don't want uses to
see intermediate steps when some of the documents have been updated and oth-
ers have not|they might encounter broken links or encounter new descriptions
referencing old pages or vice versa. Transactional file systems like Windows
Vista's TxF (Transactional NTFS) provide an API that lets applications apply
all of these updates atomically, allowing the programmer to write something
like the following pseudo-code:
ResultCodepublish(){
transactionID=beginTransaction();
foreachfilefin/development/readythatisnotin/server/live{
error=moveffrom/development/readyto/server/live;
if(error){
rollbackTransaction(transactionID);
returnROLLED_BACK;
}
}
foreachfilefin/server/livethatisnotin/development/ready{
error=deletef;
if(error){
rollbackTransaction(transactionID);
returnROLLED_BACK;
}
}
foreachfilefin/development/readythatisdifferentthanin/server/live{
error=moveffrom/development/readyto/server/live;
if(error){
rollbackTransaction(transactionID);
returnROLLED_BACK;
}
}
commitTransaction(transactionID);
returnCOMMITTED;
}
Notice that a transaction can finish in one of two ways:
it can commit ,
,Definition: commit
meaning all of its updates occur, or it can roll back meaning that none of its
Denition: roll back
updates occur.
Here, if the transaction commits, we are guaranteed that all of the updates
will be seen by all subsequent reads, but if it encounters and error and rolls
back or crashes without committing or rolling back, no reads will see any of the
updates.
More precisely, a transaction is a way to perform a set of updates while
Denition: transaction
Search WWH ::




Custom Search