Description
Currently when PersistentTtlNode starts, it will
- create a CONTAINER node
- create a CHILD node `_touch`
But there is a initialDelay between 1 and 2. If the initialDelay is long enough and the client is disconnected, 1 will not be deleted forever (because CONTAINER node only delete its parent when all its child is gone, but in this case, it never has any of them).
The initialDelay could be configured, but not so flexible. The initialDelay is calculated by the formula `ttl/touchScheduleFactor`, but this formula is also used to how frequent we want to ping Zookeeper to keep our znodes alive, aka period.
As you can see here (2nd parameter is initialDelay and 3rd parameter is for period)
// PersistentTtlNode.java Future<?> future = executorService.scheduleAtFixedRate(touchTask, ttlMs / touchScheduleFactor, ttlMs / touchScheduleFactor, TimeUnit.MILLISECONDS); // Interface ScheduledExecutorService ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) |
Let's say we have ttl of 5 minutes. We want to have 0 initialDelay so we will set the touchScheduleFactor to 5 minutes too. This will give us 1ms (5 minutes/5 minutes) of initialDelay (which solves our problem) but spamming Zookeeper every second.
So it would be nice if we can set `initialDelay`