mirror of https://gitee.com/bigwinds/arangodb
changed sync to actively wait for result to avoid timeouts
This commit is contained in:
parent
3b1c3cd37d
commit
e98c8b0758
|
@ -30,8 +30,6 @@
|
|||
var internal = require("internal");
|
||||
var arangosh = require("@arangodb/arangosh");
|
||||
|
||||
|
||||
|
||||
var logger = {};
|
||||
var applier = {};
|
||||
|
||||
|
@ -141,8 +139,7 @@ applier.properties = function (config) {
|
|||
var requestResult;
|
||||
if (config === undefined) {
|
||||
requestResult = db._connection.GET("/_api/replication/applier-config");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
requestResult = db._connection.PUT("/_api/replication/applier-config",
|
||||
JSON.stringify(config));
|
||||
}
|
||||
|
@ -158,24 +155,40 @@ applier.properties = function (config) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var sync = function(config) {
|
||||
var db = internal.db;
|
||||
const db = internal.db;
|
||||
|
||||
const body = JSON.stringify(config || {});
|
||||
const headers = {
|
||||
"X-Arango-Async": "store"
|
||||
};
|
||||
|
||||
var body = JSON.stringify(config || { });
|
||||
var requestResult;
|
||||
if (config.async) {
|
||||
var headers = { "X-Arango-Async" : "store" };
|
||||
requestResult = db._connection.PUT_RAW("/_api/replication/sync", body, headers);
|
||||
}
|
||||
else {
|
||||
requestResult = db._connection.PUT("/_api/replication/sync", body);
|
||||
}
|
||||
|
||||
const requestResult = db._connection.PUT_RAW("/_api/replication/sync", body, headers);
|
||||
arangosh.checkRequestResult(requestResult);
|
||||
if (config.async) {
|
||||
|
||||
return requestResult.headers["x-arango-async-id"];
|
||||
} else {
|
||||
const requestResult = db._connection.PUT_RAW("/_api/replication/sync", body, headers);
|
||||
arangosh.checkRequestResult(requestResult);
|
||||
|
||||
let count = 0;
|
||||
|
||||
while (true) {
|
||||
const jobResult = db._connection.PUT(
|
||||
"/_api/job/" + requestResult.headers["x-arango-async-id"], "");
|
||||
arangosh.checkRequestResult(jobResult);
|
||||
|
||||
if (jobResult.code !== 204) {
|
||||
return jobResult;
|
||||
}
|
||||
|
||||
return requestResult;
|
||||
if (++count % 6 === 0) {
|
||||
internal.print("still synchronizing, please wait...");
|
||||
}
|
||||
|
||||
internal.sleep(10);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -193,10 +206,11 @@ var syncCollection = function (collection, config) {
|
|||
var body = JSON.stringify(config);
|
||||
var requestResult;
|
||||
if (config.async) {
|
||||
var headers = { "X-Arango-Async" : "store" };
|
||||
var headers = {
|
||||
"X-Arango-Async": "store"
|
||||
};
|
||||
requestResult = db._connection.PUT_RAW("/_api/replication/sync", body, headers);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
requestResult = db._connection.PUT("/_api/replication/sync", body);
|
||||
}
|
||||
|
||||
|
@ -242,5 +256,3 @@ exports.sync = sync;
|
|||
exports.syncCollection = syncCollection;
|
||||
exports.getSyncResult = getSyncResult;
|
||||
exports.serverId = serverId;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue