From 5f645c5e44c83f769dc789b6935a157d145c2668 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 9 May 2024 13:51:19 +0300 Subject: [PATCH] Increase mod_revision on lease operations --- etctree.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/etctree.js b/etctree.js index 7813280..f385fb7 100644 --- a/etctree.js +++ b/etctree.js @@ -232,7 +232,7 @@ class EtcTree if (!snapshot.leases[id]) { // Revoke without replicating and notifying - this._sync_revoke_lease(id, notifications); + this._sync_revoke_lease(id, notifications, this.mod_revision); } } } @@ -366,6 +366,7 @@ class EtcTree } const expires = Date.now() + req.TTL*1000; this.leases[id] = { ttl: req.TTL, expires, timer_id: null, keys: {} }; + this.mod_revision++; this._set_expire(id); if (this.replicate) { @@ -389,6 +390,7 @@ class EtcTree } const ttl = this.leases[id].ttl; lease.expires = Date.now() + ttl*1000; + this.mod_revision++; this._set_expire(id); if (this.replicate) { @@ -424,13 +426,12 @@ class EtcTree return true; } - _sync_revoke_lease(id, notifications) + _sync_revoke_lease(id, notifications, next_revision) { if (!this.leases[id]) { throw new Error('unknown lease'); } - const next_revision = this.mod_revision + 1; for (const key in this.leases[id].keys) { this._delete_range({ key }, next_revision, notifications); @@ -447,7 +448,8 @@ class EtcTree return null; throw new Error('unknown lease'); } - this._sync_revoke_lease(req.ID, notifications); + this.mod_revision++; + this._sync_revoke_lease(req.ID, notifications, this.mod_revision); if (this.replicate) { await this.notify_replicator(notifications, [ { id: req.ID } ]); @@ -470,6 +472,7 @@ class EtcTree async apply_replication(msg) { + this.mod_revision = msg.header.revision; const notifications = []; if ((msg.leases||[]).length) { @@ -481,7 +484,7 @@ class EtcTree } else { - this._sync_revoke_lease(lease.id, notifications); + this._sync_revoke_lease(lease.id, notifications, this.mod_revision); } } }