Not sure, but there seem to be two issues in the example WriteLock:
(1) ZNodeName is sorted according to session ID first, and then according to znode sequence number. This might cause starvation as lower session IDs always get priority. WriteLock is not thread-safe in the first place, so having session ID involved in compare operation does not seem to make sense.
(2) if findPrefixInChildren finds previous ID, it should add dir in front of the ID