Finished lookup port, ported isLocked and removeLocks for absic and range types

This commit is contained in:
Dan Ballard 2011-02-28 23:40:37 -08:00
parent a5b83691e6
commit a3ccd10c8f
2 changed files with 126 additions and 30 deletions

View File

@ -425,6 +425,7 @@ function getLockType(type) {
return null; return null;
} }
/*
function isLocked(lockType, lockName, start, end) { function isLocked(lockType, lockName, start, end) {
if (lockType == "range") { if (lockType == "range") {
var rlock = getRangeLock(lockname, start, end); var rlock = getRangeLock(lockname, start, end);
@ -441,7 +442,7 @@ function isLocked(lockType, lockName, start, end) {
return true; return true;
} }
} }
*/
function loadTest(tname) { function loadTest(tname) {
if(tname == '') { if(tname == '') {
@ -1066,6 +1067,7 @@ function lookForWork() {
} }
} }
/*
function getRangeLock(name, start, end) { function getRangeLock(name, start, end) {
log("getRangeLock for (" + name + " from " + start + " to " + end + ")"); log("getRangeLock for (" + name + " from " + start + " to " + end + ")");
if (!rangeLocks[name]) { if (!rangeLocks[name]) {
@ -1116,6 +1118,7 @@ function getRangeLock(name, start, end) {
} }
} }
*/
function makeRangeLock(tlock, suggestedSize) { function makeRangeLock(tlock, suggestedSize) {
suggestedSize--; suggestedSize--;
@ -1169,6 +1172,7 @@ function makeRangeLock(tlock, suggestedSize) {
} }
} }
/*
function genRangeCell(name, start, end, next) { function genRangeCell(name, start, end, next) {
var c = new Object(); var c = new Object();
c.name = name; c.name = name;
@ -1178,7 +1182,7 @@ function genRangeCell(name, start, end, next) {
c.locked = false; c.locked = false;
c.done = false; c.done = false;
return c; return c;
} } */
var map_test = null; var map_test = null;
var reduce = null; var reduce = null;

View File

