mirror of https://gitee.com/bigwinds/arangodb
refactoring
This commit is contained in:
parent
a4356f0499
commit
3418cc193b
|
@ -55,8 +55,7 @@ class ReplicationTransaction : public Transaction {
|
|||
inline TransactionCollection* trxCollection(TRI_voc_cid_t cid) {
|
||||
TRI_ASSERT(cid > 0);
|
||||
|
||||
TransactionCollection* trxCollection =
|
||||
TRI_GetCollectionTransaction(this->_trx, cid, AccessMode::Type::WRITE);
|
||||
TransactionCollection* trxCollection = this->_trx->collection(cid, AccessMode::Type::WRITE);
|
||||
|
||||
if (trxCollection == nullptr) {
|
||||
int res = TRI_AddCollectionTransaction(
|
||||
|
@ -70,8 +69,7 @@ class ReplicationTransaction : public Transaction {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
trxCollection =
|
||||
TRI_GetCollectionTransaction(this->_trx, cid, AccessMode::Type::WRITE);
|
||||
trxCollection = this->_trx->collection(cid, AccessMode::Type::WRITE);
|
||||
}
|
||||
|
||||
return trxCollection;
|
||||
|
|
|
@ -79,8 +79,7 @@ TransactionCollection* SingleCollectionTransaction::trxCollection() {
|
|||
TRI_ASSERT(_cid > 0);
|
||||
|
||||
if (_trxCollection == nullptr) {
|
||||
_trxCollection =
|
||||
TRI_GetCollectionTransaction(_trx, _cid, _accessType);
|
||||
_trxCollection = _trx->collection(_cid, _accessType);
|
||||
|
||||
if (_trxCollection != nullptr) {
|
||||
_documentCollection =
|
||||
|
|
|
@ -640,7 +640,7 @@ TransactionCollection* Transaction::trxCollection(TRI_voc_cid_t cid) const {
|
|||
TRI_ASSERT(_trx != nullptr);
|
||||
TRI_ASSERT(getStatus() == Transaction::Status::RUNNING);
|
||||
|
||||
return TRI_GetCollectionTransaction(_trx, cid, AccessMode::Type::READ);
|
||||
return _trx->collection(cid, AccessMode::Type::READ);
|
||||
}
|
||||
|
||||
/// @brief order a ditch for a collection
|
||||
|
@ -653,7 +653,7 @@ DocumentDitch* Transaction::orderDitch(TRI_voc_cid_t cid) {
|
|||
return _ditchCache.ditch;
|
||||
}
|
||||
|
||||
TransactionCollection* trxCollection = TRI_GetCollectionTransaction(_trx, cid, AccessMode::Type::READ);
|
||||
TransactionCollection* trxCollection = _trx->collection(cid, AccessMode::Type::READ);
|
||||
|
||||
if (trxCollection == nullptr) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "unable to determine transaction collection");
|
||||
|
@ -3094,7 +3094,8 @@ arangodb::LogicalCollection* Transaction::documentCollection(
|
|||
TRI_ASSERT(_trx != nullptr);
|
||||
TRI_ASSERT(getStatus() == Transaction::Status::RUNNING);
|
||||
|
||||
auto trxCollection = TRI_GetCollectionTransaction(_trx, cid, AccessMode::Type::READ);
|
||||
auto trxCollection = _trx->collection(cid, AccessMode::Type::READ);
|
||||
|
||||
if (trxCollection == nullptr) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "could not find collection");
|
||||
}
|
||||
|
@ -3169,8 +3170,8 @@ bool Transaction::isLocked(LogicalCollection* document,
|
|||
return false;
|
||||
}
|
||||
|
||||
TransactionCollection* trxCollection =
|
||||
TRI_GetCollectionTransaction(_trx, document->cid(), type);
|
||||
TransactionCollection* trxCollection = _trx->collection(document->cid(), type);
|
||||
|
||||
TRI_ASSERT(trxCollection != nullptr);
|
||||
return TRI_IsLockedCollectionTransaction(trxCollection, type, _nestingLevel);
|
||||
}
|
||||
|
|
|
@ -631,16 +631,13 @@ static void UpdateTransactionStatus(TransactionState* const trx,
|
|||
trx->_status = status;
|
||||
}
|
||||
|
||||
|
||||
/// @brief return the collection from a transaction
|
||||
TransactionCollection* arangodb::TRI_GetCollectionTransaction(
|
||||
TransactionState const* trx, TRI_voc_cid_t cid,
|
||||
AccessMode::Type accessType) {
|
||||
TRI_ASSERT(trx->_status == Transaction::Status::CREATED ||
|
||||
trx->_status == Transaction::Status::RUNNING);
|
||||
TransactionCollection* TransactionState::collection(TRI_voc_cid_t cid, AccessMode::Type accessType) {
|
||||
TRI_ASSERT(_status == Transaction::Status::CREATED ||
|
||||
_status == Transaction::Status::RUNNING);
|
||||
|
||||
TransactionCollection* trxCollection =
|
||||
FindCollection(trx, cid, nullptr);
|
||||
FindCollection(this, cid, nullptr);
|
||||
|
||||
if (trxCollection == nullptr) {
|
||||
// not found
|
||||
|
@ -648,8 +645,8 @@ TransactionCollection* arangodb::TRI_GetCollectionTransaction(
|
|||
}
|
||||
|
||||
if (trxCollection->_collection == nullptr) {
|
||||
if (!HasHint(trx, TransactionHints::Hint::LOCK_NEVER) ||
|
||||
!HasHint(trx, TransactionHints::Hint::NO_USAGE_LOCK)) {
|
||||
if (!HasHint(this, TransactionHints::Hint::LOCK_NEVER) ||
|
||||
!HasHint(this, TransactionHints::Hint::NO_USAGE_LOCK)) {
|
||||
// not opened. probably a mistake made by the caller
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -942,8 +939,8 @@ int arangodb::TRI_AddOperationTransaction(TransactionState* trx,
|
|||
collection->increaseUncollectedLogfileEntries(1);
|
||||
} else {
|
||||
// operation is buffered and might be rolled back
|
||||
TransactionCollection* trxCollection = TRI_GetCollectionTransaction(
|
||||
trx, collection->cid(), AccessMode::Type::WRITE);
|
||||
TransactionCollection* trxCollection = trx->collection(collection->cid(), AccessMode::Type::WRITE);
|
||||
|
||||
if (trxCollection->_operations == nullptr) {
|
||||
trxCollection->_operations = new std::vector<MMFilesDocumentOperation*>;
|
||||
trxCollection->_operations->reserve(16);
|
||||
|
|
|
@ -46,21 +46,32 @@ struct TransactionCollection;
|
|||
|
||||
/// @brief transaction type
|
||||
struct TransactionState {
|
||||
TransactionState() = delete;
|
||||
TransactionState(TransactionState const&) = delete;
|
||||
TransactionState& operator=(TransactionState const&) = delete;
|
||||
|
||||
TransactionState(TRI_vocbase_t* vocbase, double timeout, bool waitForSync);
|
||||
~TransactionState();
|
||||
|
||||
public:
|
||||
|
||||
/// @brief return the collection from a transaction
|
||||
TransactionCollection* collection(TRI_voc_cid_t cid, AccessMode::Type accessType);
|
||||
|
||||
bool hasFailedOperations() const {
|
||||
return (_hasOperations && _status == Transaction::Status::ABORTED);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
TRI_vocbase_t* _vocbase; // vocbase
|
||||
TRI_voc_tid_t _id; // local trx id
|
||||
AccessMode::Type _type; // access type (read|write)
|
||||
Transaction::Status _status; // current status
|
||||
AccessMode::Type _type; // access type (read|write)
|
||||
Transaction::Status _status; // current status
|
||||
SmallVector<TransactionCollection*>::allocator_type::arena_type _arena; // memory for collections
|
||||
SmallVector<TransactionCollection*> _collections; // list of participating collections
|
||||
rocksdb::Transaction* _rocksTransaction;
|
||||
TransactionHints _hints; // hints;
|
||||
TransactionHints _hints; // hints;
|
||||
int _nestingLevel;
|
||||
bool _allowImplicit;
|
||||
bool _hasOperations;
|
||||
|
@ -79,10 +90,6 @@ static inline TRI_voc_tid_t TRI_MarkerIdTransaction(
|
|||
return trx->_id;
|
||||
}
|
||||
|
||||
/// @brief return the collection from a transaction
|
||||
TransactionCollection* TRI_GetCollectionTransaction(
|
||||
TransactionState const*, TRI_voc_cid_t, AccessMode::Type);
|
||||
|
||||
/// @brief add a collection to a transaction
|
||||
int TRI_AddCollectionTransaction(TransactionState*, TRI_voc_cid_t,
|
||||
AccessMode::Type, int, bool, bool);
|
||||
|
|
Loading…
Reference in New Issue