Commit edd23f40 authored by Sven Franck's avatar Sven Franck

libs/jio: correctly set 404 on master/slave replicatestorage

parent 6e05fa15
...@@ -347,7 +347,6 @@ ...@@ -347,7 +347,6 @@
// setup master storage or all // setup master storage or all
if (master !== undefined) { if (master !== undefined) {
console.log("INTO MASTER")
priority_list[0] = success( priority_list[0] = success(
command.storage(storages[master]).put(metadata, option) command.storage(storages[master]).put(metadata, option)
); );
...@@ -369,10 +368,10 @@ ...@@ -369,10 +368,10 @@
switch (true) { switch (true) {
// NOTE: this means if the master is 503, nothing will be saved on // NOTE: this means if the master is 503, nothing will be saved on
// the slave? Is this what I would want? // the slave? Is this what I would want? YES
case response.status >= 500: case response.status >= 500:
// command.error(response); command.error(response);
// break; break;
// HACK: why does 204 return status code 0 on promises? // HACK: why does 204 return status code 0 on promises?
case response.status === 0: case response.status === 0:
default: default:
...@@ -466,14 +465,16 @@ ...@@ -466,14 +465,16 @@
sequence([function () { sequence([function () {
return all(promise_list); return all(promise_list);
}, function (answers) { }, function (answers) {
var i, j, k, l, record, reply, rows, count, total, base, test, must_add, var i, j, k, l, record, reply, count, total, base, test, must_add,
len = answers.length; empty_reply, rows_len, rows, len = answers.length;
// NOTE: every storage may return different records!
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
reply = answers[i]; reply = answers[i];
if (reply.result === "success") { if (reply.result === "success") {
total = reply.data.total_rows; total = reply.data.total_rows;
if (total === 0) {
empty_reply = true;
}
// loop records returned in response // loop records returned in response
for (j = 0; j < total; j += 1) { for (j = 0; j < total; j += 1) {
...@@ -488,12 +489,11 @@ ...@@ -488,12 +489,11 @@
// loop records already in rows object // loop records already in rows object
for (k = 0; k < count; k += 1) { for (k = 0; k < count; k += 1) {
base = rows[k]; base = rows[k];
test = checksum(cleanClone(base));
// record exists, test for coherence // record exists, test for coherence
if (base.id === record.id) { if (base.id === record.id) {
must_add = undefined; must_add = undefined;
if (test !== checksum(record)) { if (checksum(cleanClone(base)) !== checksum(record)) {
if (!base._conflict_list) { if (!base._conflict_list) {
base._conflict_list = [base]; base._conflict_list = [base];
} }
...@@ -504,7 +504,7 @@ ...@@ -504,7 +504,7 @@
must_add = true; must_add = true;
} }
} }
// add missing records // add missing record
if (must_add) { if (must_add) {
// if on 2+ iteration, this means a 404 on previous storages // if on 2+ iteration, this means a 404 on previous storages
if (i > 0) { if (i > 0) {
...@@ -518,9 +518,9 @@ ...@@ -518,9 +518,9 @@
} }
// if a storage returns rows = 0, make sure all records are labelled // if a storage returns rows = 0, make sure all records are labelled
if (total === 0) { rows_len = (rows || []).length;
rows = rows || []; if (empty_reply && rows_len > 0) {
for (l = 0; l < rows.length; l += 1) { for (l = 0; l < rows_len; l += 1) {
rows[l]._missing = true; rows[l]._missing = true;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment