Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
fix delta calculation to use milliseconds on example dlm server
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinwilson541 committed May 25, 2017
1 parent 15db7aa commit f14b727
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions examples/gen_server/dlm/dlm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var _ = require("lodash"),
debug = require("debug")("clusterluck:examples:dlm");

var GenServer = cl.GenServer;
const mcsToMs = 1000;

class Lock {
constructor(type, id, holder, timeout) {
Expand Down Expand Up @@ -136,7 +137,7 @@ class DLMServer extends GenServer {
timeout: timeout
}, (err, data) => {
if (err) return cb(err);
var delta = microtime.now()-time;
var delta = (microtime.now()-time)/mcsToMs;
var nData = DLMServer.findLockPasses(nodes, data);
if (nData.length/data.length >= this._rquorum && delta < timeout) {
return cb(null, nData);
Expand Down Expand Up @@ -169,7 +170,7 @@ class DLMServer extends GenServer {
timeout: timeout
}, (err, data) => {
if (err) return cb(err);
var delta = microtime.now()-time;
var delta = (microtime.now()-time)/mcsToMs;
var nData = DLMServer.findLockPasses(nodes, data);
if (nData.length/data.length >= this._wquorum && delta < timeout) {
return cb(null, nData);
Expand Down Expand Up @@ -304,6 +305,8 @@ class DLMServer extends GenServer {
var lock = this._locks.get(data.id);
if (lock && lock.type() === "write") {
return this.reply(from, DLMServer.encodeResp({ok: false}));
} else if (lock && lock.holder().has(data.holder)) {
return this.reply(from, DLMServer.encodeResp({ok: true}));
}
var timeout = setTimeout(() => {
var lock = this._locks.get(data.id);
Expand Down

0 comments on commit f14b727

Please sign in to comment.