org.apache.cassandra.db.commitlog

## Class CommitLogSegment

- java.lang.Object
- - org.apache.cassandra.db.commitlog.CommitLogSegment

    public class CommitLogSegment
    extends java.lang.Object

### Nested Class Summary

Nested Classes
`static class` `CommitLogSegment.CommitLogSegmentFileComparator`

### Field Summary

Fields
`CommitLogDescriptor` `descriptor`
`long` `id`

### Method Summary

Methods
`void` `close()` Close the segment file.
`boolean` `contains(ReplayPosition context)` Check to see if a certain ReplayPosition is contained by this segment file.
`java.lang.String` `dirtyString()`
`void` `discard(boolean deleteFile)` Completely discards a segment file by deleting it.
`static CommitLogSegment` `freshSegment()`
`ReplayPosition` `getContext()`
`java.util.Collection<java.util.UUID>` `getDirtyCFIDs()`
`java.lang.String` `getName()`
`static long` `getNextId()`
`java.lang.String` `getPath()`
`boolean` `hasCapacityFor(long size)`
`boolean` `isUnused()`
`void` `markClean(java.util.UUID cfId, ReplayPosition context)` Marks the ColumnFamily specified by cfId as clean for this log segment.
`int` `position()`
`CommitLogSegment` `recycle()` Recycle processes an unneeded segment file for reuse.
`void` `sync()` Forces a disk flush for this segment file.
`java.lang.String` `toString()`
`ReplayPosition` `write(RowMutation mutation)` Appends a row mutation onto the commit log.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### id

    public final long id

#### descriptor

    public final CommitLogDescriptor descriptor

### Method Detail

#### freshSegment

    public static CommitLogSegment freshSegment()

Returns:
  a newly minted segment file

#### getNextId

    public static long getNextId()

#### discard

    public void discard(boolean deleteFile)

Completely discards a segment file by deleting it. (Potentially blocking operation)

#### recycle

    public CommitLogSegment recycle()

Recycle processes an unneeded segment file for reuse.

Returns:
  a new CommitLogSegment representing the newly reusable segment.

#### hasCapacityFor

    public boolean hasCapacityFor(long size)

Returns:
  true if there is room to write() @param size to this segment

#### write

    public ReplayPosition write(RowMutation mutation)
                         throws java.io.IOException

Appends a row mutation onto the commit log. Requres that hasCapacityFor has already been checked.

Parameters:
  `mutation` - the mutation to append to the commit log.
Returns:
  the position of the appended mutation
Throws:
  `java.io.IOException`

#### sync

    public void sync()

Forces a disk flush for this segment file.

#### getContext

    public ReplayPosition getContext()

Returns:
  the current ReplayPosition for this log segment

#### getPath

    public java.lang.String getPath()

Returns:
  the file path to this segment

#### getName

    public java.lang.String getName()

Returns:
  the file name of this segment

#### close

    public void close()

Close the segment file.

#### markClean

    public void markClean(java.util.UUID cfId,
                 ReplayPosition context)

Marks the ColumnFamily specified by cfId as clean for this log segment. If the given context argument is contained in this file, it will only mark the CF as clean if no newer writes have taken place.

Parameters:
  `cfId` - the column family ID that is now clean
  `context` - the optional clean offset

#### getDirtyCFIDs

    public java.util.Collection<java.util.UUID> getDirtyCFIDs()

Returns:
  a collection of dirty CFIDs for this segment file.

#### isUnused

    public boolean isUnused()

Returns:
  true if this segment is unused and safe to recycle or delete

#### contains

    public boolean contains(ReplayPosition context)

Check to see if a certain ReplayPosition is contained by this segment file.

Parameters:
  `context` - the replay position to be checked
Returns:
  true if the replay position is contained by this segment file.

#### dirtyString

    public java.lang.String dirtyString()

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`

#### position

    public int position()