Thursday, February 29th, 2024
Hell, there are no rules here-- we're trying to accomplish something.
— Thomas Edison
ECS165A Milestone 3 thoughts
- Need to implement transaction isolation & consistency (if a transaction wants to insert a tail record, it must lock the base record and prevent other transactions from interacting with it; this might not be the correct way to handle this)
- How to ensure transactions are serializable?—No two transactions can modify the same record at the same time (i.e. if transaction modify )
- What happens if transaction A inserts one tail record, and transaction B wants to insert another tail record for the same tail record? Just fail transaction B, since transaction A holds the lock for that (base) record.
- Make sure the
ReadersWriterLock
doesn’t wait to acquire a write lock, i.e. reading
- Read committed base/tail records only.
- Record locking
- Base record insertion: gains lock on base record
- If lock acquisition fails, raise error (this should technically never happen)
- Need to prevent another thread from seeing base record before commit
- Tail record insertion: gains lock on base record
- If lock acquisition fails, return false
- Base record insertion: gains lock on base record
- THIS IS NOT NECESSARY: Change users of ReadersWriterLock to strict 2PL (don’t release lock until commit, will require adding the release function to Transaction, and upon commit or abort, release all locks that was added). Must make sure transaction uses the highest level of lock (if it reads and write, only acquire a write lock, because we don’t want to support elevating a read lock)
- Implement strict 2PL for
_base_rec_lock
- Each base RID has a read count and write count.
- Exclusive lock for editing the lock table.
- When reading, check if write count is zero. Then add to read count.
- When writing, check if both read and write count is zero, then add to write count.
- Query needs to add locked base RIDs (in a separate list) to the Transaction object so that Transaction could unlock them later. Also need to keep track of whether it’s read or write.
- Need to update add_base/tail_record so that it acquires a write lock
- Need to update get_record_version so that it acquires a read lock