Download presentation
Presentation is loading. Please wait.
Published byRuby Hood Modified over 8 years ago
1
Synchronization CSCI 4900/6900
2
Transactions Protects data and allows processes to access and modify multiple data items as a single atomic transaction –If process backs out halfway, everything is restored back Originated in business world –Parties free to negotiate and back-off during negotiation –No backing-off after the contract is signed Initiator process announces the beginning of a transaction Processes create, update, and delete entries Initiator announces that it wants others to “commit” –Transaction made permanent if everyone agrees –Otherwise transaction is aborted and all entries are restored back
3
The Transaction Model Updating a master tape is fault tolerant.
4
Need for Transactions Banking Example –Withdraw 100 dollars from account A –Deposit 100 dollars to account B –What happens if withdrawal succeeds but deposit fails? Book an air-ticket on a multi-leg journey –White Plains to JFK –JFK to Nairobi –Nairobi to Malindi Requirement is that either all operations complete or none of them complete
5
Transaction Primitives Examples of primitives for transactions. PrimitiveDescription BEGIN_TRANSACTIONMake the start of a transaction END_TRANSACTIONTerminate the transaction and try to commit ABORT_TRANSACTIONKill the transaction and restore the old values READRead data from a file, a table, or otherwise WRITEWrite data to a file, a table, or otherwise
6
Utilizing Transaction Primitives a)Transaction to reserve three flights commits b)Transaction aborts when third flight is unavailable BEGIN_TRANSACTION reserve WP -> JFK; reserve JFK -> Nairobi; reserve Nairobi -> Malindi; END_TRANSACTION (a) BEGIN_TRANSACTION reserve WP -> JFK; reserve JFK -> Nairobi; reserve Nairobi -> Malindi full => ABORT_TRANSACTION (b)
7
ACID Properties of Transactions Atomic – Happens indivisibly to the outside world –File append transaction example Consistent – Does not violate system constraints –Banking example – Law of money conservation for internal transfers Isolated – Concurrent transactions do not interfere with each other –Banking example – Depositing and adding interest Durable – Changes are permanent when a transaction commits –Failure after commits do not affect data values that are modified
8
Transactions Classification Flat transactions are simple but have limitations –Does not allow partial results to be committed –Airline example – need to book legs that are busy Nested transaction –Constructed from number of sub-transactions –Transaction starts several sub-transactions in parallel –Each sub-transaction might commit independently –If parent aborts all sub-transactions have to be rolled back –Durability now applies only to top-level transactions –Recursive nesting
9
Distributed Transactions What about transactions where data is distributed? –Nested transaction does not always work –Example – Remit 1% of my bank account to charities Distributed transaction is a transaction where in data is distributed –In nested transactions the transaction is divided into hierarchy of transactions –Distributed transaction is logically flat and indivisible but operates on distributed data Need for distributed algorithms for locking and committing
10
Distributed Transactions a)A nested transaction b)A distributed transaction
11
How to Implement Transactions? Two methods –Private workspace –Writeahead Log –File system example Private workspace –When a process starts a transaction, it gets a private workspace of all files it needs to use –Operations only on private workspace –Private workspace is written back (ignored) on commit (abort) –Efficiency problems – copying everything is costly.
12
Optimizations to Private Workspace No need to copy files that are only being read Optimization -1 – Create private workspace with pointer to parent workspace –Trace pointer when a file is opened to read –Copy when the file is being written Optimization -2 –When a file is opened for writing, just copy the file’s index (i- node) –When a file-block is actually written make local copy (and insert address into private index) –Make index permanent on commit or ignore the index on abort
13
Private Workspace a)The file index and disk blocks for a three-block file b)The situation after a transaction has modified block 0 and appended block 3 c)After committing
14
Writeahead Log Files are modified in place Before any modification can take place a log has to be written onto the disk –Transaction ID, File ID, Block ID –What is the old value, what is the new value Changes to the file can take place only after log has been made permanent If transaction commits, a commit record is written to log Rollback for aborted transactions
15
Writeahead Log a) A transaction b) – d) The log before each statement is executed x = 0; y = 0; BEGIN_TRANSACTION; x = x + 1; y = y + 2 x = y * y; END_TRANSACTION; (a) Log [x = 0 / 1] (b) Log [x = 0 / 1] [y = 0/2] (c) Log [x = 0 / 1] [y = 0/2] [x = 1/4] (d)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.