## org.apache.cassandra.db.commitlog
Class CommitLog

    java.lang.Object
      org.apache.cassandra.db.commitlog.CommitLog

All Implemented Interfaces:
  CommitLogMBean

    public class CommitLog

extends java.lang.Object
implements CommitLogMBean

Field Summary
`CommitLogSegment` `activeSegment`
`CommitLogAllocator` `allocator`
`CommitLogArchiver` `archiver`
`static int` `END_OF_SEGMENT_MARKER`
`static int` `END_OF_SEGMENT_MARKER_SIZE`
`static CommitLog` `instance`

Method Summary
`int` `activeSegments()` Used by tests.
`void` `add(RowMutation rm)` Add a RowMutation to the commit log.
`void` `discardCompletedSegments(java.lang.Integer cfId, ReplayPosition context)` Modifies the per-CF dirty cursors of any commit log segments for the column family according to the position given.
`void` `forceNewSegment()` Forces a new segment file to be allocated and activated.
`java.util.List<java.lang.String>` `getActiveSegmentNames()`
`java.util.List<java.lang.String>` `getArchivingSegmentNames()`
`long` `getCompletedTasks()` Get the number of completed tasks
`java.util.concurrent.Future<ReplayPosition>` `getContext()`
`long` `getPendingTasks()` Get the number of tasks waiting to be executed
`long` `getTotalCommitlogSize()` Get the current size used by all the commitlog segments.
`int` `recover()` Perform recovery on commit logs located in the directory specified by the config file.
`int` `recover(java.io.File... clogs)` Perform recovery on a list of commit log files.
`void` `recover(java.lang.String path)` Perform recovery on a single commit log.
`void` `resetUnsafe()` FOR TESTING PURPOSES.
`void` `shutdownBlocking()` Shuts down the threads used by the commit log, blocking until completion.
`void` `sync()` Forces a disk flush on the commit log files that need it.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### instance

    public static final CommitLog instance

### allocator

    public final CommitLogAllocator allocator

### archiver

    public final CommitLogArchiver archiver

### END_OF_SEGMENT_MARKER

    public static final int END_OF_SEGMENT_MARKER

See Also:
  Constant Field Values

### END_OF_SEGMENT_MARKER_SIZE

    public static final int END_OF_SEGMENT_MARKER_SIZE

See Also:
  Constant Field Values

### activeSegment

    public CommitLogSegment activeSegment

Method Detail

### resetUnsafe

    public void resetUnsafe()
                     throws java.io.IOException

  FOR TESTING PURPOSES. See CommitLogAllocator.

  Throws:
    `java.io.IOException`

### recover

    public int recover()
                throws java.io.IOException

  Perform recovery on commit logs located in the directory specified by the config file.

  Returns:
    the number of mutations replayed
  Throws:
    `java.io.IOException`

### recover

    public int recover(java.io.File... clogs)
                throws java.io.IOException

  Perform recovery on a list of commit log files.

  Parameters:
    `clogs` - the list of commit log files to replay
  Returns:
    the number of mutations replayed
  Throws:
    `java.io.IOException`

### recover

    public void recover(java.lang.String path)
                 throws java.io.IOException

  Perform recovery on a single commit log.

  Specified by:
    `recover` in interface `CommitLogMBean`
  Throws:
    `java.io.IOException`

### getContext

    public java.util.concurrent.Future<ReplayPosition> getContext()

  Returns:
    a Future representing a ReplayPosition such that when it is ready, all commitlog tasks enqueued prior to the getContext call will be complete (i.e., appended to the log)

### activeSegments

    public int activeSegments()

  Used by tests.

  Returns:
    the number of active segments (segments with unflushed data in them)

### add

    public void add(RowMutation rm)
             throws java.io.IOException

  Add a RowMutation to the commit log.

  Parameters:
    `rm` - the RowMutation to add to the log
  Throws:
    `java.io.IOException`

### discardCompletedSegments

    public void discardCompletedSegments(java.lang.Integer cfId,
                                         ReplayPosition context)
                                  throws java.io.IOException

  Modifies the per-CF dirty cursors of any commit log segments for the column family according to the position given. Discards any commit log segments that are no longer used.

  Parameters:
    `cfId` - the column family ID that was flushed
    `context` - the replay position of the flush
  Throws:
    `java.io.IOException`

### sync

    public void sync()
              throws java.io.IOException

  Forces a disk flush on the commit log files that need it.

  Throws:
    `java.io.IOException`

### getCompletedTasks

    public long getCompletedTasks()

  Description copied from interface: `CommitLogMBean`
  Get the number of completed tasks

  Specified by:
    `getCompletedTasks` in interface `CommitLogMBean`
  Returns:
    the number of tasks completed by the commit log executor

### getPendingTasks

    public long getPendingTasks()

  Description copied from interface: `CommitLogMBean`
  Get the number of tasks waiting to be executed

  Specified by:
    `getPendingTasks` in interface `CommitLogMBean`
  Returns:
    the depth of pending commit log executor queue

### getTotalCommitlogSize

    public long getTotalCommitlogSize()

  Description copied from interface: `CommitLogMBean`
  Get the current size used by all the commitlog segments.

  Specified by:
    `getTotalCommitlogSize` in interface `CommitLogMBean`
  Returns:
    the total size occupied by commitlo segments expressed in bytes. (used by MBean)

### forceNewSegment

    public void forceNewSegment()
                         throws java.util.concurrent.ExecutionException,
                                java.lang.InterruptedException

  Forces a new segment file to be allocated and activated. Used mainly by truncate.

  Throws:
    `java.util.concurrent.ExecutionException`
    `java.lang.InterruptedException`

### getActiveSegmentNames

    public java.util.List<java.lang.String> getActiveSegmentNames()

  Specified by:
    `getActiveSegmentNames` in interface `CommitLogMBean`
  Returns:
    file names (not full paths) of active commit log segments (segments containing unflushed data)

### getArchivingSegmentNames

    public java.util.List<java.lang.String> getArchivingSegmentNames()

  Specified by:
    `getArchivingSegmentNames` in interface `CommitLogMBean`
  Returns:
    Files which are pending for archival attempt. Does NOT include failed archive attempts.

### shutdownBlocking

    public void shutdownBlocking()
                          throws java.lang.InterruptedException

  Shuts down the threads used by the commit log, blocking until completion.

  Throws:
    `java.lang.InterruptedException`

Copyright © 2013 The Apache Software Foundation