Ejemplo n.º 1
0
bool TRI_RegisterNodeContextAql (TRI_aql_context_t* const context,
                                 void* const node) {
  TRI_ASSERT_MAINTAINER(context != NULL);
  TRI_ASSERT_MAINTAINER(node != NULL);

  TRI_PushBackVectorPointer(&context->_memory._nodes, node);

  return true;
}
Ejemplo n.º 2
0
static const char* NormalizeName (const TRI_aql_function_t* const function) {
  const char* pos;

  TRI_ASSERT_MAINTAINER(function != NULL);
  TRI_ASSERT_MAINTAINER(function->_externalName != NULL);

  pos = strstr(function->_externalName, "::");

  if (pos == NULL) {
    return function->_externalName;
  }

  return (pos + 2);
}
Ejemplo n.º 3
0
void TRI_CloneMarker (TRI_df_marker_t* dst,
                      TRI_df_marker_t const* src,
                      TRI_voc_size_t copyLength,
                      TRI_voc_size_t newSize,
                      TRI_voc_tick_t tick) {
  TRI_ASSERT_MAINTAINER(src != NULL);
  TRI_ASSERT_MAINTAINER(dst != NULL);
  TRI_ASSERT_MAINTAINER(copyLength > 0);
  TRI_ASSERT_MAINTAINER(newSize > 0);
  TRI_ASSERT_MAINTAINER(tick > 0);

  memcpy(dst, src, copyLength);

  dst->_size = newSize;
  dst->_crc  = 0;
  dst->_tick = tick;
}
Ejemplo n.º 4
0
void TRI_CloneMarker (TRI_df_marker_t* dst,
                      TRI_df_marker_t const* src,
                      TRI_voc_size_t copyLength,
                      TRI_voc_size_t newSize) {
  TRI_ASSERT_MAINTAINER(src != NULL);
  TRI_ASSERT_MAINTAINER(dst != NULL);
  TRI_ASSERT_MAINTAINER(copyLength > 0);
  TRI_ASSERT_MAINTAINER(newSize > 0);

  memcpy(dst, src, copyLength);

  dst->_size = newSize;

  // these values will be set later, so wipe them
  dst->_crc  = 0;
  dst->_tick = 0;
}
Ejemplo n.º 5
0
void TRI_InitMarker (TRI_df_marker_t* marker,
                     TRI_df_marker_type_e type,
                     TRI_voc_size_t size,
                     TRI_voc_tick_t tick) {

  TRI_ASSERT_MAINTAINER(marker != NULL);
  TRI_ASSERT_MAINTAINER(type > TRI_MARKER_MIN && type < TRI_MARKER_MAX);
  TRI_ASSERT_MAINTAINER(size > 0);
  TRI_ASSERT_MAINTAINER(tick > 0);

  // initialise the basic bytes
  memset(marker, 0, size);

  marker->_size = size;
  marker->_crc  = 0;
  marker->_type = type;
  marker->_tick = tick;
}
Ejemplo n.º 6
0
void TRI_InitMarker (char* marker,
                     TRI_df_marker_type_e type,
                     TRI_voc_size_t size) {

  TRI_df_marker_t* df = (TRI_df_marker_t*) marker;

  TRI_ASSERT_MAINTAINER(marker != NULL);
  TRI_ASSERT_MAINTAINER(type > TRI_MARKER_MIN && type < TRI_MARKER_MAX);
  TRI_ASSERT_MAINTAINER(size > 0);

  // initialise the basic bytes
  memset(marker, 0, size);

  df->_size = size;
  df->_type = type;
  // not needed because of memset above
  // marker->_crc  = 0;
  // marker->_tick = 0;
}
Ejemplo n.º 7
0
static int PostInsertCapConstraint (TRI_transaction_collection_t* trxCollection,
                                    TRI_index_t* idx,
                                    TRI_doc_mptr_t const* doc) {
  TRI_cap_constraint_t* cap;

  cap = (TRI_cap_constraint_t*) idx;

  TRI_ASSERT_MAINTAINER(cap->_size > 0);

  return ApplyCap(cap, trxCollection->_collection->_collection, trxCollection);
}
Ejemplo n.º 8
0
void TRI_FreeContextAql (TRI_aql_context_t* const context) {
  TRI_ASSERT_MAINTAINER(context != NULL);

  LOG_TRACE("freeing context");

  // remove barriers for all collections used
  TRI_RemoveBarrierCollectionsAql(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);
}
Ejemplo n.º 9
0
static int InitialiseCap (TRI_cap_constraint_t* cap, 
                          TRI_primary_collection_t* primary) { 
  TRI_document_collection_t* document;
  TRI_headers_t* headers;
  size_t count;
  
  TRI_ASSERT_MAINTAINER(cap->_size > 0);
  
  document = (TRI_document_collection_t*) primary;
  headers = document->_headers;
  count = headers->count(headers);
  
  if (count <= cap->_size) {
    // nothing to do
    return TRI_ERROR_NO_ERROR;
  }
  else {
    TRI_vocbase_t* vocbase;
    TRI_transaction_t* trx;
    TRI_transaction_collection_t* trxCollection;
    TRI_voc_cid_t cid;
    int res;

    vocbase = primary->base._vocbase;
    cid = primary->base._info._cid;

    trx = TRI_CreateTransaction(vocbase->_transactionContext, 0.0, false);

    if (trx == NULL) {
      return TRI_ERROR_OUT_OF_MEMORY;
    }

    res = TRI_AddCollectionTransaction(trx, cid, TRI_TRANSACTION_WRITE, TRI_TRANSACTION_TOP_LEVEL);

    if (res == TRI_ERROR_NO_ERROR) {
      trxCollection = TRI_GetCollectionTransaction(trx, cid, TRI_TRANSACTION_WRITE);

      if (trxCollection != NULL) {
        res = TRI_BeginTransaction(trx, (TRI_transaction_hint_t) TRI_TRANSACTION_HINT_LOCK_NEVER, TRI_TRANSACTION_TOP_LEVEL);

        if (res == TRI_ERROR_NO_ERROR) {
          res = ApplyCap(cap, primary, trxCollection);

          if (res == TRI_ERROR_NO_ERROR) {
            res = TRI_CommitTransaction(trx, TRI_TRANSACTION_TOP_LEVEL);
          }
          else {
            TRI_AbortTransaction(trx, TRI_TRANSACTION_TOP_LEVEL);
          }
        }
      }
      else {
        res = TRI_ERROR_INTERNAL;
      }
    }

    TRI_FreeTransaction(trx);

    return res;
  }
}
Ejemplo n.º 10
0
TRI_aql_context_t* TRI_CreateContextAql (TRI_vocbase_t* vocbase,
                                         const char* const query) {
  TRI_aql_context_t* context;

  TRI_ASSERT_MAINTAINER(vocbase != NULL);
  TRI_ASSERT_MAINTAINER(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->_vocbase = vocbase;

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

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

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

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

  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;

  context->_parser = TRI_CreateParserAql(context->_query);
  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;
  }

  TRI_InitScopesAql(context);

  return context;
}