Principles Of Distributed Database Systems Exercise Solutions Better Access
The flickering neon sign of "The Partitioned Plate," a diner known for its chaotic yet surprisingly efficient service, hummed with a low-frequency buzz. Inside, Elara, a database architect with a penchant for solving unsolvable puzzles, sat hunched over a worn copy of "Principles of Distributed Database Systems."
She wasn't just reading; she was wrestling with a phantom. A phantom named "The Inconsistent State."
For weeks, her team's distributed transaction system had been plagued by phantom reads and lost updates. Every time they thought they had the concurrency control figured out, a new anomaly would ripple through the nodes like a digital seismic wave.
"Trouble with the exercise sets again, Elara?" a voice rasped from across the counter. It was Silas, the diner's owner, a man whose wisdom was as deep as his coffee was black.
Elara sighed, pushing the book toward him. "Exercise 12.4. Reliability and Fault Tolerance. I can't seem to find the right balance between replication and performance. Every time I increase the replication factor to handle node failures, the write latency skyrockets."
Silas leaned in, his eyes twinkling. "Think of this diner, Elara. We've got three kitchens, right? All serving the same menu. If one kitchen goes down, the others pick up the slack. But if we try to make sure every single chef in every kitchen knows exactly what every customer ordered the second they order it, nothing would ever get cooked."
Elara frowned. "But we need consistency, Silas. We can't have one customer getting their pancakes while another is told they're out of stock when they're not." The flickering neon sign of "The Partitioned Plate,"
"Exactly," Silas said, tapping the book. "The key isn't perfect synchronization. It's about
consistency. You don't need every node to be identical every millisecond. You just need them to agree on the final state before the bill is paid."
He pointed to a specific diagram in the exercise set—a complex web of message exchanges and heartbeat protocols. "Look at the quorum-based protocols. They don't require everyone to agree, just a majority. It's like my staff. If three out of five servers say we're out of blueberry muffins, we're out of blueberry muffins. We don't need to wait for the other two to check the pantry."
Elara's eyes widened. She began to see the logic. The exercise wasn't about finding a single, perfect solution; it was about understanding the trade-offs. The "answer" wasn't a formula, but a strategy.
She spent the rest of the night scribbling notes, mapping out quorum systems and failure-aware commit protocols. The solutions weren't just lines of code; they were a blueprint for a resilient, distributed world.
As the sun began to peek over the horizon, Elara finally closed the book. The phantom of inconsistency hadn't vanished, but it was no longer a threat. She had the principles. She had the solutions. And most importantly, she had a fresh perspective, courtesy of a diner owner and a very challenging exercise set. Local WFG : Shows only locks managed at that site
She left a generous tip, not just for the coffee, but for the clarity. The "Principles of Distributed Database Systems" were no longer just abstract concepts; they were the tools she would use to build something truly robust. And as she stepped out into the crisp morning air, she knew that even in a world of distributed systems and inevitable failures, consistency, eventually, would always prevail.
Part 3: Concurrency Control & Distributed Deadlock
Distributed concurrency control ensures transaction atomicity and isolation across multiple sites.
Key Principles
- Local WFG: Shows only locks managed at that site.
- Global deadlock: A cycle in the global graph, possibly involving edges from different sites.
- Centralized detection: One site collects all local graphs. Simple but creates bottleneck.
- Hierarchical detection: Sites send local graphs to a coordinator, which may compress edges.
6. Distributed Database Design: Allocation and Replication
Final exercises often combine fragmentation with allocation: given fragments and sites, decide whether to replicate or allocate uniquely to minimize cost.
Part 4: Distributed Reliability & The 2-Phase Commit (2PC)
Ensuring atomicity (all nodes commit or all nodes abort) is critical.
Exercise 3.1 – 2PL vs. Strict 2PL in Distributed DB
Question: A distributed transaction T1: write(X) at site A, write(Y) at site B. T2: read(X) at A, read(Y) at B.
Explain deadlock possibility under 2PL without strict locking.
Solution:
Under Basic 2PL (locks held until commit, but released earlier for reads possible in some implementations): read_TS(D)=5. TS(T2)=20 >
- T1: write-lock X at A, write-lock Y at B.
- T2: read-lock X at A (if T1 hasn’t released write-lock, T2 waits). No deadlock yet.
But if locks are released after use (not strict), and T2 reads X after T1 released write-lock, T2 proceeds, then T1 still holds Y write-lock, T2 tries read-lock Y → deadlock.
Strict 2PL (all locks held until commit/abort) avoids this because T1 doesn’t release X lock before committing, so T2 can’t read X until T1 commits → no cycle.
2. Distributed Query Processing: Semi-Join Reduction
A classic exercise is to optimize a distributed join between two relations stored at different sites using semi-joins.
10. Work a concrete example
- Always include a short worked example with small numbers:
- e.g., N=5 replicas, W=3, R=3 and show read/write scenarios.
- e.g., two concurrent transactions with read/write sets — build the precedence graph and show whether serializable.
- Show intermediate states (timestamps, locks held, message counts).
Exercise 3.2: Timestamp Ordering – Write Rule Conflict
Problem:
Given TS(T1)=10, TS(T2)=20. At site X, data item D has write_TS=5, read_TS=5. T2 issues write(D). T1 issues write(D) later. Apply basic timestamp ordering (TO) rules.
Solution:
Basic TO rule for write_TS:
- If TS(T) < read_TS(D) → reject T (write too late, someone newer read).
- If TS(T) < write_TS(D) → reject T (Thomas Write Rule: ignore obsolete write).
- Else allow.
Step 1 – T2 (TS=20) write(D):
write_TS(D)=5, read_TS(D)=5. TS(T2)=20 > both → allow. Update write_TS(D)=20.
Step 2 – T1 (TS=10) write(D):
Now read_TS(D)=5, write_TS(D)=20. TS(T1)=10 < write_TS(D)=20 → reject (obsolete write).
Answer: T1’s write is rejected (rolled back/restarted) because a later transaction already wrote D.