Fix bugs related to tracking changes

This commit is contained in:
Zaid Abdulla committed 2016-10-28 16:29:34 -07:00
1 parent 7b0ea61596
commit 1bbef345e0
2 files changed
+24 -34

No files matched your search

+19 -29
View File
@@ -170,16 +170,16 @@ function unpack(deviceData, path, revision) {
function clear(deviceData, path, timestamp, attributes) { function clear(deviceData, path, timestamp, attributes) {
for (let p of deviceData.paths.all(path, timestamp ? 99 : 0)) { for (let p of deviceData.paths.all(path, timestamp ? 99 : 0)) {
for (let k in deviceData.trackers.get(p))
deviceData.changes.add(k);
let t = deviceData.timestamps.get(p); let t = deviceData.timestamps.get(p);
if (!t) if (!t)
continue; continue;
let changeFlags = 0;
if (!(timestamp <= t)) { if (!(timestamp <= t)) {
deviceData.timestamps.delete(p); deviceData.timestamps.delete(p);
deviceData.attributes.delete(p); deviceData.attributes.delete(p);
changeFlags |= 3;
} else if (t && attributes) { } else if (t && attributes) {
let currentAttributes = deviceData.attributes.get(p); let currentAttributes = deviceData.attributes.get(p);
if (currentAttributes) { if (currentAttributes) {
@@ -190,8 +190,6 @@ function clear(deviceData, path, timestamp, attributes) {
if (!newAttrs) if (!newAttrs)
newAttrs = JSON.parse(JSON.stringify(currentAttributes)); newAttrs = JSON.parse(JSON.stringify(currentAttributes));
delete newAttrs[attrName]; delete newAttrs[attrName];
changeFlags |= CHANGE_FLAGS[attrName];
changeFlags |= CHANGE_FLAGS[attrName] << 1;
} }
} }
@@ -199,14 +197,6 @@ function clear(deviceData, path, timestamp, attributes) {
deviceData.attributes.set(p, newAttrs); deviceData.attributes.set(p, newAttrs);
} }
} }
if (changeFlags)
for (let sup of deviceData.paths.superset(p)) {
let c = deviceData.trackers.get(sup);
for (let k in c)
if (c[k] & changeFlags)
deviceData.changes.add(k);
}
} }
} }
@@ -228,8 +218,6 @@ function compareEquality(a, b) {
function set(deviceData, path, timestamp, attributes, toClear) { function set(deviceData, path, timestamp, attributes, toClear) {
path = deviceData.paths.add(path); path = deviceData.paths.add(path);
let changeFlags = 0;
let currentTimestamp = deviceData.timestamps.get(path); let currentTimestamp = deviceData.timestamps.get(path);
let currentAttributes; let currentAttributes;
@@ -249,6 +237,8 @@ function set(deviceData, path, timestamp, attributes, toClear) {
attributes.value = [attributes.object[0]]; attributes.value = [attributes.object[0]];
if (currentAttributes) { if (currentAttributes) {
let changeFlags = 0;
for (let attrName in attributes) { for (let attrName in attributes) {
timestamp = Math.max(timestamp, attributes[attrName][0]); timestamp = Math.max(timestamp, attributes[attrName][0]);
if (attrName in currentAttributes) { if (attrName in currentAttributes) {
@@ -267,7 +257,8 @@ function set(deviceData, path, timestamp, attributes, toClear) {
} }
if (Object.keys(attributes).length) { if (Object.keys(attributes).length) {
if (attributes.object && attributes.object[1] === 0) { if (attributes.object && currentAttributes.object &&
attributes.object[1] !== currentAttributes.object[1]) {
toClear = toClear || []; toClear = toClear || [];
toClear.push([path.concat('*'), attributes.object[0]]); toClear.push([path.concat('*'), attributes.object[0]]);
} }
@@ -279,15 +270,24 @@ function set(deviceData, path, timestamp, attributes, toClear) {
} }
if (timestamp > currentTimestamp) { if (timestamp > currentTimestamp) {
changeFlags |= 1;
deviceData.timestamps.set(path, timestamp); deviceData.timestamps.set(path, timestamp);
if (path.length > 1) if (path.length > 1)
toClear = set(deviceData, path.slice(0, path.length - 1), timestamp, toClear = set(deviceData, path.slice(0, path.length - 1), timestamp,
{object: [timestamp, 1]}, toClear); {object: [timestamp, 1]}, toClear);
} }
if (changeFlags)
for (let sup of deviceData.paths.superset(path)) {
let c = deviceData.trackers.get(sup);
for (let k in c)
if (c[k] & changeFlags) {
deviceData.changes.add(k);
}
}
} }
else if (!(timestamp <= currentTimestamp)) { else if (!(timestamp <= currentTimestamp)) {
changeFlags |= 2;
deviceData.timestamps.set(path, timestamp); deviceData.timestamps.set(path, timestamp);
deviceData.attributes.set(path, attributes); deviceData.attributes.set(path, attributes);
@@ -300,11 +300,9 @@ function set(deviceData, path, timestamp, attributes, toClear) {
} }
} }
else if (!(timestamp <= currentTimestamp)) { else if (!(timestamp <= currentTimestamp)) {
changeFlags |= 1;
deviceData.timestamps.set(path, timestamp); deviceData.timestamps.set(path, timestamp);
if (currentAttributes) { if (currentAttributes) {
changeFlags |= 2;
deviceData.attributes.delete(path); deviceData.attributes.delete(path);
toClear = toClear || []; toClear = toClear || [];
toClear.push([path, timestamp]); toClear.push([path, timestamp]);
@@ -321,14 +319,6 @@ function set(deviceData, path, timestamp, attributes, toClear) {
} }
} }
if (changeFlags)
for (let sup of deviceData.paths.superset(path)) {
let c = deviceData.trackers.get(sup);
for (let k in c)
if (c[k] & changeFlags)
deviceData.changes.add(k);
}
return toClear; return toClear;
} }
@@ -344,11 +334,11 @@ function track(deviceData, path, marker, timestamp, attributeTimestamps, exist,
f |= 2; f |= 2;
if (attributeTimestamps) if (attributeTimestamps)
for (let attrName in attributeTimestamps) for (let attrName of attributeTimestamps)
f |= CHANGE_FLAGS[attrName]; f |= CHANGE_FLAGS[attrName];
if (attributeValues) if (attributeValues)
for (let attrName in attributeValues) for (let attrName of attributeValues)
f |= CHANGE_FLAGS[attrName] << 1; f |= CHANGE_FLAGS[attrName] << 1;
let cur = deviceData.trackers.get(path); let cur = deviceData.trackers.get(path);
+5 -5
View File
@@ -442,10 +442,6 @@ rpcRequest = (sessionData, _declarations, callback) ->
) )
) )
if sessionData.deviceData.changes.has('prerequisite')
delete sessionData.syncState
device.clearTrackers(sessionData.deviceData, 'prerequisite')
if _declarations?.length if _declarations?.length
delete sessionData.syncState delete sessionData.syncState
sessionData.declarations[0] ?= [] sessionData.declarations[0] ?= []
@@ -493,6 +489,11 @@ rpcRequest = (sessionData, _declarations, callback) ->
if not provisions if not provisions
sessionData.rpcRequest = generateGetRpcRequest(sessionData) sessionData.rpcRequest = generateGetRpcRequest(sessionData)
if not sessionData.rpcRequest if not sessionData.rpcRequest
if sessionData.deviceData.changes.has('prerequisite')
delete sessionData.syncState
device.clearTrackers(sessionData.deviceData, 'prerequisite')
return rpcRequest(sessionData, null, callback)
provisions = generateSetVirtualParameterProvisions(sessionData, sessionData.syncState.virtualParameterDeclarations[inception]) provisions = generateSetVirtualParameterProvisions(sessionData, sessionData.syncState.virtualParameterDeclarations[inception])
if not provisions if not provisions
sessionData.rpcRequest = generateSetRpcRequest(sessionData) sessionData.rpcRequest = generateSetRpcRequest(sessionData)
@@ -814,7 +815,6 @@ processDeclarations = (sessionData, allDeclareTimestamps, allDeclareAttributeTim
for attrName of attrs for attrName of attrs
declareAttributeValues[attrName] = attrs[attrName] declareAttributeValues[attrName] = attrs[attrName]
aaa = (if currentPath[0] != '*' then currentPath[0] else leafParam[0])
switch (if currentPath[0] != '*' then currentPath[0] else leafParam[0]) switch (if currentPath[0] != '*' then currentPath[0] else leafParam[0])
when 'Reboot' when 'Reboot'
if currentPath.length == 1 if currentPath.length == 1