Switch to a new segment, regardless of how much is left in the current one.

Flushes any dirty CFs for this segment and any older segments, and then recycles
the segments
199115
void forceRecycleAll(Iterable<UUID> droppedCfs)
    {
        List<CommitLogSegment> segmentsToRecycle = new ArrayList<>(activeSegments);
        CommitLogSegment last = segmentsToRecycle.get(segmentsToRecycle.size() - 1);
        advanceAllocatingFrom(last);

        // wait for the commit log modifications
        last.waitForModifications();

        // make sure the writes have materialized inside of the memtables by waiting for all outstanding writes
        // on the relevant keyspaces to complete
        Set<Keyspace> keyspaces = new HashSet<>();
        for (UUID cfId : last.getDirtyCFIDs())
        {
            ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(cfId);
            if (cfs != null)
                keyspaces.add(cfs.keyspace);
        }
        for (Keyspace keyspace : keyspaces)
            keyspace.writeOrder.awaitNewBarrier();

        // flush and wait for all CFs that are dirty in segments up-to and including 'last'
        Future<?> future = flushDataFrom(segmentsToRecycle, true);
        try
        {
            future.get();

            for (CommitLogSegment segment : activeSegments)
                for (UUID cfId : droppedCfs)
                    segment.markClean(cfId, segment.getContext());

            // now recycle segments that are unused, as we may not have triggered a discardCompletedSegments()
            // if the previous active segment was the only one to recycle (since an active segment isn't
            // necessarily dirty, and we only call dCS after a flush).
            for (CommitLogSegment segment : activeSegments)
                if (segment.isUnused())
                    recycleSegment(segment);

            CommitLogSegment first;
            if ((first = activeSegments.peek()) != null && first.id <= last.id)
                logger.error("Failed to force-recycle all segments; at least one segment is still in use with dirty CFs.");
        }
        catch (Throwable t)
        {
            // for now just log the error and return false, indicating that we failed
            logger.error("Failed waiting for a forced recycle of in-use commit log segments", t);
        }
    }
553093
private void ProcessNextStep() {

        switch (iSelectionStep) {

            case SELECT_SOURCE_CATALOG :
            case SELECT_DEST_CATALOG :
                if (CatalogToSelect()) {
                    fMain.show();

                    return;
                }
                break;

            case SELECT_DEST_SCHEMA :
            case SELECT_SOURCE_SCHEMA :
                if (SchemaToSelect()) {
                    fMain.show();

                    return;
                }
                break;

            case SELECT_SOURCE_TABLES :
                if (iTransferMode == TRFM_TRANSFER) {
                    bStart.setLabel("Start Transfer");
                } else if (iTransferMode == TRFM_DUMP) {
                    bStart.setLabel("Start Dump");
                } else if (iTransferMode == TRFM_RESTORE) {
                    bStart.setLabel("Start Restore");
                }

                bStart.invalidate();
                bStart.setEnabled(false);
                lTable.setMultipleMode(false);
                RefreshMainDisplay();
                break;

            default :
                break;
        }
    }
573818
private void transferEntry(long index, Entry entry, Segment compactSegment) {
    compactSegment.append(entry);

    // If the entry was released in the prior segment, mark it as released in the compact segment.
    if (!segment.isLive(index)) {
      compactSegment.release(index);
    }
  }
1368515
function(segments) {
        var previousSegment = [-1, -1];
        var segmentIndicesToRemove = [];
        var cleanedSegmentArray = [];
        var i, ii;
        for (i = 0, ii = segments.length; i < ii; ++i) {
            if (!(previousSegment[0] <= segments[i][0] &&
                    previousSegment[1] >= segments[i][1])) {
                cleanedSegmentArray.push(segments[i]);
            }
            previousSegment = segments[i];
        }

        segments.length = 0;
        for (i = 0, ii = cleanedSegmentArray.length; i < ii; ++i) {
            segments.push(cleanedSegmentArray[i]);
        }
    }
1100056
private void discardSegment(final CommitLogSegment segment, final boolean deleteFile)
    {
        logger.debug("Segment {} is no longer active and will be deleted {}", segment, deleteFile ? "now" : "by the archive script");
        size.addAndGet(-DatabaseDescriptor.getCommitLogSegmentSize());

        segmentManagementTasks.add(new Callable<CommitLogSegment>()
        {
            public CommitLogSegment call()
            {
                segment.close();
                if (deleteFile)
                    segment.delete();
                return null;
            }
        });
    }
1221947
def swap(self, old_chunks, new_chunk):
    
    indexes = [self.index(chunk) for chunk in old_chunks]
    del self[indexes[0]:indexes[-1] + 1]
    self.insert(indexes[0], new_chunk)
843867
public void flush() throws IOException {
        checkForClosed();
        writeBufferToFile();
        if (_currentOffset > _offset) { // something to commit
            _nfsFile.commit(_offset, (int) (_currentOffset - _offset));
            _offset = _currentOffset;
        }
        super.flush();
    }
1093610
def flush(now)
      if now || @entries.length > WATERMARK
        @entries.each do |e|
          if e.modified
            e.obj.save
            e.modified = false
          end
        end

        # Delete all but the first WATERMARK entry.
        @entries = @entries[0..WATERMARK - 1] if @entries.length > WATERMARK
      end
    end
