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());
}
Ejemplo n.º 3
0
std::vector<Segment*>   BasicCMManager::getSegments( const Representation *rep )
{
    std::vector<Segment *>          retSegments;
    SegmentInfo*                    info = rep->getSegmentInfo();
    Segment*                        initSegment = info->getInitialisationSegment();

    if ( initSegment )
        retSegments.push_back( initSegment );
    retSegments.insert( retSegments.end(), info->getSegments().begin(),
                                            info->getSegments().end() );
    return retSegments;
}
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();
  }
}
Ejemplo n.º 5
0
std::vector<Segment*>           BasicCMManager::getSegments             (Representation *rep) const
{
    std::vector<Segment *> retSegments;

    SegmentInfo *info = rep->getSegmentInfo();
    Segment     *init = info->getInitSegment();

    retSegments.push_back(init);

    std::vector<Segment *> segments = info->getSegments();

    for(unsigned int i = 0; i < segments.size(); i++)
        retSegments.push_back(segments.at(i));

    return retSegments;
}
Ejemplo n.º 6
0
void IndexFileDeleter::decRef(const SegmentInfo& info)
{
	QList<QString> files = info.files();
	for (int i = 0; i < files.size(); i++) {
		decRef(files.at(i));
	}
}
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());
	  }
	}

}
Ejemplo n.º 8
0
std::map<size_t,Morphology::SegmentInfo> Morphology::createSegmentMap(SegmentedImageCPtr segmentedImage) const
{
	std::map<size_t,SegmentInfo> segments;
	for(size_t y=0;y<segmentedImage->Height();++y)
	{
		for(size_t x=0;x<segmentedImage->Width();++x)
		{
			size_t segmentValue = segmentedImage->Value(x,y);
			if(segmentValue != 0)
			{
				if(segments.count(segmentValue) == 0)
				{
					SegmentInfo segment;
					segment.segment = segmentValue;
					segment.left = x;
					segment.right = x+1;
					segment.top = y;
					segment.bottom = y+1;
					segment.AddPoint(x,y);
					segments.insert(std::map<size_t,SegmentInfo>::value_type(segmentValue, segment));
				} else {
					SegmentInfo &segment = segments.find(segmentValue)->second;
					segment.AddPoint(x,y);
				}
			}
		}
	}

	for(std::map<size_t,SegmentInfo>::iterator i=segments.begin();i!=segments.end();++i)
	{
		SegmentInfo &info = i->second;
		info.width = info.right - info.left;
		info.height = info.bottom - info.top;
	}
	return segments;
}