You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Aristedes Maniatis <am...@apache.org> on 2020/05/27 01:43:59 UTC
Update TTL without setData()
I want to use ZK as a session store. Really the only thing in the data byte array will be the user id, but every request to the server will need to fetch that value.
Because we'll use TTL as a way to timeout sessions after inactivity, we need some way to update the TTL counter every time we check that the node exists, either with getData() or exists(). I'd rather avoid a heavy operation like setData() when we almost never need to update that byte array, for performance reasons.
Is there a way to update the TTL in this way?
Re: Update TTL without setData()
Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
TTL nodes automatically reset when they are updated. From the docs - https://zookeeper.apache.org/doc/r3.6.1/zookeeperProgrammers.html#TTL+Nodes <https://zookeeper.apache.org/doc/r3.6.1/zookeeperProgrammers.html#TTL+Nodes> - "If the znode is not modified within the TTL and has no children it will become a candidate to be deleted by the server at some point in the future." So the TTL works off of the ZNode's "mtime" field (last modified). The implication of this is that you need to incur a transaction with the leader in order for the "mtime" to get updated. This requires a setData call as non-mutating APIs are serviced from the instance you are connected to and don't affect the "mtime". Even if ZooKeeper had an "updateTTL" API it would effectively be the same as setData and would be just as heavy-weight.
-Jordan
> On May 26, 2020, at 8:43 PM, Aristedes Maniatis <am...@apache.org> wrote:
>
> I want to use ZK as a session store. Really the only thing in the data byte array will be the user id, but every request to the server will need to fetch that value.
> Because we'll use TTL as a way to timeout sessions after inactivity, we need some way to update the TTL counter every time we check that the node exists, either with getData() or exists(). I'd rather avoid a heavy operation like setData() when we almost never need to update that byte array, for performance reasons.
>
> Is there a way to update the TTL in this way?