mirror of https://gitee.com/bigwinds/arangodb
pass transaction options into AQL queries
This commit is contained in:
parent
145ba83d04
commit
d24455c682
|
@ -29,6 +29,7 @@
|
|||
#include "Aql/Collection.h"
|
||||
#include "Transaction/StandaloneContext.h"
|
||||
#include "Transaction/Methods.h"
|
||||
#include "Transaction/Options.h"
|
||||
#include "VocBase/vocbase.h"
|
||||
|
||||
namespace arangodb {
|
||||
|
@ -41,9 +42,11 @@ class AqlTransaction final : public transaction::Methods {
|
|||
AqlTransaction(
|
||||
std::shared_ptr<transaction::Context> const& transactionContext,
|
||||
std::map<std::string, aql::Collection*> const* collections,
|
||||
transaction::Options const& options,
|
||||
bool isMainTransaction)
|
||||
: transaction::Methods(transactionContext),
|
||||
_collections(*collections) {
|
||||
: transaction::Methods(transactionContext, options),
|
||||
_collections(*collections),
|
||||
_options(options) {
|
||||
if (!isMainTransaction) {
|
||||
addHint(transaction::Hints::Hint::LOCK_NEVER);
|
||||
} else {
|
||||
|
@ -91,7 +94,7 @@ class AqlTransaction final : public transaction::Methods {
|
|||
/// AQL query running on the coordinator
|
||||
transaction::Methods* clone() const override {
|
||||
return new AqlTransaction(transaction::StandaloneContext::Create(vocbase()),
|
||||
&_collections, false);
|
||||
&_collections, _options, false);
|
||||
}
|
||||
|
||||
/// @brief lockCollections, this is needed in a corner case in AQL: we need
|
||||
|
@ -106,6 +109,7 @@ class AqlTransaction final : public transaction::Methods {
|
|||
/// operation
|
||||
private:
|
||||
std::map<std::string, aql::Collection*> _collections;
|
||||
transaction::Options _options;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -342,6 +342,7 @@ void Query::prepare(QueryRegistry* registry, uint64_t queryHash) {
|
|||
// create the transaction object, but do not start it yet
|
||||
AqlTransaction* trx = new AqlTransaction(
|
||||
createTransactionContext(), _collections.collections(),
|
||||
_queryOptions.transactionOptions,
|
||||
_part == PART_MAIN);
|
||||
_trx = trx;
|
||||
|
||||
|
@ -429,8 +430,8 @@ ExecutionPlan* Query::prepare() {
|
|||
|
||||
// create the transaction object, but do not start it yet
|
||||
AqlTransaction* trx = new AqlTransaction(
|
||||
createTransactionContext(), _collections.collections(),
|
||||
_part == PART_MAIN);
|
||||
createTransactionContext(), _collections.collections(),
|
||||
_queryOptions.transactionOptions, _part == PART_MAIN);
|
||||
_trx = trx;
|
||||
|
||||
// As soon as we start du instantiate the plan we have to clean it
|
||||
|
@ -919,7 +920,8 @@ QueryResult Query::explain() {
|
|||
|
||||
// create the transaction object, but do not start it yet
|
||||
_trx = new AqlTransaction(createTransactionContext(),
|
||||
_collections.collections(), true);
|
||||
_collections.collections(),
|
||||
_queryOptions.transactionOptions, true);
|
||||
|
||||
// we have an AST
|
||||
Result res = _trx->begin();
|
||||
|
|
|
@ -172,6 +172,9 @@ void QueryOptions::fromVelocyPack(VPackSlice const& slice) {
|
|||
it.next();
|
||||
}
|
||||
}
|
||||
|
||||
// also handle transaction options
|
||||
transactionOptions.fromVelocyPack(slice);
|
||||
}
|
||||
|
||||
void QueryOptions::toVelocyPack(VPackBuilder& builder, bool disableOptimizerRules) const {
|
||||
|
@ -216,6 +219,9 @@ void QueryOptions::toVelocyPack(VPackBuilder& builder, bool disableOptimizerRule
|
|||
}
|
||||
builder.close(); // shardIds
|
||||
}
|
||||
|
||||
// also handle transaction options
|
||||
transactionOptions.toVelocyPack(builder);
|
||||
|
||||
builder.close();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#define ARANGOD_AQL_QUERY_OPTIONS_H 1
|
||||
|
||||
#include "Basics/Common.h"
|
||||
#include "Transaction/Options.h"
|
||||
|
||||
namespace arangodb {
|
||||
namespace velocypack {
|
||||
|
@ -58,6 +59,8 @@ struct QueryOptions {
|
|||
bool inspectSimplePlans;
|
||||
std::vector<std::string> optimizerRules;
|
||||
std::unordered_set<std::string> shardIds;
|
||||
|
||||
transaction::Options transactionOptions;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ BaseEngine::BaseEngine(TRI_vocbase_t* vocbase, VPackSlice info)
|
|||
|
||||
_trx = new arangodb::aql::AqlTransaction(
|
||||
arangodb::transaction::StandaloneContext::Create(vocbase),
|
||||
_collections.collections(), true);
|
||||
_collections.collections(), transaction::Options(), true);
|
||||
// true here as last argument is crucial: it leads to the fact that the
|
||||
// created transaction is considered a "MAIN" part and will not switch
|
||||
// off collection locking completely!
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
|
||||
#include "Options.h"
|
||||
|
||||
#include <velocypack/Builder.h>
|
||||
#include <velocypack/Slice.h>
|
||||
#include <velocypack/velocypack-aliases.h>
|
||||
|
||||
using namespace arangodb::transaction;
|
||||
|
||||
uint64_t Options::defaultMaxTransactionSize = UINT64_MAX;
|
||||
|
@ -42,3 +46,44 @@ void Options::setLimits(uint64_t maxTransactionSize, uint64_t intermediateCommit
|
|||
defaultIntermediateCommitSize = intermediateCommitSize;
|
||||
defaultIntermediateCommitCount = intermediateCommitCount;
|
||||
}
|
||||
|
||||
void Options::fromVelocyPack(arangodb::velocypack::Slice const& slice) {
|
||||
VPackSlice value;
|
||||
|
||||
value = slice.get("lockTimeout");
|
||||
if (value.isNumber()) {
|
||||
lockTimeout = value.getNumber<double>();
|
||||
}
|
||||
value = slice.get("maxTransactionSize");
|
||||
if (value.isNumber()) {
|
||||
maxTransactionSize = value.getNumber<uint64_t>();
|
||||
}
|
||||
value = slice.get("intermediateCommitSize");
|
||||
if (value.isNumber()) {
|
||||
intermediateCommitSize = value.getNumber<uint64_t>();
|
||||
}
|
||||
value = slice.get("intermediateCommitCount");
|
||||
if (value.isNumber()) {
|
||||
intermediateCommitCount = value.getNumber<uint64_t>();
|
||||
}
|
||||
value = slice.get("allowImplicitCollections");
|
||||
if (value.isBool()) {
|
||||
allowImplicitCollections = value.getBool();
|
||||
}
|
||||
value = slice.get("waitForSync");
|
||||
if (value.isBool()) {
|
||||
waitForSync = value.getBool();
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief add the options to an opened vpack builder
|
||||
void Options::toVelocyPack(arangodb::velocypack::Builder& builder) const {
|
||||
TRI_ASSERT(builder.isOpenObject());
|
||||
|
||||
builder.add("lockTimeout", VPackValue(lockTimeout));
|
||||
builder.add("maxTransactionSize", VPackValue(maxTransactionSize));
|
||||
builder.add("intermediateCommitSize", VPackValue(intermediateCommitSize));
|
||||
builder.add("intermediateCommitCount", VPackValue(intermediateCommitCount));
|
||||
builder.add("allowImplicitCollections", VPackValue(allowImplicitCollections));
|
||||
builder.add("waitForSync", VPackValue(waitForSync));
|
||||
}
|
||||
|
|
|
@ -27,12 +27,25 @@
|
|||
#include "Basics/Common.h"
|
||||
|
||||
namespace arangodb {
|
||||
namespace velocypack {
|
||||
class Builder;
|
||||
class Slice;
|
||||
}
|
||||
|
||||
namespace transaction {
|
||||
|
||||
struct Options {
|
||||
Options();
|
||||
|
||||
/// @brief adjust the global default values for transactions
|
||||
static void setLimits(uint64_t maxTransactionSize, uint64_t intermediateCommitSize, uint64_t intermediateCommitCount);
|
||||
|
||||
/// @brief read the options from a vpack slice
|
||||
void fromVelocyPack(arangodb::velocypack::Slice const&);
|
||||
|
||||
/// @brief add the options to an opened vpack builder
|
||||
void toVelocyPack(arangodb::velocypack::Builder&) const;
|
||||
|
||||
static constexpr double defaultLockTimeout = 900.0;
|
||||
static uint64_t defaultMaxTransactionSize;
|
||||
static uint64_t defaultIntermediateCommitSize;
|
||||
|
|
Loading…
Reference in New Issue