private void pushToSnapshot(List<ImmutableSegment> segments) { if(segments.isEmpty()) return; if(segments.size() == 1 && !segments.get(0).isEmpty()) { this.snapshot = segments.get(0); return; } else { // create composite snapshot this.snapshot = SegmentFactory.instance().createCompositeImmutableSegment(getComparator(), segments); } }
private void pushPipelineToSnapshot() { int iterationsCnt = 0; boolean done = false; while (!done) { iterationsCnt++; VersionedSegmentsList segments = pipeline.getVersionedList(); pushToSnapshot(segments.getStoreSegments()); // swap can return false in case the pipeline was updated by ongoing compaction // and the version increase, the chance of it happenning is very low // In Swap: don't close segments (they are in snapshot now) and don't update the region size done = pipeline.swap(segments, null, false, false); if (iterationsCnt>2) { // practically it is impossible that this loop iterates more than two times // (because the compaction is stopped and none restarts it while in snapshot request), // however stopping here for the case of the infinite loop causing by any error LOG.warn("Multiple unsuccessful attempts to push the compaction pipeline to snapshot," + " while flushing to disk."); this.snapshot = SegmentFactory.instance().createImmutableSegment(getComparator()); break; } } }
case COMPACT: iterator = new MemStoreCompactorSegmentsIterator(segments, compactingMemStore.getComparator(), compactionKVMax, compactingMemStore.getStore()); compactingMemStore.getConfiguration(), compactingMemStore.getComparator(), iterator, versionedList.getNumOfCells(), compactingMemStore.getIndexType(), action); iterator.close(); iterator = new MemStoreMergerSegmentsIterator(segments, compactingMemStore.getComparator(), compactionKVMax); compactingMemStore.getConfiguration(), compactingMemStore.getComparator(), iterator, versionedList.getNumOfCells(), segments, compactingMemStore.getIndexType(), action); iterator.close();