From ebc61295e734d56b93f28005daa7c4c200107a87 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Mon, 24 Jun 2013 14:25:21 +0200 Subject: [PATCH] more assertions --- arangod/VocBase/document-collection.c | 12 ++++++------ arangod/VocBase/headers.c | 17 ++++++++++++----- arangod/VocBase/headers.h | 2 +- arangod/VocBase/transaction.c | 11 ++++++++--- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/arangod/VocBase/document-collection.c b/arangod/VocBase/document-collection.c index 4318e871a8..6997de5d2d 100644 --- a/arangod/VocBase/document-collection.c +++ b/arangod/VocBase/document-collection.c @@ -765,7 +765,7 @@ static int RollbackInsert (TRI_document_collection_t* document, DeleteSecondaryIndexes(document, newHeader, true); // release the header. nobody else should point to it now - document->_headers->release(document->_headers, newHeader); + document->_headers->release(document->_headers, newHeader, true); res = TRI_ERROR_NO_ERROR; @@ -901,7 +901,7 @@ static int InsertDocument (TRI_transaction_collection_t* trxCollection, if (res != TRI_ERROR_NO_ERROR) { // insert has failed - document->_headers->release(document->_headers, header); + document->_headers->release(document->_headers, header, true); return res; } @@ -911,7 +911,7 @@ static int InsertDocument (TRI_transaction_collection_t* trxCollection, if (res != TRI_ERROR_NO_ERROR) { // insertion into secondary indexes failed DeletePrimaryIndex(document, header, true); - document->_headers->release(document->_headers, header); + document->_headers->release(document->_headers, header, true); return res; } @@ -1099,7 +1099,7 @@ static int RemoveDocument (TRI_transaction_collection_t* trxCollection, if (res == TRI_ERROR_NO_ERROR) { if (directOperation) { // release the header pointer - document->_headers->release(document->_headers, header); + document->_headers->release(document->_headers, header, true); } return TRI_ERROR_NO_ERROR; @@ -1965,7 +1965,7 @@ static int OpenIteratorApplyInsert (open_iterator_state_t* state, if (res != TRI_ERROR_NO_ERROR) { // insertion failed LOG_ERROR("inserting document into indexes failed"); - document->_headers->release(document->_headers, header); + document->_headers->release(document->_headers, header, true); return res; } @@ -2116,7 +2116,7 @@ static int OpenIteratorApplyRemove (open_iterator_state_t* state, DeletePrimaryIndex(document, found, false); // free the header - document->_headers->release(document->_headers, CONST_CAST(found)); + document->_headers->release(document->_headers, CONST_CAST(found), true); } return TRI_ERROR_NO_ERROR; diff --git a/arangod/VocBase/headers.c b/arangod/VocBase/headers.c index 68894f4bc8..9c2abf99e9 100644 --- a/arangod/VocBase/headers.c +++ b/arangod/VocBase/headers.c @@ -96,7 +96,7 @@ static size_t GetBlockSize (const size_t blockNumber) { } //////////////////////////////////////////////////////////////////////////////// -/// @brief clears an header +/// @brief clears a header //////////////////////////////////////////////////////////////////////////////// static void ClearHeader (TRI_headers_t* h, @@ -172,6 +172,8 @@ static void MoveBackHeader (TRI_headers_t* h, // we must adjust the size of the collection headers->_totalSize += (int64_t) (((TRI_df_marker_t*) header->_data)->_size); headers->_totalSize -= (int64_t) (((TRI_df_marker_t*) old->_data)->_size); + + TRI_ASSERT_MAINTAINER(headers->_totalSize > 0); } //////////////////////////////////////////////////////////////////////////////// @@ -424,7 +426,7 @@ static TRI_doc_mptr_t* RequestHeader (TRI_headers_t* h, headers->_nrAllocated++; headers->_nrLinked++; headers->_totalSize += (int64_t) size; - + return result; } @@ -433,14 +435,17 @@ static TRI_doc_mptr_t* RequestHeader (TRI_headers_t* h, //////////////////////////////////////////////////////////////////////////////// static void ReleaseHeader (TRI_headers_t* h, - TRI_doc_mptr_t* header) { + TRI_doc_mptr_t* header, + bool unlink) { simple_headers_t* headers = (simple_headers_t*) h; if (header == NULL) { return; } - UnlinkHeader(h, header); + if (unlink) { + UnlinkHeader(h, header); + } ClearHeader(h, header); header->_data = headers->_freelist; @@ -504,6 +509,8 @@ static void DumpHeaders (TRI_headers_t const* h) { printf("number of allocated headers: %lu\n", (unsigned long) headers->_nrAllocated); printf("number of linked headers: %lu\n", (unsigned long) headers->_nrLinked); + printf("total size: %lld\n", (long long) headers->_totalSize); + printf("begin ptr: %p\n", headers->_begin); printf("end ptr: %p\n", headers->_end); @@ -575,7 +582,7 @@ TRI_headers_t* TRI_CreateSimpleHeaders () { headers->base.dump = DumpHeaders; #endif - TRI_InitVectorPointer(&headers->_blocks, TRI_UNKNOWN_MEM_ZONE); + TRI_InitVectorPointer2(&headers->_blocks, TRI_UNKNOWN_MEM_ZONE, 8); return &headers->base; } diff --git a/arangod/VocBase/headers.h b/arangod/VocBase/headers.h index 1c24318297..1caca9fae5 100644 --- a/arangod/VocBase/headers.h +++ b/arangod/VocBase/headers.h @@ -58,7 +58,7 @@ typedef struct TRI_headers_s { struct TRI_doc_mptr_s* (*request) (struct TRI_headers_s*, size_t); // release/free an existing header, putting it back onto the freelist - void (*release) (struct TRI_headers_s*, struct TRI_doc_mptr_s*); + void (*release) (struct TRI_headers_s*, struct TRI_doc_mptr_s*, bool unlink); // move an existing header to the end of the linked list void (*moveBack) (struct TRI_headers_s*, struct TRI_doc_mptr_s*, struct TRI_doc_mptr_s*); diff --git a/arangod/VocBase/transaction.c b/arangod/VocBase/transaction.c index b3d8184f10..a61ace4964 100644 --- a/arangod/VocBase/transaction.c +++ b/arangod/VocBase/transaction.c @@ -977,7 +977,7 @@ static void FreeCollectionOperations (TRI_transaction_collection_t* trxCollectio if (wasCommitted) { if (trxOperation->_type == TRI_VOC_DOCUMENT_OPERATION_REMOVE) { - document->_headers->release(document->_headers, trxOperation->_oldHeader); + document->_headers->release(document->_headers, trxOperation->_oldHeader, false); } } @@ -1866,7 +1866,6 @@ int TRI_CommitTransaction (TRI_transaction_t* const trx, if (nestingLevel == 0) { if (trx->_hasOperations) { res = WriteOperations(trx); - FreeOperations(trx); } if (res != TRI_ERROR_NO_ERROR) { @@ -1876,6 +1875,10 @@ int TRI_CommitTransaction (TRI_transaction_t* const trx, else { res = UpdateTransactionStatus(trx, TRI_TRANSACTION_COMMITTED); } + + if (trx->_hasOperations) { + FreeOperations(trx); + } } ReleaseCollections(trx, nestingLevel); @@ -1898,10 +1901,12 @@ int TRI_AbortTransaction (TRI_transaction_t* const trx, if (nestingLevel == 0) { if (trx->_hasOperations) { RollbackOperations(trx); - FreeOperations(trx); } res = UpdateTransactionStatus(trx, TRI_TRANSACTION_ABORTED); + if (trx->_hasOperations) { + FreeOperations(trx); + } } else { res = TRI_ERROR_NO_ERROR;