Netflix/curator — pull request #261 by trun (2013-03-07 01:31:35+00:00)
Title: POST_INITIALIZED_EVENT race conditions / optimizations

We've been running a data structure modeled after PathChildrenCache for a while now on a path with ~2500 child nodes and using a async loading strategy very similar to the new POST_INITIALIZED_EVENT startup mode. I noticed a couple subtle race conditions that we've encountered in our own code - thought I'd share them back.

- https://github.com/trun/curator/commit/5229c8c8f4a8852dc39e817795c313cedd4d7e88 If a node is removed during startup (after getChildren() but before getDataAndStat()) the INITIALIZED_EVENT will never fire. Handling NONODE events fixes this.
- https://github.com/trun/curator/commit/fb945306e9813e69ea3472177ea2c4487daaf049 Though highly unlikely, I think it's possible for the initialSet to appear to be fully initialized before all the getDataAndStat() calls have even been issued? Constructing the initialSet before issuing any getDataAndStat() calls eliminates this possibility.
- https://github.com/trun/curator/commit/e4ddc6cc6d21ee3e1a7713c11a6569ca2071c182 Each call to maybeOfferInitializedEvent() loops over the entire initialSet, and since it's called after each updateInitialSet() this can get pretty expensive ( O(n2) ) with thousands of children. There doesn't seem to be much value in keeing the entire initialSet around so removing each node after it's loaded simplifies this check a great deal.

Also one simple bugfix (which may not even be necessary any more)...

- https://github.com/trun/curator/commit/3385adb35f732c51eef8a670d186bd57df51900d initialSet is keyed on node, not fullPath so this call was just a NOP before.