コード例 #1
0
void TRI_FreeContextAql (TRI_aql_context_t* const context) {
  TRI_ASSERT(context != NULL);

  LOG_TRACE("freeing context");

  // release all scopes
  TRI_FreeScopesAql(context);

  FreeStrings(context);
  FreeNodes(context);

  // free parameter names hash
  TRI_DestroyAssociativePointer(&context->_parameters._names);

  // free collection names
  TRI_DestroyAssociativePointer(&context->_collectionNames);

  FreeCollections(context);

  // free parameter values
  TRI_FreeBindParametersAql(context);
  TRI_DestroyAssociativePointer(&context->_parameters._values);

  // free parser/lexer
  TRI_FreeParserAql(context->_parser);

  // free statement list
  TRI_FreeStatementListAql(context->_statements);

  // free error struct
  TRI_DestroyErrorAql(&context->_error);

  TRI_Free(TRI_UNKNOWN_MEM_ZONE, context);
}
コード例 #2
0
ファイル: json-shaper.c プロジェクト: santanu1122/ArangoDB
void TRI_DestroyArrayShaper (TRI_shaper_t* shaper) {
  array_shaper_t* s;
  size_t i;
  size_t n;

  s = (array_shaper_t*) shaper;

  for (i = 0, n = s->_attributes._length;  i < n;  ++i) {
    attribute_2_id_t* a2i;

    a2i = s->_attributes._buffer[i];
    TRI_Free(shaper->_memoryZone, a2i);
  }

  TRI_DestroyAssociativePointer(&s->_attributeNames);
  TRI_DestroyVectorPointer(&s->_attributes);

  for (i = 0, n = s->_shapes._length;  i < n;  ++i) {
    TRI_shape_t* shape;

    shape = s->_shapes._buffer[i];
    TRI_Free(shaper->_memoryZone, shape);
  }

  TRI_DestroyAssociativePointer(&s->_shapeDictionary);
  TRI_DestroyVectorPointer(&s->_shapes);

  TRI_DestroyShaper(shaper);
}
コード例 #3
0
void TRI_DestroyPrimaryCollection (TRI_primary_collection_t* primary) {
  size_t i, n;

  if (primary->_keyGenerator != NULL) {
    TRI_FreeKeyGenerator(primary->_keyGenerator);
  }

  TRI_DestroyReadWriteLock(&primary->_compactionLock);
  TRI_DestroyReadWriteLock(&primary->_lock);

  TRI_DestroyAssociativePointer(&primary->_primaryIndex);

  if (primary->_shaper != NULL) {
    TRI_FreeVocShaper(primary->_shaper);
  }
  
  n = primary->_datafileInfo._nrAlloc;

  for (i = 0; i < n; ++i) {
    TRI_doc_datafile_info_t* dfi = primary->_datafileInfo._table[i];
    if (dfi != NULL) {
      FreeDatafileInfo(dfi);
    }
  }

  TRI_DestroyAssociativePointer(&primary->_datafileInfo);
  
  TRI_DestroyBarrierList(&primary->_barrierList);

  TRI_DestroyCollection(&primary->base);
}
コード例 #4
0
bool TRI_HasDuplicateKeyJson (const TRI_json_t* const object) {
  if (object && object->_type == TRI_JSON_ARRAY) {
    size_t n;

    // if we don't have attributes, we do not need to check for duplicates
    // if we only have one attribute, we don't need to check for duplicates in 
    // the array, but we need to recursively validate the array values (if 
    // array value itself is an array)
    n = object->_value._objects._length;
    if (n > 0) {
      TRI_associative_pointer_t hash;
      size_t i;

      TRI_InitAssociativePointer(&hash, 
          TRI_UNKNOWN_MEM_ZONE, 
          &TRI_HashStringKeyAssociativePointer,
          &TRI_HashStringKeyAssociativePointer,
          &TRI_EqualStringKeyAssociativePointer,
          0);

      for (i = 0;  i < n; i += 2) {
        TRI_json_t* key;
        TRI_json_t* value;
        void* previous;

        key = TRI_AtVector(&object->_value._objects, i);

        if (key->_type != TRI_JSON_STRING) {
          continue;
        }

        value = TRI_AtVector(&object->_value._objects, i + 1);

        // recursively check sub-array elements
        if (value->_type == TRI_JSON_ARRAY && TRI_HasDuplicateKeyJson(value)) {
          // duplicate found in sub-array
          TRI_DestroyAssociativePointer(&hash);

          return true;
        }

        previous = TRI_InsertKeyAssociativePointer(&hash, key->_value._string.data, key->_value._string.data, false);
        if (previous != NULL) {
          // duplicate found
          TRI_DestroyAssociativePointer(&hash);

          return true;
        }
      }

      TRI_DestroyAssociativePointer(&hash);
    }
  }

  // no duplicate found
  return false;
}
コード例 #5
0
ファイル: shadow-data.c プロジェクト: aboleab/ArangoDB
void TRI_FreeShadowStore (TRI_shadow_store_t* const store) {
  assert(store);

  // force deletion of all remaining shadows
  TRI_CleanupShadowData(store, 0.0, true);

  TRI_DestroyMutex(&store->_lock);
  TRI_DestroyAssociativePointer(&store->_ids);
  TRI_DestroyAssociativePointer(&store->_pointers);
  TRI_Free(TRI_UNKNOWN_MEM_ZONE, store);
}
コード例 #6
0
static void FreeScope (TRI_aql_scope_t* const scope) {
  size_t i, n;

  // free variables lookup hash
  n = scope->_variables._nrAlloc;
  for (i = 0; i < n; ++i) {
    TRI_aql_variable_t* variable = scope->_variables._table[i];

    if (variable) {
      TRI_FreeVariableAql(variable);
    }
  }

  TRI_DestroyAssociativePointer(&scope->_variables);

  if (scope->_ranges) {
    // free ranges if set
    TRI_FreeAccessesAql(scope->_ranges);
  }

  for (i = 0; i < scope->_sorts._length; ++i) {
    char* criterion = (char*) TRI_AtVectorPointer(&scope->_sorts, i);

    TRI_Free(TRI_UNKNOWN_MEM_ZONE, criterion);
  }

  TRI_DestroyVectorPointer(&scope->_sorts);

  TRI_Free(TRI_UNKNOWN_MEM_ZONE, scope);
}
コード例 #7
0
void TRI_FreeStoreGeneralCursor (TRI_general_cursor_store_t* store) {
  // force deletion of all remaining cursors
  TRI_CleanupGeneralCursor(store, true);

  TRI_DestroySpin(&store->_lock);
  TRI_DestroyAssociativePointer(&store->_ids);
  TRI_Free(TRI_UNKNOWN_MEM_ZONE, store);
}
コード例 #8
0
static void FreeDatafileInfo (TRI_associative_pointer_t* const files) {
  size_t i;
  size_t n;

  n = files->_nrAlloc;
  for (i = 0; i < n; ++i) {
    TRI_doc_datafile_info_t* file = files->_table[i];
    if (!file) {
      continue;
    }

    TRI_Free(TRI_UNKNOWN_MEM_ZONE, file);
  }

  TRI_DestroyAssociativePointer(files);
}
コード例 #9
0
void TRI_FreeFunctionsAql (TRI_associative_pointer_t* functions) {
  size_t i;

  for (i = 0; i < functions->_nrAlloc; ++i) {
    TRI_aql_function_t* function = (TRI_aql_function_t*) functions->_table[i];
    if (!function) {
      continue;
    }

    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function->_externalName);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function->_internalName);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, function);
  }

  TRI_DestroyAssociativePointer(functions);
  TRI_Free(TRI_UNKNOWN_MEM_ZONE, functions);
}
コード例 #10
0
void TRI_DestroyPrimaryCollection (TRI_primary_collection_t* primary) {
  if (primary->_keyGenerator != NULL) {
    TRI_FreeKeyGenerator(primary->_keyGenerator);
  }

  TRI_DestroyReadWriteLock(&primary->_lock);
  TRI_DestroyAssociativePointer(&primary->_primaryIndex);

  if (primary->_shaper != NULL) {
    TRI_FreeVocShaper(primary->_shaper);
  }

  FreeDatafileInfo(&primary->_datafileInfo);
  TRI_DestroyBarrierList(&primary->_barrierList);

  TRI_DestroyCollection(&primary->base);
}
コード例 #11
0
int TRI_InitPrimaryCollection (TRI_primary_collection_t* primary,
                               TRI_shaper_t* shaper) {
  int res;

  primary->_shaper             = shaper;
  primary->_capConstraint      = NULL;
  primary->_keyGenerator       = NULL;
  primary->_numberDocuments    = 0;
  primary->_lastCompaction     = 0.0;

  primary->figures             = Figures;
  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_InitReadWriteLock(&primary->_lock);
  TRI_InitReadWriteLock(&primary->_compactionLock);

  return TRI_ERROR_NO_ERROR;
}
コード例 #12
0
ファイル: mimetypes.cpp プロジェクト: CedarLogic/arangodb
void TRI_ShutdownMimetypes () {
  size_t i;

  if (! Initialized) {
    return;
  }

  for (i = 0; i < Mimetypes._nrAlloc; i++) {
    mimetype_t* mimetype = static_cast<mimetype_t*>(Mimetypes._table[i]);

    if (mimetype != nullptr) {
      TRI_Free(TRI_CORE_MEM_ZONE, mimetype->_extension);
      TRI_Free(TRI_CORE_MEM_ZONE, mimetype->_mimetype);
      TRI_Free(TRI_CORE_MEM_ZONE, mimetype);
    }
  }

  TRI_DestroyAssociativePointer(&Mimetypes);

  Initialized = false;
}
コード例 #13
0
ファイル: ahuacatl-scope.c プロジェクト: luxyer/ArangoDB
static void FreeScope (TRI_aql_scope_t* const scope) {
  size_t i, n;

  // free variables lookup hash
  n = scope->_variables._nrAlloc;
  for (i = 0; i < n; ++i) {
    TRI_aql_variable_t* variable = scope->_variables._table[i];

    if (variable) {
      TRI_FreeVariableAql(variable);
    }
  }
  
  TRI_DestroyAssociativePointer(&scope->_variables);
  
  if (scope->_ranges) {
    // free ranges if set
    TRI_FreeAccessesAql(scope->_ranges);
  }

  TRI_Free(TRI_UNKNOWN_MEM_ZONE, scope);
}
コード例 #14
0
TRI_aql_context_t* TRI_CreateContextAql (TRI_vocbase_t* vocbase,
                                         const char* const query,
                                         const size_t queryLength,
                                         bool isCoordinator,
                                         TRI_json_t* userOptions) {
  TRI_aql_context_t* context;
  int res;

  TRI_ASSERT(vocbase != NULL);
  TRI_ASSERT(query != NULL);

  LOG_TRACE("creating context");

  context = (TRI_aql_context_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_context_t), false);

  if (context == NULL) {
    return NULL;
  }

  context->_type            = TRI_AQL_QUERY_READ;
  context->_vocbase         = vocbase;
  context->_userOptions     = userOptions;
  context->_writeOptions    = NULL;
  context->_writeCollection = NULL;

  context->_variableIndex   = 0;
  context->_scopeIndex      = 0;
  context->_subQueries      = 0;

  // actual bind parameter values
  res = TRI_InitAssociativePointer(&context->_parameters._values,
                                   TRI_UNKNOWN_MEM_ZONE,
                                   &TRI_HashStringKeyAssociativePointer,
                                   &TRI_HashBindParameterAql,
                                   &TRI_EqualBindParameterAql,
                                   0);

  if (res != TRI_ERROR_NO_ERROR) {
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, context);

    return NULL;
  }

  // bind parameter names used in the query
  res = TRI_InitAssociativePointer(&context->_parameters._names,
                                   TRI_UNKNOWN_MEM_ZONE,
                                   &TRI_HashStringKeyAssociativePointer,
                                   &TRI_HashStringKeyAssociativePointer,
                                   &TRI_EqualStringKeyAssociativePointer,
                                   0);

  if (res != TRI_ERROR_NO_ERROR) {
    TRI_DestroyAssociativePointer(&context->_parameters._values);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, context);

    return NULL;
  }

  // collections
  res = TRI_InitAssociativePointer(&context->_collectionNames,
                                   TRI_UNKNOWN_MEM_ZONE,
                                   &TRI_HashStringKeyAssociativePointer,
                                   &TRI_HashStringKeyAssociativePointer,
                                   &TRI_EqualStringKeyAssociativePointer,
                                   0);

  if (res != TRI_ERROR_NO_ERROR) {
    TRI_DestroyAssociativePointer(&context->_parameters._names);
    TRI_DestroyAssociativePointer(&context->_parameters._values);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, context);

    return NULL;
  }

  TRI_InitVectorPointer2(&context->_memory._nodes, TRI_UNKNOWN_MEM_ZONE, 16);
  TRI_InitVectorPointer2(&context->_memory._strings, TRI_UNKNOWN_MEM_ZONE, 16);
  TRI_InitVectorPointer(&context->_collections, TRI_UNKNOWN_MEM_ZONE);

  TRI_InitErrorAql(&context->_error);

  context->_parser     = NULL;
  context->_statements = NULL;
  context->_query      = query;

  TRI_InitScopesAql(context);

  context->_parser = TRI_CreateParserAql(context->_query, queryLength);

  if (context->_parser == NULL) {
    // could not create the parser
    TRI_FreeContextAql(context);
    return NULL;
  }

  if (! TRI_InitParserAql(context)) {
    // could not initialise the lexer
    TRI_FreeContextAql(context);

    return NULL;
  }

  context->_statements = TRI_CreateStatementListAql();

  if (context->_statements == NULL) {
    // could not create statement list
    TRI_FreeContextAql(context);

    return NULL;
  }

  ProcessOptions(context);

  context->_isCoordinator = isCoordinator;

  return context;
}
コード例 #15
0
void TRI_FreeAssociativePointer (TRI_associative_pointer_t* array) {
  TRI_DestroyAssociativePointer(array);
  TRI_Free(array);
}
コード例 #16
0
bool TRI_HasDuplicateKeyJson (TRI_json_t const* object) {
    if (object && object->_type == TRI_JSON_OBJECT) {
        size_t const n = TRI_LengthVector(&object->_value._objects);
        const bool hasMultipleElements = (n > 2);

        // if we don't have attributes, we do not need to check for duplicates
        // if we only have one attribute, we don't need to check for duplicates in
        // the array, but we need to recursively validate the array values (if
        // array value itself is an array)
        if (n > 0) {
            TRI_associative_pointer_t hash;
            size_t i;

            if (hasMultipleElements) {
                TRI_InitAssociativePointer(&hash,
                                           TRI_UNKNOWN_MEM_ZONE,
                                           &TRI_HashStringKeyAssociativePointer,
                                           &TRI_HashStringKeyAssociativePointer,
                                           &TRI_EqualStringKeyAssociativePointer,
                                           0);
            }

            for (i = 0;  i < n; i += 2) {
                auto key = static_cast<TRI_json_t const*>(TRI_AtVector(&object->_value._objects, i));

                if (! TRI_IsStringJson(key)) {
                    continue;
                }

                auto value = static_cast<TRI_json_t const*>(TRI_AtVector(&object->_value._objects, i + 1));

                // recursively check sub-array elements
                if (value->_type == TRI_JSON_OBJECT && TRI_HasDuplicateKeyJson(value)) {
                    // duplicate found in sub-array
                    if (hasMultipleElements) {
                        TRI_DestroyAssociativePointer(&hash);
                    }

                    return true;
                }

                if (hasMultipleElements) {
                    void* previous = TRI_InsertKeyAssociativePointer(&hash, key->_value._string.data, key->_value._string.data, false);

                    if (previous != nullptr) {
                        // duplicate found
                        TRI_DestroyAssociativePointer(&hash);

                        return true;
                    }
                }
            }

            if (hasMultipleElements) {
                TRI_DestroyAssociativePointer(&hash);
            }
        }
    }

    // no duplicate found
    return false;
}
コード例 #17
0
ファイル: linked-list.c プロジェクト: santanu1122/ArangoDB
void TRI_DestroyLinkedArray (TRI_linked_array_t* array) {
  TRI_DestroyLinkedList(&array->_list, array->_memoryZone);
  TRI_DestroyAssociativePointer(&array->_array);
}
コード例 #18
0
ファイル: associative.cpp プロジェクト: CoDEmanX/ArangoDB
void TRI_FreeAssociativePointer (TRI_memory_zone_t* zone, TRI_associative_pointer_t* array) {
  TRI_DestroyAssociativePointer(array);
  TRI_Free(zone, array);
}