mirror of https://gitee.com/bigwinds/arangodb
fixed hanging test
This commit is contained in:
parent
f422576ee0
commit
1fc4c0d34e
|
@ -671,6 +671,7 @@ ArangoCollection.prototype.removeByExample = function (example,
|
||||||
if (limit === 0) {
|
if (limit === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof waitForSync === "object") {
|
if (typeof waitForSync === "object") {
|
||||||
if (typeof limit !== "undefined") {
|
if (typeof limit !== "undefined") {
|
||||||
throw "too many parameters";
|
throw "too many parameters";
|
||||||
|
@ -682,6 +683,48 @@ ArangoCollection.prototype.removeByExample = function (example,
|
||||||
limit = tmp_options.limit;
|
limit = tmp_options.limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var i;
|
||||||
|
var cluster = require("@arangodb/cluster");
|
||||||
|
|
||||||
|
if (cluster.isCoordinator()) {
|
||||||
|
var dbName = require("internal").db._name();
|
||||||
|
var shards = cluster.shardList(dbName, this.name());
|
||||||
|
var coord = { coordTransactionID: ArangoClusterInfo.uniqid() };
|
||||||
|
var options = { coordTransactionID: coord.coordTransactionID, timeout: 360 };
|
||||||
|
|
||||||
|
if (limit > 0 && shards.length > 1) {
|
||||||
|
var err = new ArangoError();
|
||||||
|
err.errorNum = internal.errors.ERROR_CLUSTER_UNSUPPORTED.code;
|
||||||
|
err.errorMessage = "limit is not supported in sharded collections";
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
shards.forEach(function (shard) {
|
||||||
|
ArangoClusterComm.asyncRequest("put",
|
||||||
|
"shard:" + shard,
|
||||||
|
dbName,
|
||||||
|
"/_api/simple/remove-by-example",
|
||||||
|
JSON.stringify({
|
||||||
|
collection: shard,
|
||||||
|
example: example,
|
||||||
|
waitForSync: waitForSync,
|
||||||
|
limit: limit || undefined
|
||||||
|
}),
|
||||||
|
{ },
|
||||||
|
options);
|
||||||
|
});
|
||||||
|
|
||||||
|
var deleted = 0;
|
||||||
|
var results = cluster.wait(coord, shards);
|
||||||
|
for (i = 0; i < results.length; ++i) {
|
||||||
|
var body = JSON.parse(results[i].body);
|
||||||
|
deleted += (body.deleted || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
var query = buildExampleQuery(this, example, limit);
|
var query = buildExampleQuery(this, example, limit);
|
||||||
var opts = { waitForSync : waitForSync };
|
var opts = { waitForSync : waitForSync };
|
||||||
query.query += " REMOVE doc IN @@collection OPTIONS " + JSON.stringify(opts);
|
query.query += " REMOVE doc IN @@collection OPTIONS " + JSON.stringify(opts);
|
||||||
|
@ -728,6 +771,48 @@ ArangoCollection.prototype.replaceByExample = function (example,
|
||||||
limit = tmp_options.limit;
|
limit = tmp_options.limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cluster = require("@arangodb/cluster");
|
||||||
|
|
||||||
|
if (cluster.isCoordinator()) {
|
||||||
|
var dbName = require("internal").db._name();
|
||||||
|
var shards = cluster.shardList(dbName, this.name());
|
||||||
|
var coord = { coordTransactionID: ArangoClusterInfo.uniqid() };
|
||||||
|
var options = { coordTransactionID: coord.coordTransactionID, timeout: 360 };
|
||||||
|
|
||||||
|
if (limit > 0 && shards.length > 1) {
|
||||||
|
var err2 = new ArangoError();
|
||||||
|
err2.errorNum = internal.errors.ERROR_CLUSTER_UNSUPPORTED.code;
|
||||||
|
err2.errorMessage = "limit is not supported in sharded collections";
|
||||||
|
|
||||||
|
throw err2;
|
||||||
|
}
|
||||||
|
|
||||||
|
shards.forEach(function (shard) {
|
||||||
|
ArangoClusterComm.asyncRequest("put",
|
||||||
|
"shard:" + shard,
|
||||||
|
dbName,
|
||||||
|
"/_api/simple/replace-by-example",
|
||||||
|
JSON.stringify({
|
||||||
|
collection: shard,
|
||||||
|
example: example,
|
||||||
|
newValue: newValue,
|
||||||
|
waitForSync: waitForSync,
|
||||||
|
limit: limit || undefined
|
||||||
|
}),
|
||||||
|
{ },
|
||||||
|
options);
|
||||||
|
});
|
||||||
|
|
||||||
|
var replaced = 0;
|
||||||
|
var results = cluster.wait(coord, shards), i;
|
||||||
|
for (i = 0; i < results.length; ++i) {
|
||||||
|
var body = JSON.parse(results[i].body);
|
||||||
|
replaced += (body.replaced || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return replaced;
|
||||||
|
}
|
||||||
|
|
||||||
var query = buildExampleQuery(this, example, limit);
|
var query = buildExampleQuery(this, example, limit);
|
||||||
var opts = { waitForSync : waitForSync };
|
var opts = { waitForSync : waitForSync };
|
||||||
query.query += " REPLACE doc WITH @newValue IN @@collection OPTIONS " + JSON.stringify(opts);
|
query.query += " REPLACE doc WITH @newValue IN @@collection OPTIONS " + JSON.stringify(opts);
|
||||||
|
@ -785,6 +870,49 @@ ArangoCollection.prototype.updateByExample = function (example,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cluster = require("@arangodb/cluster");
|
||||||
|
|
||||||
|
if (cluster.isCoordinator()) {
|
||||||
|
var dbName = require("internal").db._name();
|
||||||
|
var shards = cluster.shardList(dbName, this.name());
|
||||||
|
var coord = { coordTransactionID: ArangoClusterInfo.uniqid() };
|
||||||
|
var options = { coordTransactionID: coord.coordTransactionID, timeout: 360 };
|
||||||
|
|
||||||
|
if (limit > 0 && shards.length > 1) {
|
||||||
|
var err2 = new ArangoError();
|
||||||
|
err2.errorNum = internal.errors.ERROR_CLUSTER_UNSUPPORTED.code;
|
||||||
|
err2.errorMessage = "limit is not supported in sharded collections";
|
||||||
|
|
||||||
|
throw err2;
|
||||||
|
}
|
||||||
|
|
||||||
|
shards.forEach(function (shard) {
|
||||||
|
ArangoClusterComm.asyncRequest("put",
|
||||||
|
"shard:" + shard,
|
||||||
|
dbName,
|
||||||
|
"/_api/simple/update-by-example",
|
||||||
|
JSON.stringify({
|
||||||
|
collection: shard,
|
||||||
|
example: example,
|
||||||
|
newValue: newValue,
|
||||||
|
waitForSync: waitForSync,
|
||||||
|
keepNull: keepNull,
|
||||||
|
mergeObjects: mergeObjects,
|
||||||
|
limit: limit || undefined
|
||||||
|
}),
|
||||||
|
{ },
|
||||||
|
options);
|
||||||
|
});
|
||||||
|
|
||||||
|
var updated = 0;
|
||||||
|
var results = cluster.wait(coord, shards), i;
|
||||||
|
for (i = 0; i < results.length; ++i) {
|
||||||
|
var body = JSON.parse(results[i].body);
|
||||||
|
updated += (body.updated || 0);
|
||||||
|
}
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
var query = buildExampleQuery(this, example, limit);
|
var query = buildExampleQuery(this, example, limit);
|
||||||
var opts = { waitForSync : waitForSync, keepNull: keepNull, mergeObjects: mergeObjects };
|
var opts = { waitForSync : waitForSync, keepNull: keepNull, mergeObjects: mergeObjects };
|
||||||
query.query += " UPDATE doc WITH @newValue IN @@collection OPTIONS " + JSON.stringify(opts);
|
query.query += " UPDATE doc WITH @newValue IN @@collection OPTIONS " + JSON.stringify(opts);
|
||||||
|
|
Loading…
Reference in New Issue