From 40b7f372f90c6b01ff27c79aada64c72ef3cde6e Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 2 Jul 2013 17:20:51 +0200 Subject: [PATCH] handle OOM --- arangod/VocBase/index.c | 27 +++++++++++++----- arangod/VocBase/primary-collection.c | 41 ++++++++++++++++++---------- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/arangod/VocBase/index.c b/arangod/VocBase/index.c index afb6163941..d70838bc41 100644 --- a/arangod/VocBase/index.c +++ b/arangod/VocBase/index.c @@ -774,9 +774,29 @@ TRI_index_t* TRI_CreateEdgeIndex (struct TRI_primary_collection_s* primary) { TRI_edge_index_t* edgeIndex; TRI_index_t* idx; char* id; + int res; // create index edgeIndex = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_edge_index_t), false); + + if (edgeIndex == NULL) { + return NULL; + } + + res = TRI_InitMultiPointer(&edgeIndex->_edges, + TRI_UNKNOWN_MEM_ZONE, + HashElementEdge, + HashElementEdge, + IsEqualKeyEdge, + IsEqualElementEdge); + + if (res != TRI_ERROR_NO_ERROR) { + TRI_Free(TRI_CORE_MEM_ZONE, edgeIndex); + + return NULL; + } + + idx = &edgeIndex->base; TRI_InitVectorString(&idx->_fields, TRI_CORE_MEM_ZONE); @@ -790,13 +810,6 @@ TRI_index_t* TRI_CreateEdgeIndex (struct TRI_primary_collection_s* primary) { idx->insert = InsertEdge; idx->remove = RemoveEdge; - TRI_InitMultiPointer(&edgeIndex->_edges, - TRI_UNKNOWN_MEM_ZONE, - HashElementEdge, - HashElementEdge, - IsEqualKeyEdge, - IsEqualElementEdge); - return idx; } diff --git a/arangod/VocBase/primary-collection.c b/arangod/VocBase/primary-collection.c index 771589c13c..fd4e85347a 100644 --- a/arangod/VocBase/primary-collection.c +++ b/arangod/VocBase/primary-collection.c @@ -559,6 +559,8 @@ static TRI_voc_size_t Count (TRI_primary_collection_t* primary) { int TRI_InitPrimaryCollection (TRI_primary_collection_t* primary, TRI_shaper_t* shaper) { + int res; + primary->_shaper = shaper; primary->_capConstraint = NULL; primary->_keyGenerator = NULL; @@ -568,22 +570,32 @@ int TRI_InitPrimaryCollection (TRI_primary_collection_t* primary, primary->size = Count; + res = TRI_InitAssociativePointer(&primary->_datafileInfo, + TRI_UNKNOWN_MEM_ZONE, + HashKeyDatafile, + HashElementDatafile, + IsEqualKeyElementDatafile, + NULL); + + if (res != TRI_ERROR_NO_ERROR) { + return res; + } + + res = TRI_InitAssociativePointer(&primary->_primaryIndex, + TRI_UNKNOWN_MEM_ZONE, + HashKeyHeader, + HashElementDocument, + IsEqualKeyDocument, + NULL); + + if (res != TRI_ERROR_NO_ERROR) { + TRI_DestroyAssociativePointer(&primary->_datafileInfo); + + return res; + } + TRI_InitBarrierList(&primary->_barrierList, primary); - TRI_InitAssociativePointer(&primary->_datafileInfo, - TRI_UNKNOWN_MEM_ZONE, - HashKeyDatafile, - HashElementDatafile, - IsEqualKeyElementDatafile, - NULL); - - TRI_InitAssociativePointer(&primary->_primaryIndex, - TRI_UNKNOWN_MEM_ZONE, - HashKeyHeader, - HashElementDocument, - IsEqualKeyDocument, - NULL); - TRI_InitReadWriteLock(&primary->_lock); TRI_InitReadWriteLock(&primary->_compactionLock); @@ -603,6 +615,7 @@ void TRI_DestroyPrimaryCollection (TRI_primary_collection_t* primary) { TRI_DestroyReadWriteLock(&primary->_compactionLock); TRI_DestroyReadWriteLock(&primary->_lock); + TRI_DestroyAssociativePointer(&primary->_primaryIndex); if (primary->_shaper != NULL) {