1
0
Fork 0

Merge branch 'master' of github.com:triAGENS/AvocadoDB

This commit is contained in:
Frank Celler 2012-04-04 18:24:19 +02:00
commit c7ce15e179
7 changed files with 203 additions and 39 deletions

View File

@ -217,6 +217,7 @@ static TRI_shape_pid_t FindNameAttributePath (TRI_shaper_t* shaper, char const*
// split path into attribute pieces
count = 0;
aids = TRI_Allocate(len * sizeof(TRI_shape_aid_t));
/* TODO FIXME: memory allocation might fail */
buffer = ptr = TRI_DuplicateString2(name, len);
end = buffer + len + 1;
@ -239,6 +240,7 @@ static TRI_shape_pid_t FindNameAttributePath (TRI_shaper_t* shaper, char const*
// create element
total = sizeof(TRI_shape_path_t) + (len + 1) + (count * sizeof(TRI_shape_aid_t));
result = TRI_Allocate(total);
/* TODO FIXME: memory allocation might fail */
result->_pid = shaper->_nextPid++;
result->_nameLength = len + 1;
@ -331,6 +333,7 @@ static TRI_shape_aid_t FindAttributeNameArrayShaper (TRI_shaper_t* shaper, char
n = strlen(name) + 1;
a2i = TRI_Allocate(sizeof(attribute_2_id_t) + n);
/* TODO FIXME: memory allocation might fail */
a2i->_aid = 1 + s->_attributes._length;
a2i->_size = n;
@ -479,6 +482,7 @@ TRI_shaper_t* TRI_CreateArrayShaper () {
// create the shaper
shaper = TRI_Allocate(sizeof(array_shaper_t));
/* TODO FIXME: memory allocation might fail */
TRI_InitShaper(&shaper->base);
@ -640,6 +644,19 @@ void TRI_InitShaper (TRI_shaper_t* shaper) {
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyShaper (TRI_shaper_t* shaper) {
size_t n = shaper->_attributePathsByName._nrAlloc;
size_t i;
// only free pointers in attributePathsByName
// (attributePathsByPid contains the same pointers!)
for (i = 0; i < n; ++i) {
void* data = shaper->_attributePathsByName._table[i];
if (data) {
TRI_Free(data);
}
}
TRI_DestroyAssociativeSynced(&shaper->_attributePathsByName);
TRI_DestroyAssociativeSynced(&shaper->_attributePathsByPid);
@ -656,6 +673,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// NULL
shape = TRI_Allocate(sizeof(TRI_null_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_null_shape_t));
shape->_size = sizeof(TRI_null_shape_t);
@ -672,6 +690,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// BOOLEAN
shape = TRI_Allocate(sizeof(TRI_boolean_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_boolean_shape_t));
shape->_size = sizeof(TRI_boolean_shape_t);
@ -688,6 +707,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// NUMBER
shape = TRI_Allocate(sizeof(TRI_number_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_number_shape_t));
shape->_size = sizeof(TRI_number_shape_t);
@ -704,6 +724,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// SHORT STRING
shape = TRI_Allocate(sizeof(TRI_short_string_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_short_string_shape_t));
shape->_size = sizeof(TRI_short_string_shape_t);
@ -720,6 +741,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// LONG STRING
shape = TRI_Allocate(sizeof(TRI_long_string_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_long_string_shape_t));
shape->_size = sizeof(TRI_long_string_shape_t);
@ -736,6 +758,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// LIST
shape = TRI_Allocate(sizeof(TRI_list_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_list_shape_t));
shape->_size = sizeof(TRI_list_shape_t);

View File

@ -841,7 +841,8 @@ static void* SkiplistPrevsIterationCallback(TRI_skiplist_iterator_t* iterator, i
void SkiplistIndexDestroy(SkiplistIndex* slIndex) {
if (slIndex == NULL) {
return;
}
}
if (slIndex->unique) {
TRI_FreeSkipList(slIndex->skiplist.uniqueSkiplist);
slIndex->skiplist.uniqueSkiplist = NULL;
@ -1282,9 +1283,21 @@ static void SkiplistIndex_findHelper(SkiplistIndex* skiplistIndex,
relationOperator = (TRI_sl_relation_operator_t*)(slOperator);
logicalOperator = (TRI_sl_logical_operator_t*)(slOperator);
values.fields = relationOperator->_fields;
values.numFields = relationOperator->_numFields;
values.collection = relationOperator->_collection;
switch (slOperator->_type) {
case TRI_SL_EQ_OPERATOR:
case TRI_SL_LE_OPERATOR:
case TRI_SL_LT_OPERATOR:
case TRI_SL_GE_OPERATOR:
case TRI_SL_GT_OPERATOR:
values.fields = relationOperator->_fields;
values.numFields = relationOperator->_numFields;
values.collection = relationOperator->_collection;
default: {
// must not access relationOperator->xxx if the operator is not a relational one
// otherwise we'll get invalid reads and the prog might crash
}
}
switch (slOperator->_type) {

View File

@ -557,6 +557,10 @@ static v8::Handle<v8::Value> EnsureHashSkipListIndex (string const& cmd,
// .............................................................................
TRI_json_t* json = idx->json(idx, collection->_collection);
if (!json) {
return scope.Close(v8::ThrowException(v8::String::New("out of memory")));
}
v8::Handle<v8::Value> index = TRI_ObjectJson(json);
if (index->IsObject()) {
@ -564,6 +568,8 @@ static v8::Handle<v8::Value> EnsureHashSkipListIndex (string const& cmd,
}
ReleaseCollection(collection);
TRI_FreeJson(json);
return scope.Close(index);
}
@ -3611,6 +3617,10 @@ static v8::Handle<v8::Value> JS_EnsureGeoIndexVocbaseCol (v8::Arguments const& a
}
TRI_json_t* json = idx->json(idx, collection->_collection);
if (!json) {
return scope.Close(v8::ThrowException(v8::String::New("out of memory")));
}
v8::Handle<v8::Value> index = TRI_ObjectJson(json);
if (index->IsObject()) {
@ -3618,6 +3628,8 @@ static v8::Handle<v8::Value> JS_EnsureGeoIndexVocbaseCol (v8::Arguments const& a
}
ReleaseCollection(collection);
TRI_FreeJson(json);
return scope.Close(index);
}
@ -3781,6 +3793,9 @@ static v8::Handle<v8::Value> JS_GetIndexesVocbaseCol (v8::Arguments const& argv)
// get a list of indexes
TRI_vector_pointer_t* indexes = TRI_IndexesSimCollection(sim);
if (!indexes) {
return scope.Close(v8::ThrowException(v8::String::New("out of memory")));
}
v8::Handle<v8::Array> result = v8::Array::New();
@ -3788,11 +3803,16 @@ static v8::Handle<v8::Value> JS_GetIndexesVocbaseCol (v8::Arguments const& argv)
for (uint32_t i = 0; i < n; ++i) {
TRI_json_t* idx = (TRI_json_t*) indexes->_buffer[i];
result->Set(i, TRI_ObjectJson(idx));
if (idx) {
result->Set(i, TRI_ObjectJson(idx));
TRI_FreeJson(idx);
}
}
ReleaseCollection(collection);
TRI_FreeVectorPointer(indexes);
return scope.Close(result);
}

View File

@ -318,6 +318,26 @@ static void FreeDatafilesVector (TRI_vector_pointer_t* const vector) {
TRI_DestroyVectorPointer(vector);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief closes the datafiles passed in the vector
////////////////////////////////////////////////////////////////////////////////
static bool CloseDataFiles (const TRI_vector_pointer_t* const files) {
TRI_datafile_t* datafile;
size_t n = files->_length;
size_t i;
bool result = true;
for (i = 0; i < n; ++i) {
datafile = files->_buffer[i];
assert(datafile);
result &= TRI_CloseDatafile(datafile);
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
@ -864,36 +884,15 @@ TRI_collection_t* TRI_OpenCollection (TRI_collection_t* collection, char const*
////////////////////////////////////////////////////////////////////////////////
int TRI_CloseCollection (TRI_collection_t* collection) {
TRI_datafile_t* datafile;
size_t n;
size_t i;
// close compactor files
n = collection->_compactors._length;
for (i = 0; i < n; ++i) {
datafile = collection->_compactors._buffer[i];
TRI_CloseDatafile(datafile);
}
CloseDataFiles(&collection->_compactors);
// close journal files
n = collection->_journals._length;
for (i = 0; i < n; ++i) {
datafile = collection->_journals._buffer[i];
TRI_CloseDatafile(datafile);
}
CloseDataFiles(&collection->_journals);
// close datafiles
n = collection->_datafiles._length;
for (i = 0; i < n; ++i) {
datafile = collection->_datafiles._buffer[i];
TRI_CloseDatafile(datafile);
}
CloseDataFiles(&collection->_datafiles);
return TRI_ERROR_NO_ERROR;
}

View File

@ -51,6 +51,38 @@
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief free an index
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeIndex (TRI_index_t* const idx) {
assert(idx);
LOG_TRACE("freeing index");
switch (idx->_type) {
case TRI_IDX_TYPE_GEO_INDEX:
TRI_FreeGeoIndex(idx);
break;
case TRI_IDX_TYPE_HASH_INDEX:
TRI_FreeHashIndex(idx);
break;
case TRI_IDX_TYPE_SKIPLIST_INDEX:
TRI_FreeSkiplistIndex(idx);
break;
case TRI_IDX_TYPE_PRIMARY_INDEX:
TRI_FreePrimaryIndex(idx);
break;
default:
// no action necessary
break;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an index file
////////////////////////////////////////////////////////////////////////////////
@ -200,6 +232,38 @@ char const* TRI_TypeNameIndex (const TRI_index_t* const idx) {
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- PRIMARY INDEX
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup VocBase
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a primary index, but does not free the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyPrimaryIndex (TRI_index_t* idx) {
LOG_TRACE("destroying primary index");
TRI_DestroyVectorString(&idx->_fields);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a primary index and frees the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_FreePrimaryIndex (TRI_index_t* idx) {
TRI_DestroyPrimaryIndex(idx);
TRI_Free(idx);
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- GEO INDEX
// -----------------------------------------------------------------------------
@ -684,9 +748,9 @@ static TRI_json_t* JsonGeoIndex2 (TRI_index_t* idx, TRI_doc_collection_t const*
TRI_PushBack3ListJson(fields, TRI_CreateStringCopyJson(latitude));
TRI_PushBack3ListJson(fields, TRI_CreateStringCopyJson(longitude));
TRI_Insert2ArrayJson(json, "id", TRI_CreateNumberJson(idx->_iid));
TRI_Insert2ArrayJson(json, "type", TRI_CreateStringCopyJson("geo"));
TRI_Insert2ArrayJson(json, "fields", fields);
TRI_Insert3ArrayJson(json, "id", TRI_CreateNumberJson(idx->_iid));
TRI_Insert3ArrayJson(json, "type", TRI_CreateStringCopyJson("geo"));
TRI_Insert3ArrayJson(json, "fields", fields);
return json;
}
@ -716,9 +780,14 @@ TRI_index_t* TRI_CreateGeoIndex (struct TRI_doc_collection_s* collection,
char* ln;
geo = TRI_Allocate(sizeof(TRI_geo_index_t));
ln = TRI_DuplicateString(locationName);
if (geo == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
if (geo == NULL || ln == NULL) {
ln = TRI_DuplicateString(locationName);
if (ln == NULL) {
TRI_Free(geo);
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
@ -802,6 +871,7 @@ TRI_index_t* TRI_CreateGeoIndex2 (struct TRI_doc_collection_s* collection,
void TRI_DestroyGeoIndex (TRI_index_t* idx) {
TRI_geo_index_t* geo;
LOG_TRACE("destroying geo index");
TRI_DestroyVectorString(&idx->_fields);
geo = (TRI_geo_index_t*) idx;
@ -1436,13 +1506,15 @@ TRI_index_t* TRI_CreateHashIndex (struct TRI_doc_collection_s* collection,
void TRI_DestroyHashIndex (TRI_index_t* idx) {
TRI_hash_index_t* hash;
LOG_TRACE("destroying hash index");
TRI_DestroyVectorString(&idx->_fields);
hash = (TRI_hash_index_t*) idx;
TRI_DestroyVector(&hash->_paths);
LOG_ERROR("TRI_DestroyHashIndex not implemented TODO oreste");
// TODO FIXME: not implemented
LOG_DEBUG("TRI_DestroyHashIndex not implemented TODO oreste");
}
////////////////////////////////////////////////////////////////////////////////
@ -2175,6 +2247,7 @@ void TRI_DestroySkiplistIndex (TRI_index_t* idx) {
return;
}
LOG_TRACE("destroying skiplist index");
TRI_DestroyVectorString(&idx->_fields);
sl = (TRI_skiplist_index_t*) idx;
@ -2191,6 +2264,7 @@ void TRI_FreeSkiplistIndex (TRI_index_t* idx) {
if (idx == NULL) {
return;
}
TRI_DestroySkiplistIndex(idx);
TRI_Free(idx);
}

View File

@ -167,6 +167,12 @@ TRI_skiplist_index_t;
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief free an index
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeIndex (TRI_index_t* const);
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an index file
////////////////////////////////////////////////////////////////////////////////
@ -195,6 +201,31 @@ char const* TRI_TypeNameIndex (const TRI_index_t* const);
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- PRIMARY INDEX
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup VocBase
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a primary index, but does not free the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyPrimaryIndex (TRI_index_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a primary index and frees the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_FreePrimaryIndex (TRI_index_t*);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- GEO INDEX
// -----------------------------------------------------------------------------

View File

@ -1826,8 +1826,7 @@ void TRI_DestroySimCollection (TRI_sim_collection_t* collection) {
for (i = 0 ; i < n ; ++i) {
TRI_index_t* idx = (TRI_index_t*) collection->_indexes._buffer[i];
TRI_DestroyVectorString(&idx->_fields);
TRI_Free(idx);
TRI_FreeIndex(idx);
}
// free index vector
TRI_DestroyVectorPointer(&collection->_indexes);
@ -2360,6 +2359,10 @@ TRI_vector_pointer_t* TRI_IndexesSimCollection (TRI_sim_collection_t* sim) {
size_t i;
vector = TRI_Allocate(sizeof(TRI_vector_pointer_t));
if (!vector) {
return NULL;
}
TRI_InitVectorPointer(vector);
// .............................................................................
@ -2803,6 +2806,7 @@ static TRI_index_t* CreateHashIndexSimCollection (TRI_sim_collection_t* collecti
// ...........................................................................
TRI_DestroyVector(&paths);
TRI_DestroyVectorPointer(&fields);
// ...........................................................................
// If index id given, use it otherwise use the default.
@ -2877,7 +2881,6 @@ static TRI_index_t* CreateSkiplistIndexSimCollection (TRI_sim_collection_t* coll
if (idx != NULL) {
TRI_DestroyVector(&paths);
TRI_DestroyVectorPointer(&fields);
LOG_TRACE("skiplist-index already created");
if (created != NULL) {
@ -2923,6 +2926,7 @@ static TRI_index_t* CreateSkiplistIndexSimCollection (TRI_sim_collection_t* coll
// ...........................................................................
TRI_DestroyVector(&paths);
TRI_DestroyVectorPointer(&fields);
if (created != NULL) {
*created = true;