Ejemplo n.º 1
0
void IndexFileDeleter::decRef(const SegmentInfo& info)
{
	QList<QString> files = info.files();
	for (int i = 0; i < files.size(); i++) {
		decRef(files.at(i));
	}
}
void IndexFileDeleter::decRef(SegmentInfos* segmentInfos) {
  int32_t size = segmentInfos->size();
  for(int32_t i=0;i<size;i++) {
    SegmentInfo* segmentInfo = segmentInfos->info(i);
    if (segmentInfo->dir == directory) {
      decRef(segmentInfo->files());
    }
  }
}
/**
* For definition of "check point32_t" see IndexWriter comments:
* "Clarification: Check Point32_ts (and commits)".
*
* Writer calls this when it has made a "consistent
* change" to the index, meaning new files are written to
* the index and the in-memory SegmentInfos have been
* modified to point32_t to those files.
*
* This may or may not be a commit (segments_N may or may
* not have been written).
*
* We simply incref the files referenced by the new
* SegmentInfos and decref the files we had previously
* seen (if any).
*
* If this is a commit, we also call the policy to give it
* a chance to remove other commits.  If any commits are
* removed, we decref their files as well.
*/
void IndexFileDeleter::checkpoint(SegmentInfos* segmentInfos, bool isCommit) {

  if (infoStream != NULL) {
    message(string("now checkpoint \"") + segmentInfos->getCurrentSegmentFileName() + "\" [" +
      Misc::toString(segmentInfos->size()) + " segments ; isCommit = " + Misc::toString(isCommit) + "]");
  }

  // Try again now to delete any previously un-deletable
  // files (because they were in use, on Windows):
  deletePendingFiles();

  // Incref the files:
  incRef(segmentInfos, isCommit);
  const vector<string>* docWriterFiles = NULL;
  if (docWriter != NULL) {
    docWriterFiles = &docWriter->files();
    if (!docWriterFiles->empty())
      incRef(*docWriterFiles);
    else
      docWriterFiles = NULL;
  }

  if (isCommit) {
    // Append to our commits list:
    commits.push_back(_CLNEW CommitPoint(this, segmentInfos));

    // Tell policy so it can remove commits:
    policy->onCommit(commits);

    // Decref files for commits that were deleted by the policy:
    deleteCommits();
  }

  // DecRef old files from the last checkpoint, if any:
  int32_t size = lastFiles.size();
  if (size > 0) {
    for(int32_t i=0;i<size;i++)
      decRef(lastFiles[i]);
    lastFiles.clear();
  }

  if (!isCommit) {
    // Save files so we can decr on next checkpoint/commit:
    size = segmentInfos->size();
    for(int32_t i=0;i<size;i++) {
      SegmentInfo* segmentInfo = segmentInfos->info(i);
      if (segmentInfo->dir == directory) {
        const vector<string>& files = segmentInfo->files();
        lastFiles.insert(lastFiles.end(), files.begin(), files.end());
      }
    }
  }
  if (docWriterFiles != NULL)
    lastFiles.insert(lastFiles.end(), docWriterFiles->begin(),docWriterFiles->end());
}
void IndexFileDeleter::incRef(SegmentInfos* segmentInfos, bool isCommit) {
  int32_t size = segmentInfos->size();
  for(int32_t i=0;i<size;i++) {
    SegmentInfo* segmentInfo = segmentInfos->info(i);
    if (segmentInfo->dir == directory) {
      incRef(segmentInfo->files());
    }
  }

  if (isCommit) {
    // Since this is a commit point32_t, also incref its
    // segments_N file:
    getRefCount(segmentInfos->getCurrentSegmentFileName().c_str())->IncRef();
  }
}
IndexFileDeleter::CommitPoint::CommitPoint(IndexFileDeleter* _this, SegmentInfos* segmentInfos){
  this->_this = _this;
  this->deleted = false;
  this->gen = 0;
	segmentsFileName = segmentInfos->getCurrentSegmentFileName();
	int32_t size = segmentInfos->size();
	files.push_back(segmentsFileName);
	gen = segmentInfos->getGeneration();
	for(int32_t i=0;i<size;i++) {
	  SegmentInfo* segmentInfo = segmentInfos->info(i);
	  if (segmentInfo->dir == _this->directory) {
      const vector<string>& ff = segmentInfo->files();
      files.insert(files.end(),ff.begin(), ff.end());
	  }
	}

}