port = parseInt(process.argv[5]);
}
+// gRPC backends.
+var grpc_backends = ["localhost:50051", "localhost:50052"];
+if (process.argv.length >= 7) {
+ grpc_backends = process.argv[6].split(",");
+}
+hash_lookup.init(grpc_backends);
+
// If set to 1, we are already processing a JSON update and should not
// start a new one. If set to 2, we are _also_ having one in the queue.
var json_lock = 0;
}
}
+ var parsed = JSON.parse(new_json_contents);
+
+ if (parsed['internal']) {
+ if (parsed['internal']['grpc_backends'] &&
+ hash_lookup.need_reinit(parsed['internal']['grpc_backends'])) {
+ hash_lookup.init(parsed['internal']['grpc_backends']);
+ }
+ delete parsed['internal'];
+ new_json_contents = JSON.stringify(parsed);
+ }
+
var new_json = {
- parsed: JSON.parse(new_json_contents),
+ parsed: parsed,
plain: new_json_contents,
last_modified: mtime
};
var histobj = history_left.shift();
var diff = delta.JSON_delta.diff(histobj.parsed, new_json.parsed);
var diff_text = JSON.stringify(diff);
+
+ // Verify that the delta is correct
+ var base = JSON.parse(histobj.plain);
+ delta.JSON_delta.patch(base, diff);
+ var correct_pv = JSON.stringify(base['pv']);
+ var wrong_pv = JSON.stringify(new_json.parsed['pv']);
+ if (correct_pv !== wrong_pv) {
+ console.log("Patch went wrong:", histobj.plain, new_json.plain);
+ exit();
+ }
+
zlib.gzip(diff_text, function(err, buffer) {
if (err) throw err;
new_diff_json[histobj.last_modified] = {
if (json_lock == 1) {
// Already processing; wait a bit.
json_lock = 2;
- setTimeout(function() { json_lock = 1; reread_file(event, filename); }, 100);
+ setTimeout(function() { if (json_lock == 2) json_lock = 1; reread_file(event, filename); }, 100);
return;
}
json_lock = 1;
touch_timer = setTimeout(function() {
console.log("Touching analysis.json due to no other activity");
var now = Date.now() / 1000;
- fs.utimes(json_filename, now, now);
+ fs.utimes(json_filename, now, now, function() {});
}, 30000);
}
var possibly_wakeup_clients = function() {