1
0
Fork 0

pass transaction options into AQL queries

This commit is contained in:
jsteemann 2017-05-31 16:23:04 +02:00
parent 145ba83d04
commit d24455c682
7 changed files with 80 additions and 7 deletions

View File

@ -29,6 +29,7 @@
#include "Aql/Collection.h" #include "Aql/Collection.h"
#include "Transaction/StandaloneContext.h" #include "Transaction/StandaloneContext.h"
#include "Transaction/Methods.h" #include "Transaction/Methods.h"
#include "Transaction/Options.h"
#include "VocBase/vocbase.h" #include "VocBase/vocbase.h"
namespace arangodb { namespace arangodb {
@ -41,9 +42,11 @@ class AqlTransaction final : public transaction::Methods {
AqlTransaction( AqlTransaction(
std::shared_ptr<transaction::Context> const& transactionContext, std::shared_ptr<transaction::Context> const& transactionContext,
std::map<std::string, aql::Collection*> const* collections, std::map<std::string, aql::Collection*> const* collections,
transaction::Options const& options,
bool isMainTransaction) bool isMainTransaction)
: transaction::Methods(transactionContext), : transaction::Methods(transactionContext, options),
_collections(*collections) { _collections(*collections),
_options(options) {
if (!isMainTransaction) { if (!isMainTransaction) {
addHint(transaction::Hints::Hint::LOCK_NEVER); addHint(transaction::Hints::Hint::LOCK_NEVER);
} else { } else {
@ -91,7 +94,7 @@ class AqlTransaction final : public transaction::Methods {
/// AQL query running on the coordinator /// AQL query running on the coordinator
transaction::Methods* clone() const override { transaction::Methods* clone() const override {
return new AqlTransaction(transaction::StandaloneContext::Create(vocbase()), 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 /// @brief lockCollections, this is needed in a corner case in AQL: we need
@ -106,6 +109,7 @@ class AqlTransaction final : public transaction::Methods {
/// operation /// operation
private: private:
std::map<std::string, aql::Collection*> _collections; std::map<std::string, aql::Collection*> _collections;
transaction::Options _options;
}; };
} }

View File

@ -342,6 +342,7 @@ void Query::prepare(QueryRegistry* registry, uint64_t queryHash) {
// create the transaction object, but do not start it yet // create the transaction object, but do not start it yet
AqlTransaction* trx = new AqlTransaction( AqlTransaction* trx = new AqlTransaction(
createTransactionContext(), _collections.collections(), createTransactionContext(), _collections.collections(),
_queryOptions.transactionOptions,
_part == PART_MAIN); _part == PART_MAIN);
_trx = trx; _trx = trx;
@ -430,7 +431,7 @@ ExecutionPlan* Query::prepare() {
// create the transaction object, but do not start it yet // create the transaction object, but do not start it yet
AqlTransaction* trx = new AqlTransaction( AqlTransaction* trx = new AqlTransaction(
createTransactionContext(), _collections.collections(), createTransactionContext(), _collections.collections(),
_part == PART_MAIN); _queryOptions.transactionOptions, _part == PART_MAIN);
_trx = trx; _trx = trx;
// As soon as we start du instantiate the plan we have to clean it // 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 // create the transaction object, but do not start it yet
_trx = new AqlTransaction(createTransactionContext(), _trx = new AqlTransaction(createTransactionContext(),
_collections.collections(), true); _collections.collections(),
_queryOptions.transactionOptions, true);
// we have an AST // we have an AST
Result res = _trx->begin(); Result res = _trx->begin();

View File

@ -172,6 +172,9 @@ void QueryOptions::fromVelocyPack(VPackSlice const& slice) {
it.next(); it.next();
} }
} }
// also handle transaction options
transactionOptions.fromVelocyPack(slice);
} }
void QueryOptions::toVelocyPack(VPackBuilder& builder, bool disableOptimizerRules) const { void QueryOptions::toVelocyPack(VPackBuilder& builder, bool disableOptimizerRules) const {
@ -217,5 +220,8 @@ void QueryOptions::toVelocyPack(VPackBuilder& builder, bool disableOptimizerRule
builder.close(); // shardIds builder.close(); // shardIds
} }
// also handle transaction options
transactionOptions.toVelocyPack(builder);
builder.close(); builder.close();
} }

View File

@ -25,6 +25,7 @@
#define ARANGOD_AQL_QUERY_OPTIONS_H 1 #define ARANGOD_AQL_QUERY_OPTIONS_H 1
#include "Basics/Common.h" #include "Basics/Common.h"
#include "Transaction/Options.h"
namespace arangodb { namespace arangodb {
namespace velocypack { namespace velocypack {
@ -58,6 +59,8 @@ struct QueryOptions {
bool inspectSimplePlans; bool inspectSimplePlans;
std::vector<std::string> optimizerRules; std::vector<std::string> optimizerRules;
std::unordered_set<std::string> shardIds; std::unordered_set<std::string> shardIds;
transaction::Options transactionOptions;
}; };
} }

View File

@ -101,7 +101,7 @@ BaseEngine::BaseEngine(TRI_vocbase_t* vocbase, VPackSlice info)
_trx = new arangodb::aql::AqlTransaction( _trx = new arangodb::aql::AqlTransaction(
arangodb::transaction::StandaloneContext::Create(vocbase), 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 // 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 // created transaction is considered a "MAIN" part and will not switch
// off collection locking completely! // off collection locking completely!

View File

@ -23,6 +23,10 @@
#include "Options.h" #include "Options.h"
#include <velocypack/Builder.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
using namespace arangodb::transaction; using namespace arangodb::transaction;
uint64_t Options::defaultMaxTransactionSize = UINT64_MAX; uint64_t Options::defaultMaxTransactionSize = UINT64_MAX;
@ -42,3 +46,44 @@ void Options::setLimits(uint64_t maxTransactionSize, uint64_t intermediateCommit
defaultIntermediateCommitSize = intermediateCommitSize; defaultIntermediateCommitSize = intermediateCommitSize;
defaultIntermediateCommitCount = intermediateCommitCount; 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));
}

View File

@ -27,12 +27,25 @@
#include "Basics/Common.h" #include "Basics/Common.h"
namespace arangodb { namespace arangodb {
namespace velocypack {
class Builder;
class Slice;
}
namespace transaction { namespace transaction {
struct Options { struct Options {
Options(); Options();
/// @brief adjust the global default values for transactions
static void setLimits(uint64_t maxTransactionSize, uint64_t intermediateCommitSize, uint64_t intermediateCommitCount); 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 constexpr double defaultLockTimeout = 900.0;
static uint64_t defaultMaxTransactionSize; static uint64_t defaultMaxTransactionSize;
static uint64_t defaultIntermediateCommitSize; static uint64_t defaultIntermediateCommitSize;