Increase mod_revision on lease operations

master
Vitaliy Filippov 2024-05-09 13:51:19 +03:00
parent 0c75cd1d63
commit 5f645c5e44
1 changed files with 8 additions and 5 deletions

View File

@ -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);
}
}
}