This essentially implements a heartbeat mechanism for persistent nodes, in order to keep the node's mtime up-to-date.
Todo
[x] manual testing
[x] bump version
[x] documentation for new option
Testing
[x] unit tests
For manual testing, I am verifying that:
The node appears in Zookeeper.
The node disappears automatically when Nerve is killed.
In TTL mode, the node is repeatedly "touched." This is detected with the node's mtime (last modified time). Without TTL mode, the mtime should remain the same as the ctime.
Existing behavior (ephemeral)
[x] node is registered
zookeepercli -servers localhost:2181 -c ls /mango-test/services
base64_72_eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=_0000000000
[x] node is removed on exit
zookeepercli -servers localhost:2181 -c ls /mango-test/services
#### New behavior (ephemeral): node is registered but never touched
- [x] node is registered
```bash
+ zookeepercli -servers localhost:2181 -c ls /mango-test/services
base64_72_eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=_0000000000
[x] node is removed on exit
zookeepercli -servers localhost:2181 -c ls /mango-test/services
#### New behavior (persistent): node is registered and `mtime` is updated periodically
- [x] node is registered
```bash
+ zookeepercli -servers localhost:2181 -c ls /mango-test/services
base64_72_eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=_
[x] node is removed on exit
zookeepercli -servers localhost:2181 -c ls /mango-test/services
I, [2020-03-19T13:59:16.273885 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: background thread starting
I, [2020-03-19T13:59:16.275529 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: wrote new ZK node of type persistent at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=
I, [2020-03-19T13:59:16.275620 #57404] INFO -- Nerve::ServiceWatcher: nerve: service mango-test_26009_secure is now up
I, [2020-03-19T13:59:21.296584 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=
I, [2020-03-19T13:59:31.328048 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=
I, [2020-03-19T13:59:41.367232 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=
#### New behavior (persistent): `mtime` is updated periodically when node already exists
- [x] node is not re-created
*Nerve log*
I, [2020-03-19T15:43:07.923040 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: tried to write node but exists, setting data instead
```bash
+ zookeepercli -servers localhost:2181 -c ls /mango-test/services
0001.mango-test_
[x] node is removed on exit
zookeepercli -servers localhost:2181 -c ls /mango-test/services
I, [2020-03-19T15:43:12.949821 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test
I, [2020-03-19T15:43:23.013111 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test
I, [2020-03-19T15:43:33.066686 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test
I, [2020-03-19T15:43:43.119609 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test
I, [2020-03-19T15:43:53.178126 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test_
Summary
This essentially implements a heartbeat mechanism for
persistent
nodes, in order to keep the node'smtime
up-to-date.Todo
Testing
For manual testing, I am verifying that:
mtime
(last modified time). Without TTL mode, themtime
should remain the same as thectime
.Existing behavior (ephemeral)
ctime: 2020-03-19 13:02:56 -0400 mtime: 2020-03-19 13:02:56 -0400
ctime: 2020-03-19 13:06:04 -0400 mtime: 2020-03-19 13:06:04 -0400
ctime: 2020-03-19 13:06:51 -0400 mtime: 2020-03-19 13:06:51 -0400
check 1
ctime: 2020-03-19 13:59:16 -0400 mtime: 2020-03-19 13:59:21 -0400
check 2
ctime: 2020-03-19 13:59:16 -0400 mtime: 2020-03-19 13:59:31 -0400
check 3:
ctime: 2020-03-19 13:59:16 -0400 mtime: 2020-03-19 13:59:41 -0400
I, [2020-03-19T13:59:16.273885 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: background thread starting I, [2020-03-19T13:59:16.275529 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: wrote new ZK node of type persistent at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0= I, [2020-03-19T13:59:16.275620 #57404] INFO -- Nerve::ServiceWatcher: nerve: service mango-test_26009_secure is now up I, [2020-03-19T13:59:21.296584 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0= I, [2020-03-19T13:59:31.328048 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0= I, [2020-03-19T13:59:41.367232 #57404] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/base64_72eyJob3N0IjoiMTI3LjAuMC4xIiwicG9ydCI6NjAwNywibmFtZSI6Im1hY2Jvb2stcHJvIn0=
I, [2020-03-19T15:43:07.923040 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: tried to write node but exists, setting data instead
check 1
ctime: 2020-03-19 15:43:07 -0400 mtime: 2020-03-19 15:43:12 -0400
check 2
ctime: 2020-03-19 15:43:07 -0400 mtime: 2020-03-19 15:43:23 -0400
check 3
ctime: 2020-03-19 15:43:07 -0400 mtime: 2020-03-19 15:43:33 -0400
I, [2020-03-19T15:43:12.949821 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test I, [2020-03-19T15:43:23.013111 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test I, [2020-03-19T15:43:33.066686 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test I, [2020-03-19T15:43:43.119609 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test I, [2020-03-19T15:43:53.178126 #58055] INFO -- Nerve::Reporter::Zookeeper: nerve: ttl renew: touched ZK node at /mango-test/services/0001.mango-test_