540590
function(segment) {

            var previousSegment = segment.previousSegment; // may be null
            while (segment && !segment.isSubpathStart) {

                // assign previous segment's subpath start segment to this segment
                if (previousSegment) segment.subpathStartSegment = previousSegment.subpathStartSegment; // may be null
                else segment.subpathStartSegment = null; // if segment had no previous segment, assign null - creates an invalid path!

                previousSegment = segment;
                segment = segment.nextSegment; // move on to the segment after etc.
            }
        }
317662
private void moveToNextPartition() {
    if (this.currentPartitionIdx == INITIAL_PARTITION_IDX) {
      LOG.info("Pulling topic " + this.topicName);
      this.currentPartitionIdx = 0;
    } else {
      updateStatisticsForCurrentPartition();
      this.currentPartitionIdx++;
      this.currentPartitionRecordCount = 0;
      this.currentPartitionTotalSize = 0;
      this.currentPartitionDecodeRecordTime = 0;
      this.currentPartitionFetchMessageBufferTime = 0;
      this.currentPartitionReadRecordTime = 0;
      this.currentPartitionLastSuccessfulRecord = null;
    }

    this.messageIterator = null;
    if (this.currentPartitionIdx < this.partitions.size()) {
      LOG.info(String.format("Pulling partition %s from offset %d to %d, range=%d", this.getCurrentPartition(),
          this.nextWatermark.get(this.currentPartitionIdx), this.highWatermark.get(this.currentPartitionIdx),
          this.highWatermark.get(this.currentPartitionIdx) - this.nextWatermark.get(this.currentPartitionIdx)));
      switchMetricContextToCurrentPartition();
    }

    if (!allPartitionsFinished()) {
      this.startFetchEpochTime.put(this.getCurrentPartition(), System.currentTimeMillis());
    }
  }
228725
def start(self, segment):
        """"""

        if self.closed:
            raise UserCritical(msg='attempt to transfer wal after closing',
                               hint='report a bug')

        g = gevent.Greenlet(self.transferer, segment)
        g.link(self._complete_execution)
        self.greenlets.add(g)

        # Increment .expect before starting the greenlet, or else a
        # very unlucky .join could be fooled as to when pool is
        # complete.
        self.expect += 1

        g.start()
225036
def reset(self):
        
        super(MorseSmaleComplex, self).reset()

        self.base_partitions = {}
        self.merge_sequence = {}

        self.persistences = []
        self.min_indices = []
        self.max_indices = []

        # State properties
        self.persistence = 0.
541301
def _flush(self):
        
        # Upload segment with workers
        name = self._segment_name % self._seek
        response = self._workers.submit(
            self._client.put_object, self._container, name,
            self._get_buffer())

        # Save segment information in manifest
        self._write_futures.append(dict(
            etag=response, path='/'.join((self._container, name))))
704302
public void recycle() {
        size = 0;
        position = 0;
        // clear data so it won't leak.
        fill(buffer, 0, buffer.length, (byte) 0);

        synchronized (pool) {
            // If the pool is already full, cycle back in new parcels to enable
            // refreshing memory.
            if (pool.size() == kMaxPoolSize) {
                pool.poll();
            }
            pool.offer(this);
        }
    }
144123
def reset_segments(segmentA=nil, segmentB=nil)
      if !segmentA
        @segments = [:days, :hours, :minutes, :seconds]
      elsif !segmentB
        case segmentA
        when Array
          @segments = segmentA.map{ |p| (p.to_s.downcase.chomp('s') + 's').to_sym }
          raise ArgumentError unless @segments.all?{ |s| SEGMENTS.include?(s) }
        else
          f = SEGMENTS.index(segmentA)
          @segments = SEGMENTS[f..0]
        end
      else # segmentA && segmentB
        f = SEGMENTS.index(segmentA)
        t = SEGMENTS.index(segmentB)
        @segments = SEGMENTS[f..t]
      end
    end
996595
public function optimize()
    {
        // Commit changes if any changes have been made
        $this->commit();

        if (count($this->_segmentInfos) > 1 || $this->hasDeletions()) {
            $this->_getIndexWriter()->optimize();
            $this->_updateDocCount();
        }
    }
1150983
protected synchronized void switchEntry(boolean blocking) throws IOException {
    /**
     * Must create compaction redo before update redo to prevent data loss.
     * 
     * The "applyEntries" method will internally sort compaction redo and update redo
     * entries using stable Arrays.sort. The following order of creating redo entries
     * will ensure that compaction redo does NOT overwrite update redo.
     */
    if (!_entryCompaction.isEmpty()) {
      // Create entry log and persist in-memory data
      File file = new File(getDirectory(), getEntryLogName(_entryCompaction));
      _entryCompaction.save(file);
      _entryPool.addToServiceQueue(_entryCompaction);
      _entryCompaction = _entryPool.next();
    }
    
    if (!_entry.isEmpty()) {
      if(_persistListener != null) {
        _persistListener.beforePersist(_entry);
      }
      
      // Create entry log and persist in-memory data
      File file = new File(getDirectory(), getEntryLogName(_entry));
      _entry.save(file);
      
      if(_persistListener != null) {
        _persistListener.afterPersist(_entry);
      }
      
      // Advance low water mark to maintain progress record
      _lwmScn = Math.max(_lwmScn, _entry.getMaxScn());
      _entryPool.addToServiceQueue(_entry);
      _entry = _entryPool.next();
    }
    
    // Apply entry logs to array file
    if (_autoApplyEntries) {
      if (_entryPool.getServiceQueueSize() >= _maxEntries) {
        applyEntries(blocking);
      }
    }
  }