1
0
Fork 0

Merge branch 'spdvpk' of github.com:arangodb/arangodb into spdvpk

This commit is contained in:
Michael Hackstein 2016-02-25 14:38:43 +01:00
commit 45a75bf4c6
12 changed files with 66 additions and 32 deletions

View File

@ -309,7 +309,7 @@ bool RestDocumentHandler::readSingleDocument(bool generateBody) {
} else {
// copy default options
VPackOptions options = VPackOptions::Defaults;
options.customTypeHandler = result.customTypeHandler;
options.customTypeHandler = result.customTypeHandler.get();
generateDocument(result.slice(), generateBody, &options);
}
return true;

View File

@ -57,7 +57,7 @@ struct OperationCursor : public OperationResult {
}
OperationCursor(std::shared_ptr<VPackBuffer<uint8_t>> buffer,
VPackCustomTypeHandler* handler,
std::shared_ptr<VPackCustomTypeHandler> handler,
std::string const& message,
int code,
bool wasSynchronous)
@ -67,7 +67,7 @@ struct OperationCursor : public OperationResult {
_batchSize(1000) {
}
OperationCursor(VPackCustomTypeHandler* handler, IndexIterator* iterator,
OperationCursor(std::shared_ptr<VPackCustomTypeHandler> handler, IndexIterator* iterator,
uint64_t limit, uint64_t batchSize)
: OperationResult(std::make_shared<VPackBuffer<uint8_t>>(), handler, "",
TRI_ERROR_NO_ERROR, false),

View File

@ -36,20 +36,20 @@ namespace arangodb {
struct OperationResult {
explicit OperationResult(int code)
: customTypeHandler(nullptr), code(code), wasSynchronous(false) {
: customTypeHandler(), code(code), wasSynchronous(false) {
if (code != TRI_ERROR_NO_ERROR) {
errorMessage = TRI_errno_string(code);
}
}
OperationResult(int code, std::string const& message)
: customTypeHandler(nullptr), errorMessage(message), code(code),
: customTypeHandler(), errorMessage(message), code(code),
wasSynchronous(false) {
TRI_ASSERT(code != TRI_ERROR_NO_ERROR);
}
OperationResult(std::shared_ptr<VPackBuffer<uint8_t>> buffer,
VPackCustomTypeHandler* handler,
std::shared_ptr<VPackCustomTypeHandler> handler,
std::string const& message,
int code,
bool wasSynchronous)
@ -58,7 +58,6 @@ struct OperationResult {
}
virtual ~OperationResult() {
// TODO: handle destruction of customTypeHandler
}
bool successful() const {
@ -75,7 +74,7 @@ struct OperationResult {
}
std::shared_ptr<VPackBuffer<uint8_t>> buffer;
VPackCustomTypeHandler* customTypeHandler;
std::shared_ptr<VPackCustomTypeHandler> customTypeHandler;
std::string errorMessage;
int code;
bool wasSynchronous;

View File

@ -77,7 +77,7 @@ int StandaloneTransactionContext::registerTransaction(TRI_transaction_t* trx) {
////////////////////////////////////////////////////////////////////////////////
void StandaloneTransactionContext::unregisterTransaction() {
// nothing to do. cleanup will be done by the parent's destructor
// nothing special to do. cleanup will be done by the parent's destructor
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -69,7 +69,7 @@ class StandaloneTransactionContext final : public TransactionContext {
int registerTransaction(struct TRI_transaction_s*) override;
//////////////////////////////////////////////////////////////////////////////
/// @brief unregister the transaction, does nothing
/// @brief unregister the transaction
//////////////////////////////////////////////////////////////////////////////
void unregisterTransaction() override;

View File

@ -1097,10 +1097,14 @@ class Transaction {
TRI_ASSERT(!isEmbeddedTransaction());
if (_trx != nullptr) {
this->_transactionContext->unregisterTransaction();
TRI_FreeTransaction(_trx);
auto id = _trx->_id;
bool hasFailedOperations = TRI_FreeTransaction(_trx);
_trx = nullptr;
// store result
this->_transactionContext->storeTransactionResult(id, hasFailedOperations);
this->_transactionContext->unregisterTransaction();
}
}

View File

@ -25,6 +25,7 @@
#include "Storage/Marker.h"
#include "VocBase/Ditch.h"
#include "VocBase/document-collection.h"
#include "Wal/LogfileManager.h"
#include <velocypack/Dumper.h>
#include <velocypack/Options.h>
@ -107,7 +108,8 @@ struct CustomTypeHandler : public VPackCustomTypeHandler {
TransactionContext::TransactionContext(TRI_vocbase_t* vocbase)
: _vocbase(vocbase),
_resolver(nullptr),
_customTypeHandler(nullptr),
_customTypeHandler(),
_transaction{ 0, false },
_ownsResolver(false) {}
//////////////////////////////////////////////////////////////////////////////
@ -115,6 +117,11 @@ TransactionContext::TransactionContext(TRI_vocbase_t* vocbase)
//////////////////////////////////////////////////////////////////////////////
TransactionContext::~TransactionContext() {
// unregister the transaction from the logfile manager
if (_transaction.id > 0) {
arangodb::wal::LogfileManager::instance()->unregisterTransaction(_transaction.id, _transaction.hasFailedOperations);
}
for (auto& it : _ditches) {
// we're done with this ditch
auto& ditch = it.second;
@ -122,8 +129,6 @@ TransactionContext::~TransactionContext() {
// If some external entity is still using the ditch, it is kept!
}
delete _customTypeHandler;
if (_ownsResolver) {
delete _resolver;
_resolver = nullptr;
@ -134,9 +139,9 @@ TransactionContext::~TransactionContext() {
/// @brief order a document ditch for the collection
//////////////////////////////////////////////////////////////////////////////
VPackCustomTypeHandler* TransactionContext::orderCustomTypeHandler() {
std::shared_ptr<VPackCustomTypeHandler> TransactionContext::orderCustomTypeHandler() {
if (_customTypeHandler == nullptr) {
_customTypeHandler = new CustomTypeHandler(_vocbase, getResolver());
_customTypeHandler.reset(new CustomTypeHandler(_vocbase, getResolver()));
}
TRI_ASSERT(_customTypeHandler != nullptr);
@ -200,3 +205,15 @@ void TransactionContext::createResolver() {
_ownsResolver = true;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief unregister the transaction
/// this will save the transaction's id and status locally
//////////////////////////////////////////////////////////////////////////////
void TransactionContext::storeTransactionResult(TRI_voc_tid_t id, bool hasFailedOperations) {
TRI_ASSERT(_transaction.id == 0);
_transaction.id = id;
_transaction.hasFailedOperations = hasFailedOperations;
}

View File

@ -74,7 +74,7 @@ class TransactionContext {
/// @brief orders a custom type handler
//////////////////////////////////////////////////////////////////////////////
velocypack::CustomTypeHandler* orderCustomTypeHandler();
std::shared_ptr<velocypack::CustomTypeHandler> orderCustomTypeHandler();
//////////////////////////////////////////////////////////////////////////////
/// @brief order a document ditch for the collection
@ -90,6 +90,13 @@ class TransactionContext {
DocumentDitch* ditch(TRI_voc_cid_t) const;
//////////////////////////////////////////////////////////////////////////////
/// @brief unregister the transaction
/// this will save the transaction's id and status locally
//////////////////////////////////////////////////////////////////////////////
void storeTransactionResult(TRI_voc_tid_t, bool);
//////////////////////////////////////////////////////////////////////////////
/// @brief return the resolver
//////////////////////////////////////////////////////////////////////////////
@ -113,15 +120,15 @@ class TransactionContext {
//////////////////////////////////////////////////////////////////////////////
virtual int registerTransaction(struct TRI_transaction_s*) = 0;
//////////////////////////////////////////////////////////////////////////////
/// @brief unregister the transaction from the context
/// @brief unregister the transaction
//////////////////////////////////////////////////////////////////////////////
virtual void unregisterTransaction() = 0;
protected:
//////////////////////////////////////////////////////////////////////////////
/// @brief create a resolver
//////////////////////////////////////////////////////////////////////////////
@ -134,10 +141,15 @@ class TransactionContext {
CollectionNameResolver const* _resolver;
velocypack::CustomTypeHandler* _customTypeHandler;
std::shared_ptr<velocypack::CustomTypeHandler> _customTypeHandler;
std::unordered_map<TRI_voc_cid_t, DocumentDitch*> _ditches;
struct {
TRI_voc_tid_t id;
bool hasFailedOperations;
} _transaction;
bool _ownsResolver;
};
}

View File

@ -588,7 +588,7 @@ static void DocumentVocbaseVPack(
}
VPackOptions resultOptions = VPackOptions::Defaults;
resultOptions.customTypeHandler = opResult.customTypeHandler;
resultOptions.customTypeHandler = opResult.customTypeHandler.get();
v8::Handle<v8::Value> result = TRI_VPackToV8(isolate, opResult.slice(), &resultOptions);

View File

@ -892,13 +892,14 @@ static void JS_AllQuery(v8::FunctionCallbackInfo<v8::Value> const& args) {
VPackSlice count = countResult.slice();
TRI_ASSERT(count.isNumber());
VPackOptions resultOptions = VPackOptions::Defaults;
resultOptions.customTypeHandler = opCursor.customTypeHandler;
if (!opCursor.hasMore()) {
// OUT OF MEMORY. initial hasMore should return true even if index is empty
TRI_V8_THROW_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
}
// copy default options
VPackOptions resultOptions = VPackOptions::Defaults;
resultOptions.customTypeHandler = opCursor.customTypeHandler.get();
opCursor.getMore();
// We only need this one call, limit == batchsize
@ -971,8 +972,9 @@ static void JS_AnyQuery(v8::FunctionCallbackInfo<v8::Value> const& args) {
TRI_V8_RETURN_NULL();
}
// copy default options
VPackOptions resultOptions = VPackOptions::Defaults;
resultOptions.customTypeHandler = cursor.customTypeHandler;
resultOptions.customTypeHandler = cursor.customTypeHandler.get();
TRI_V8_RETURN(TRI_VPackToV8(isolate, doc.at(0), &resultOptions));
TRI_V8_TRY_CATCH_END
}

View File

@ -769,7 +769,7 @@ TRI_transaction_t* TRI_CreateTransaction(TRI_vocbase_t* vocbase,
/// @brief free a transaction container
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeTransaction(TRI_transaction_t* trx) {
bool TRI_FreeTransaction(TRI_transaction_t* trx) {
TRI_ASSERT(trx != nullptr);
if (trx->_status == TRI_TRANSACTION_RUNNING) {
@ -779,8 +779,6 @@ void TRI_FreeTransaction(TRI_transaction_t* trx) {
// release the marker protector
bool const hasFailedOperations =
(trx->_hasOperations && trx->_status == TRI_TRANSACTION_ABORTED);
arangodb::wal::LogfileManager::instance()->unregisterTransaction(
trx->_id, hasFailedOperations);
ReleaseCollections(trx, 0);
@ -795,6 +793,8 @@ void TRI_FreeTransaction(TRI_transaction_t* trx) {
TRI_DestroyVectorPointer(&trx->_collections);
TRI_Free(TRI_UNKNOWN_MEM_ZONE, trx);
return hasFailedOperations;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -150,7 +150,7 @@ TRI_transaction_t* TRI_CreateTransaction(TRI_vocbase_t*, TRI_voc_tid_t, double,
/// @brief free a transaction
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeTransaction(TRI_transaction_t*);
bool TRI_FreeTransaction(TRI_transaction_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief return the type of the transaction as a string