Curator/Zookeeper lock cleanup
Asked Answered
I

4

7

I’m using the InterProcessSemaphoreMutex for a distributed locking recipe.

A typical path for a lock might be

/lock/calendar/uuid

Where uuid is of course a uuid and hence many lock paths may be generated.

I’d assume these paths need to be cleaned up eventually, so I’ve tried using childreaper and reaper to do so after I unlock the lock.

ChildReaper kind of works. If I add /lock/calendar/uuid it happily removes the children. the log shows it removes the leases and locks and the node itself is shown to be gone in zkClient However suddenly it begins complaining in a seemingly endless loop that the path is gone. This despite trying Mode.Delete and Mode.Until Gone.

Reaper does nothing, probably because /lock/calendar/uuid has children.

Am I missing something? Do I not need to clean up these locks? What do I need to worry concurrency wise about.

Irmgardirmina answered 31/3, 2015 at 17:2 Comment(0)
S
3

InterProcessSemaphoreMutex creates additional child nodes such as leases, locks, etc. My workaround for this particular type of lock is to add additional path /lock/path/leases, /lock/path/locks, etc to the Reaper when you acquire the lock.

Stelu answered 23/9, 2017 at 13:19 Comment(0)
B
3

If you use the latest ZooKeeper 3.5.x and the latest Curator, Curator uses "container" nodes for all its recipes and these are automatically cleaned up as needed. Curator's Reaper has been deprecated.

Bracing answered 24/9, 2017 at 21:3 Comment(0)
Z
0

The steps has to be as follows for the reaper.

  1. Create reaper (specify a threshold time. By default it is 5 minutes)
  2. Start reaper
  3. add path
  4. Thread.wait(//time more than the threshold)
  5. Close reaper

If you check the zookeeper now, the node will be deleted.

Note: This will work only for the leaf node that is when the path is empty.

P.S: Child reaper doesn't work for me. If you can put up the steps you used for child reaper in the comment or in the question, it will be helpful.

Zena answered 1/4, 2015 at 21:31 Comment(0)
I
0

Reaper wont work for InterprocessSemaphoreMutex because it will have children (locks, receipts IIRC). ChildReaper DOES work partially but then starts whining about losing the parent. This is a known bug currently fixed post 2.7.1 (not released yet). A workaround is to use ChildReaper with InterprocessLock IF the reentrancy is acceptable.

Irmgardirmina answered 1/4, 2015 at 23:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.