Commit b43cb6f5 authored by Tristan Cavelier's avatar Tristan Cavelier

add check and repair to replicaterevisionstorage

parent 25323eb5
...@@ -189,20 +189,30 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -189,20 +189,30 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
that.check = function (command) { that.check = function (command) {
function callback(err, response) {
if (err) {
return that.error(err);
}
that.success(response);
}
priv.check( priv.check(
command.cloneDoc(), command.cloneDoc(),
command.cloneOption(), command.cloneOption(),
that.success, callback
that.error
); );
}; };
that.repair = function (command) { that.repair = function (command) {
function callback(err, response) {
if (err) {
return that.error(err);
}
that.success(response);
}
priv.repair( priv.repair(
command.cloneDoc(), command.cloneDoc(),
command.cloneOption(), command.cloneOption(),
true, true,
that.success, callback
that.error
); );
}; };
priv.check = function (doc, option, success, error) { priv.check = function (doc, option, success, error) {
...@@ -213,11 +223,33 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -213,11 +223,33 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
callback = callback || priv.emptyFunction; callback = callback || priv.emptyFunction;
option = option || {}; option = option || {};
functions.begin = function () { functions.begin = function () {
// };
// functions.repairAllSubStorages = function () {
var i;
for (i = 0; i < priv.storage_list.length; i += 1) {
priv.send(
repair ? "repair" : "check",
i,
doc,
option,
functions.repairAllSubStoragesCallback
);
}
};
functions.repair_sub_storages_count = 0;
functions.repairAllSubStoragesCallback = function (method,
index, err, response) {
if (err) {
return that.error(err);
}
functions.repair_sub_storages_count += 1;
if (functions.repair_sub_storages_count === priv.storage_list.length) {
functions.getAllDocuments(functions.newParam( functions.getAllDocuments(functions.newParam(
doc, doc,
option, option,
repair repair
)); ));
}
}; };
functions.newParam = function (doc, option, repair) { functions.newParam = function (doc, option, repair) {
var param = { var param = {
...@@ -255,7 +287,6 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -255,7 +287,6 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
option.conflicts = true; option.conflicts = true;
option.revs = true; option.revs = true;
option.revs_info = true; option.revs_info = true;
option.repair = false;
for (i = 0; i < priv.storage_list.length; i += 1) { for (i = 0; i < priv.storage_list.length; i += 1) {
// if the document is not loaded // if the document is not loaded
priv.send("get", i, doc, option, functions.dealResults(param)); priv.send("get", i, doc, option, functions.dealResults(param));
...@@ -264,6 +295,7 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -264,6 +295,7 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
}; };
functions.dealResults = function (param) { functions.dealResults = function (param) {
return function (method, index, err, response) { return function (method, index, err, response) {
var response_object = {};
if (param.deal_result_state !== "ok") { if (param.deal_result_state !== "ok") {
// deal result is in a wrong state, exit // deal result is in a wrong state, exit
return; return;
...@@ -278,7 +310,7 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -278,7 +310,7 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
"error": "check_failed", "error": "check_failed",
"message": "An error occured on the sub storage", "message": "An error occured on the sub storage",
"reason": err.reason "reason": err.reason
}); }, undefined);
return; return;
} }
} }
...@@ -298,12 +330,14 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -298,12 +330,14 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
functions.makeResponsesStats(param.responses); functions.makeResponsesStats(param.responses);
if (param.responses.stats_items.length === 1) { if (param.responses.stats_items.length === 1) {
// the responses are equals! // the responses are equals!
callback(undefined, { response_object.ok = true;
"ok": true, response_object.id = param.doc._id;
"id": param.doc._id, if (doc._rev) {
"rev": (typeof param.responses.list[0] === "object" ? response_object.rev = doc._rev;
param.responses.list[0]._rev : undefined) // "rev": (typeof param.responses.list[0] === "object" ?
}); // param.responses.list[0]._rev : undefined)
}
callback(undefined, response_object);
return; return;
} }
// the responses are different // the responses are different
...@@ -315,7 +349,7 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -315,7 +349,7 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
"error": "check_not_ok", "error": "check_not_ok",
"message": "Some documents are different in the sub storages", "message": "Some documents are different in the sub storages",
"reason": "Storage contents differ" "reason": "Storage contents differ"
}); }, undefined);
return; return;
} }
// repair // repair
...@@ -408,9 +442,15 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -408,9 +442,15 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
}; };
functions.finished_count = 0; functions.finished_count = 0;
functions.finished = function () { functions.finished = function () {
var response_object = {};
functions.finished_count -= 1; functions.finished_count -= 1;
if (functions.finished_count === 0) { if (functions.finished_count === 0) {
callback(undefined, {"ok": true, "id": doc._id}); response_object.ok = true;
response_object.id = doc._id;
if (doc._rev) {
response_object.rev = doc._rev;
}
callback(undefined, response_object);
} }
}; };
functions.begin(); functions.begin();
...@@ -627,11 +667,6 @@ jIO.addStorageType('replicaterevision', function (spec, my) { ...@@ -627,11 +667,6 @@ jIO.addStorageType('replicaterevision', function (spec, my) {
} }
} }
that.success(response); that.success(response);
if (command.getOption("repair") === true) {
setTimeout(function () {
priv.repair({"_id": doc._id}, command.cloneOption(), true);
});
}
}; };
functions.error_count = 0; functions.error_count = 0;
functions.error = function (err) { functions.error = function (err) {
......
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