Reimplement locking w/o relying on hostInfo cmd
Because the hostInfo MongoDB command may not be allowed in some environments. Also, in sharded deployments the clock skew may differ between different shards so using hostInfo is not enough. This new implementation simply assumes the clocks are in sync within a certain range and throws an error if clocks are found to be out of sync.
This commit is contained in:
1 parent
a9b0e3a1f7
commit
d787f66e3f
2 files changed
+66
-80
No files matched your search
+2
-2
@@ -398,7 +398,7 @@ async function refresh(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
const unlockOrExtend = await cache.lock("presets_hash_lock", 3);
|
||||
const lockToken = await cache.acquireLock("presets_hash_lock", 4000, 4000);
|
||||
|
||||
const res = await Promise.all([
|
||||
fetchPresets(),
|
||||
@@ -432,7 +432,7 @@ async function refresh(): Promise<void> {
|
||||
currentSnapshot = computeHash(snapshot);
|
||||
snapshots.set(currentSnapshot, snapshot);
|
||||
await cache.set("presets_hash", currentSnapshot, 300);
|
||||
await unlockOrExtend(0);
|
||||
await cache.releaseLock("presets_hash_lock", lockToken);
|
||||
|
||||
nextRefresh = now + (REFRESH - (now % REFRESH));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user