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 @@
// setup master storage or all
if (master !== undefined) {
console.log("INTO MASTER")
priority_list[0] = success(
command.storage(storages[master]).put(metadata, option)
);
......@@ -369,10 +368,10 @@
switch (true) {
// 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:
// command.error(response);
// break;
command.error(response);
break;
// HACK: why does 204 return status code 0 on promises?
case response.status === 0:
default:
......@@ -466,14 +465,16 @@
sequence([function () {
return all(promise_list);
}, function (answers) {
var i, j, k, l, record, reply, rows, count, total, base, test, must_add,
len = answers.length;
var i, j, k, l, record, reply, count, total, base, test, must_add,
empty_reply, rows_len, rows, len = answers.length;
// NOTE: every storage may return different records!
for (i = 0; i < len; i += 1) {
reply = answers[i];
if (reply.result === "success") {
total = reply.data.total_rows;
if (total === 0) {
empty_reply = true;
}
// loop records returned in response
for (j = 0; j < total; j += 1) {
......@@ -488,12 +489,11 @@
// loop records already in rows object
for (k = 0; k < count; k += 1) {
base = rows[k];
test = checksum(cleanClone(base));
// record exists, test for coherence
if (base.id === record.id) {
must_add = undefined;
if (test !== checksum(record)) {
if (checksum(cleanClone(base)) !== checksum(record)) {
if (!base._conflict_list) {
base._conflict_list = [base];
}
......@@ -504,7 +504,7 @@
must_add = true;
}
}
// add missing records
// add missing record
if (must_add) {
// if on 2+ iteration, this means a 404 on previous storages
if (i > 0) {
......@@ -518,9 +518,9 @@
}
// if a storage returns rows = 0, make sure all records are labelled
if (total === 0) {
rows = rows || [];
for (l = 0; l < rows.length; l += 1) {
rows_len = (rows || []).length;
if (empty_reply && rows_len > 0) {
for (l = 0; l < rows_len; l += 1) {
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