Question: 5 . ( 1 4 % ) Zookeeper. The following pseudo - code lists the implementation of the distributed read / write lock using

5.(14\%) Zookeeper.
The following pseudo-code lists the implementation of the distributed read/write lock using Zookeeper (only the lock function is shown).
Write lock:
1. n = create(1+"/write-", EPHEMERAL_SEQUENTIAL)
2.\(\mathrm{C}=\operatorname{getChildren}(1\), false \()\)
3. if \( n \) is lowest znode in C , exit
4.\(\mathrm{p}=\) znode in C ordered just before n
5. if exists(p, true) wait for watch event
6. goto 2
Read lock:
1. n = create(1+"/read-", EPHEMERAL_SEQUENTIAL)
2.\(\mathrm{C}=\) getChildren(1, false)
3. if no write znodes lower than n in C , exit
4.\(\mathrm{p}=\) znode in C ordered just before n
5. if exists(p, true) wait for event
6. goto 2
(a)(4\%) The above pseudo-code unfortunately is known to have one bug. Can you identify the bug, explain how the bug creates incorrect results, and explain how the bug should be fixed?
(b)(4\%) Suppose that the bug in Part (a) is fixed. Suppose that there are five client requests of the read/write lock in the following order: Write, Write, Read, Read, and Write. Say \( l=z o o \). Draw the lock chain of znodes that shows how each lock request monitors the availability of locks.
(c)(6\%) We want to modify the above pseudocode, such that a writer can acquire the write lock as long as no writer exists, while a reader can acquire the read lock only when no writer exists. Thus, a writer is always given a higher priority to obtain a lock than any reader. Show how you revise the above pseudo-code.
5 . ( 1 4 \ % ) Zookeeper. The following pseudo -

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!