

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CSEP545 Transaction Processing for E-Commerce 1/11/
Solution to Assignment 1 1
The main bookkeeping of transaction state is done in Cache(e).tId. It is the negative transaction id of the transaction that updated the block, if the block has not yet been written to disk. It is made positive after being written to disk. And it is set to 0 immediately before the transaction commits or aborts.
a. Before looking at the ACID properties, consider the following scenarios:
In view of these problems, letās look at the ACID properties one by one: ļ· Atomicity: The implementation is not atomic, due to scenarios 1 and 2 above. In these cases, T1 aborts but does have an effect, due to the erroneous value of Cache(x).oldBlock. ļ· Isolation: Transactions execute serially. So in the absence of aborts due to scenarios 1 and 2, the implementation is Isolated. ļ· Consistency: This is up to the transactions. The system has no effect, one way or the other. ļ· Durability: The implementation is durable. If a transaction commits, then all of its updates are on disk.
b. If the operating system fails while a transaction is executing Commit, then only some of its updates may have been written to disk, in which case the result is not atomic. The same problem can happen if the failure happens during an execution of Abort. There are no easy solutions to this. One solution, called shadow paging, will be described in class. Later in the course, weāll discuss another approach based on logging.
c. Given the issues in (a), this scenario doesnāt make things much worse. So to make the problem more interesting, letās assume the fixes to part (a) are implemented. During Commit, if DiskWrite(b, a) succeeds (i.e. returns 0) and corrupts block b on disk, then the execution is not atomic. One way to fix this is to read back each block after it is written and diff it with the intended content, which is obviously a high price to pay for atomicity. Another way is to buy a disk that doesnāt have this bad behavior ļ.
d. In the variation, suppose DiskWrite(b, a) fails (i.e. returns -1) and corrupts block b on disk. Then two lines later abort will be called, which will restore the previous value of the page on disk. So if the fixes to part (a) are implemented, the execution is still atomic. Isolation and durability are not affected, so the system is still durable and isolated.
e. Again, this scenario doesnāt make things any worse than (a). So letās assume the fixes are implemented. In effect, this scenario deletes the first statement in Start(), thereby allowing a second transaction to start while another one is active. Letās look at the ACID properties one by one: ļ· Atomicity: Itās hard to distinguish atomicity from isolation in this case. That said, if two transactions are running concurrently, one of them could overwrite a cache block that was previously updated by the other, causing its update to be lost and hence not be atomic. A variation is that the second transaction aborts. Since
CSEP545 Transaction Processing for E-Commerce 1/11/
Solution to Assignment 1 2
its update didnāt affect Cache(e).oldBlock, when it aborts it restores the first transactionās before-image of the block, instead of the first transactionās after-image. Another example: if T 1 updates a block, T 2 reads it, and then T 1 aborts, then T 1 ās execution is not atomic. T 2 ās read operation causes āCache(e).tId = tIdā to execute, which means that T 1 ās update wonāt be undone. ļ· Isolation: Both transactions can update the same two blocks, say x and y, in different orders: W 1 (x) W 2 (y) W 1 (y) W 2 (x) C 1 C 2. Here if both transactions commit, the database state contains writes from each transaction: y from T 1 , and x from T 2. This cannot occur in a serial execution. Hence the execution is not serializable. ļ· Consistency: Same as scenario (a), though you could argue itās even worse since the execution isnāt isolated. ļ· Durability: This doesnāt affect durability, although you could argue that the violations of atomicity and isolation mean the result isnāt durable either. One simple solution is the code in the assignment, where Start() returns an error when thereās an active transaction. If you want transactions to run concurrently, then some form of per-block synchronization is needed, such as two-phase locking. Weāll discuss this soon in class.