@ -29,9 +29,9 @@ function execLockFn(family, fnName, args) {
} }
/**** Lock Functions /**** Lock Functions
* retriveLock(details) # get lock data strict (lookup?) * BR retriveLock(details) # get lock data struct (lookup?)
* removeLocks(owner) * BR removeLocks(addr/owner)
* isLocked(details) * BR isLocked(details)
* getLock(details) # aquire lock (aquire?) * getLock(details) # aquire lock (aquire?)
* equals(a, b) * equals(a, b)
* lock * lock
@ -44,16 +44,127 @@ function (args) {
return args["locks"][args["name"]]; return args["locks"][args["name"]];
}); });
function genRangeCell(name, start, end, next) {
var c = new Object();
c.name = name;
c.start=start;
c.end = end;
c.next = next;
c.locked = false;
c.done = false;
return c;
}
function getRangeLock(rangeLocks, name, start, end) {
log("getRangeLock for (" + name + " from " + start + " to " + end + ")");
if (!rangeLocks[name]) {
log("no locks for " + name + ", so MAKING");
rangeLocks[name] = genRangeCell(name, start, end);
return rangeLocks[name];
}
log("locks exist for " + name + " so SEARCHING forward");
var rlock = rangeLocks[name];
if(end < rlock.start) {
log("Space before first lock, MAKING HERE");
rangeLocks[name] = genRangeCell(name, start, end);
rangeLocks[name].next = rlock;
return rangeLocks[name];
}
while(rlock.next && rlock.start < rlock.end+1) {
log("looking at (" + rlock.start + " to " + rlock.end + ")");
if (rlock.start == start && rlock.end == end) {
log("FOUND IT");
return rlock;
}
if (rlock.end < start && rlock.next.start > end) {
log("GAP between (" + rlock.start + " to " + rlock.end + ") and (" + rlock.next.start + " to " + rlock.next.end + ") where we should be so MAKING THERE");
var nlock = rlock.next;
rlock.next = genRangeCell(name, start, end);
rlock.next.next = nlock;
return rlock.next;
}
rlock = rlock.next;
}
log("SEARCH ended");
if (rlock.start == start && rlock.end == end) {
log("Found it!");
return rlock;
} else {
if (rlock.end < start) {
log("There is space at the end to make what we want");
rlock.next = genRangeCell(name, start, end);
return rlock.next;
} else {
log("search ended after what we wanted, FAIL");
return null;
}
}
}
registerLockFn("range", "lookup", registerLockFn("range", "lookup",
function (args) { function (args) {
/******* vvvvvvvvvv *********/ var l = getRangeLock(arg['locks'] , args['name'], args['start'], args'[end']);
var l = getRangeLock(struct.name, struct.start, struct.end);
if (l == null) if (l == null)
error("retrieveLock for range got null"); error("retrieveLock for range got null");
return l; return l;
}); });
registerLockFn("basic", "isLocked",
function(args) {
var locks = args['locks'];
if (locks[args['name']] == null)
return false;
else
return locks[args['name']].locked;
});
registerLockFn("range", "isLocked",
function (args) {
var rlock = getRangeLock(args['locks'], args['name'], args['start'], args['end']);
if (rlock)
return rlock.locked;
else
return false;
});
registerLockFn("basic", "removeLocks",
function(args) {
for(var i in args['locks']) {
var lock = args['locks'][i];
if (!lock)
continue;
if (lock.addr == addr) {
lock.locked = false;
}
}
});
registerLockFn("range", "removeLocks",
function(args) {
for(var i in args['locks']) {
log("freeing " + i + " locks");
var rlock = args['locks'][i];
while (rlock != null) {
log("looking at " + i + " (" + rlock.start + " to " + rlock.end + ") : " + rlock.addr);
if (rlock.addr == args['addr']) {
log("unlocking");
rlock.locked = false;
}
rlock = rlock.next;
}
}
});
/**** Logical Lock using functions /**** Logical Lock using functions
* grant(resp, lock * grant(resp, lock
* deny(resp, lock * deny(resp, lock
@ -109,7 +220,7 @@ function handleAddLock(resp) {
} }
} else if(resp['type'] == "range" && lock.addr == null) { } else if(resp['type'] == "range" && lock.addr == null) {
log("Add range lock: " + resp['name'] + " (" + resp['start'] + " to " + resp['end'] + ") : "); log("Add range lock: " + resp['name'] + " (" + resp['start'] + " to " + resp['end'] + ") : ");
var lock = getRangeLock(resp['name'], resp['start'], resp['end']); var lock = getRangeLock(LOCKS, resp['name'], resp['start'], resp['end']);
lock.addr = resp['addr']; lock.addr = resp['addr'];
lock.locked = resp['locked']; lock.locked = resp['locked'];
@ -119,22 +230,10 @@ function handleAddLock(resp) {
} }
} }
addMessageHandler("addLock", handlerAddLock());
function removeNodeRangeLocks(addr) {
for(var i in rangeLocks) {
log("freeing " + i + " locks");
var rlock = rangeLocks[i];
while (rlock != null) {
log("looking at " + i + " (" + rlock.start + " to " + rlock.end + ") : " + rlock.addr);
if (rlock.addr == addr) {
log("unlocking");
rlock.locked = false;
}
rlock = rlock.next;
}
}
}
function removeNodeLocks(addr) { function removeNodeLocks(addr) {
removeNodeRangeLocks(resp['addr']); removeNodeRangeLocks(resp['addr']);
@ -142,14 +241,7 @@ function removeNodeLocks(addr) {
addMsgHandler("deadNode", addMsgHandler("deadNode",
function (resp) { function (resp) {
for(var i in testLocks) { BASIC
var lock = testLocks[i];
if (!lock)
continue;
if (lock.addr == addr) {
lock.locked = false;
}
}
removeNodeLocks(resp['addr']); removeNodeLocks(resp['addr']);
}); });