Exemplo n.º 1
0
static void DecreaseRefCount (TRI_shadow_store_t* const store, TRI_shadow_t* const shadow) {
  LOG_TRACE("decreasing refcount for shadow %p with data ptr %p and id %llu to %d",
            shadow,
            shadow->_data,
            (unsigned long long) shadow->_id,
            (int) (shadow->_rc - 1));

  if (--shadow->_rc <= 0 && shadow->_type == SHADOW_TRANSIENT) {
    LOG_TRACE("deleting transient shadow %p", shadow);

    TRI_RemoveKeyAssociativePointer(&store->_ids, &shadow->_id);
    TRI_RemoveKeyAssociativePointer(&store->_pointers, shadow->_data);
    store->destroyShadow(shadow->_data);
    TRI_Free(TRI_UNKNOWN_MEM_ZONE, shadow);
  }
}
Exemplo n.º 2
0
void TRI_RemoveLinkedArray (TRI_linked_array_t* array, void const* data) {
  TRI_linked_list_entry_t* found;

  found = TRI_RemoveKeyAssociativePointer(&array->_array, data);

  if (found != NULL) {
    TRI_RemoveLinkedList(&array->_list, found);
    TRI_Free(array->_memoryZone, found);
  }
}
Exemplo n.º 3
0
static TRI_shape_aid_t FindAttributeNameArrayShaper (TRI_shaper_t* shaper, char const* name) {
  array_shaper_t* s;
  void const* p;

  s = (array_shaper_t*) shaper;
  p = TRI_LookupByKeyAssociativePointer(&s->_attributeNames, name);

  if (p == NULL) {
    size_t n;
    attribute_2_id_t* a2i;
    void* f;
    int res;

    n = strlen(name) + 1;
    a2i = TRI_Allocate(shaper->_memoryZone, sizeof(attribute_2_id_t) + n, false);

    if (a2i == NULL) {
      return 0;
    }

    a2i->_aid = 1 + s->_attributes._length;
    a2i->_size = n;
    memcpy(((char*) a2i) + sizeof(attribute_2_id_t), name, n);

    f = TRI_InsertKeyAssociativePointer(&s->_attributeNames, name, a2i, false);

    if (f == NULL) {
      TRI_Free(shaper->_memoryZone, a2i);
      return 0;
    }

    res = TRI_PushBackVectorPointer(&s->_attributes, a2i);

    if (res != TRI_ERROR_NO_ERROR) {
      TRI_RemoveKeyAssociativePointer(&s->_attributeNames, name);
      TRI_Free(shaper->_memoryZone, a2i);
      return 0;
    }

    return a2i->_aid;
  }
  else {
    attribute_2_id_t const* a2i = (attribute_2_id_t const*) p;

    return a2i->_aid;
  }
}
Exemplo n.º 4
0
void TRI_CleanupGeneralCursor (TRI_general_cursor_store_t* store,
                               bool force) {
  double compareStamp = TRI_microtime();
  size_t deleteCount = 0;

  // we need an exclusive lock on the index
  TRI_LockSpin(&store->_lock);

  if (store->_ids._nrUsed == 0) {
    // store is empty, nothing to do!
    TRI_UnlockSpin(&store->_lock);
    return;
  }

  LOG_TRACE("cleaning shadows. in store: %ld", (unsigned long) store->_ids._nrUsed);

  // loop until there's nothing to delete or
  // we have deleted CURSOR_MAX_DELETE elements
  while (deleteCount++ < CURSOR_MAX_DELETE || force) {
    bool deleted = false;
    size_t i;

    for (i = 0; i < store->_ids._nrAlloc; i++) {
      // enum all cursors
      TRI_general_cursor_t* cursor = (TRI_general_cursor_t*) store->_ids._table[i];

      if (cursor == NULL) {
        continue;
      }

      TRI_LockSpin(&cursor->_lock);

      if (force ||
          (cursor->_usage._refCount == 0 &&
           (cursor->_usage._isDeleted || cursor->_expires < compareStamp))) {
        LOG_TRACE("cleaning cursor %p, id: %llu, rc: %d, expires: %d, deleted: %d",
                  cursor,
                  (unsigned long long) cursor->_id,
                  (int) cursor->_usage._refCount,
                  (int) cursor->_expires,
                  (int) cursor->_usage._isDeleted);

        TRI_RemoveKeyAssociativePointer(&store->_ids, &cursor->_id);
        TRI_UnlockSpin(&cursor->_lock);
        TRI_FreeGeneralCursor(cursor);
        deleted = true;

        // the remove might reposition elements in the container.
        // therefore break here and start iteration anew
        break;
      }

      TRI_UnlockSpin(&cursor->_lock);
    }

    if (! deleted) {
      // we did not find anything to delete, so give up
      break;
    }
  }

  // release lock
  TRI_UnlockSpin(&store->_lock);
}
Exemplo n.º 5
0
void TRI_RemoveDatafileInfoPrimaryCollection (TRI_primary_collection_t* primary,
                                              TRI_voc_fid_t fid) {
  TRI_RemoveKeyAssociativePointer(&primary->_datafileInfo, &fid);
}
Exemplo n.º 6
0
void TRI_CleanupShadowData (TRI_shadow_store_t* const store,
                            const double maxAge,
                            const bool force) {
  double compareStamp = TRI_microtime() - maxAge; // age must be specified in secs
  size_t deleteCount = 0;

  // we need an exclusive lock on the index
  TRI_LockMutex(&store->_lock);

  if (store->_ids._nrUsed == 0) {
    // store is empty, nothing to do!
    TRI_UnlockMutex(&store->_lock);
    return;
  }

  LOG_TRACE("cleaning shadows. in store: %ld", (unsigned long) store->_ids._nrUsed);

  // loop until there's nothing to delete or
  // we have deleted SHADOW_MAX_DELETE elements
  while (deleteCount++ < SHADOW_MAX_DELETE || force) {
    bool deleted = false;
    size_t i;

    for (i = 0; i < store->_ids._nrAlloc; i++) {
      // enum all shadows
      TRI_shadow_t* shadow = (TRI_shadow_t*) store->_ids._table[i];

      if (shadow == NULL) {
        continue;
      }
          
      // check if shadow is unused and expired
      if (shadow->_rc < 1 || force) {
        if (shadow->_type == SHADOW_TRANSIENT ||
            shadow->_timestamp < compareStamp ||
            shadow->_deleted ||
            force) {
          LOG_TRACE("cleaning shadow %p, id: %llu, rc: %d, expired: %d, deleted: %d",
                    shadow,
                    (unsigned long long) shadow->_id,
                    (int) shadow->_rc,
                    (int) (shadow->_timestamp < compareStamp),
                    (int) shadow->_deleted);

          TRI_RemoveKeyAssociativePointer(&store->_ids, &shadow->_id);
          TRI_RemoveKeyAssociativePointer(&store->_pointers, shadow->_data);
          store->destroyShadow(shadow->_data);
          TRI_Free(TRI_UNKNOWN_MEM_ZONE, shadow);

          deleted = true;
          // the remove might reposition elements in the container.
          // therefore break here and start iteration anew
          break;
        }
      }
    }

    if (! deleted) {
      // we did not find anything to delete, so give up
      break;
    }
  }

  // release lock
  TRI_UnlockMutex(&store->_lock);
}