示例#1
0
static TRI_datafile_t* CreateCompactor (TRI_document_collection_t* document,
                                        TRI_voc_fid_t fid,
                                        TRI_voc_size_t maximalSize) {
  TRI_collection_t* collection;
  TRI_datafile_t* compactor;
  
  collection = &document->base.base;
  
  // reserve room for one additional entry
  if (TRI_ReserveVectorPointer(&collection->_compactors, 1) != TRI_ERROR_NO_ERROR) {
    // could not get memory, exit early
    return NULL;
  }
  
  TRI_LOCK_JOURNAL_ENTRIES_DOC_COLLECTION(document);

  compactor = TRI_CreateCompactorPrimaryCollection(&document->base, fid, maximalSize);

  if (compactor != NULL) {
    int res = TRI_PushBackVectorPointer(&collection->_compactors, compactor);

    // we have reserved space before, so we can be sure the push succeeds
    assert(res == TRI_ERROR_NO_ERROR);
  }
    
  // we still must wake up the other thread from time to time, otherwise we'll deadlock
  TRI_BROADCAST_JOURNAL_ENTRIES_DOC_COLLECTION(document);

  TRI_UNLOCK_JOURNAL_ENTRIES_DOC_COLLECTION(document);

  return compactor;
}
示例#2
0
static bool CheckCompactorDocumentCollection (TRI_document_collection_t* sim) {
  TRI_collection_t* base;
  TRI_datafile_t* compactor;
  bool worked;
  size_t i;
  size_t n;
  
  worked = false;
  base = &sim->base.base;

  // .............................................................................
  // the only thread MODIFYING the _compactor variable is this thread,
  // therefore no locking is required to access the _compactors
  // .............................................................................

  n = base->_compactors._length;

  for (i = 0;  i < n;) {
    compactor = base->_compactors._buffer[i];

    if (compactor->_full) {
      worked = true;

      LOG_DEBUG("closing full compactor '%s'", compactor->_filename);

      TRI_LOCK_JOURNAL_ENTRIES_DOC_COLLECTION(sim);
      TRI_CloseCompactorPrimaryCollection(&sim->base, i);
      TRI_UNLOCK_JOURNAL_ENTRIES_DOC_COLLECTION(sim);

      n = base->_compactors._length;
      i = 0;
    }
    else {
      ++i;
    }
  }

  if (base->_compactors._length == 0) {
    TRI_LOCK_JOURNAL_ENTRIES_DOC_COLLECTION(sim);

    compactor = TRI_CreateCompactorPrimaryCollection(&sim->base);

    if (compactor != NULL) {
      worked = true;
      LOG_DEBUG("created new compactor '%s'", compactor->_filename);
    
      TRI_BROADCAST_JOURNAL_ENTRIES_DOC_COLLECTION(sim);
    }
    else {
      // an error occurred when creating the compactor file
      LOG_ERROR("could not create compactor file");
    }

    TRI_UNLOCK_JOURNAL_ENTRIES_DOC_COLLECTION(sim);
  }

  return worked;
}