1
0
Fork 0
arangodb/arangod/MMFiles/MMFilesTransactionState.h

97 lines
2.9 KiB
C++

////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Jan Steemann
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGOD_MMFILES_TRANSACTION_STATE_H
#define ARANGOD_MMFILES_TRANSACTION_STATE_H 1
#include "Basics/Common.h"
#include "Basics/SmallVector.h"
#include "StorageEngine/TransactionState.h"
#include "Utils/Transaction.h"
#include "Utils/TransactionHints.h"
#include "VocBase/AccessMode.h"
#include "VocBase/voc-types.h"
struct TRI_vocbase_t;
namespace rocksdb {
class Transaction;
}
namespace arangodb {
class LogicalCollection;
struct MMFilesDocumentOperation;
class MMFilesWalMarker;
class Transaction;
class TransactionCollection;
/// @brief transaction type
class MMFilesTransactionState final : public TransactionState {
public:
explicit MMFilesTransactionState(TRI_vocbase_t* vocbase);
~MMFilesTransactionState();
/// @brief begin a transaction
int beginTransaction(TransactionHints hints, int nestingLevel) override;
/// @brief commit a transaction
int commitTransaction(Transaction* trx, int nestingLevel) override;
/// @brief abort a transaction
int abortTransaction(Transaction* trx, int nestingLevel) override;
bool hasFailedOperations() const override {
return (_hasOperations && _status == Transaction::Status::ABORTED);
}
/// @brief add a WAL operation for a transaction collection
int addOperation(TRI_voc_rid_t, MMFilesDocumentOperation&, MMFilesWalMarker const* marker, bool&);
private:
/// @brief whether or not a marker needs to be written
bool needWriteMarker(bool isBeginMarker) const {
if (isBeginMarker) {
return (!isReadOnlyTransaction() && !isSingleOperation());
}
return (_nestingLevel == 0 && _beginWritten &&
!isReadOnlyTransaction() && !isSingleOperation());
}
/// @brief write WAL begin marker
int writeBeginMarker();
/// @brief write WAL abort marker
int writeAbortMarker();
/// @brief write WAL commit marker
int writeCommitMarker();
/// @brief free all operations for a transaction
void freeOperations(arangodb::Transaction* activeTrx);
};
}
#endif