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