org.apache.cassandra.db.commitlog

## Class CommitLogSegment

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

Direct Known Subclasses:
  FileDirectSegment, MemoryMappedSegment

    public abstract class CommitLogSegment
    extends java.lang.Object

### Nested Class Summary

Nested Classes
`protected static class` `CommitLogSegment.Allocation` A simple class for tracking information about the portion of a segment that has been allocated to a log write.
`static class` `CommitLogSegment.CDCState`
`static class` `CommitLogSegment.CommitLogSegmentFileComparator`

### Field Summary

Fields
`CommitLogDescriptor` `descriptor`
`static int` `ENTRY_OVERHEAD_SIZE`
`long` `id`
`protected AbstractCommitLogSegmentManager` `manager`

### Method Summary

All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
`protected java.util.Map<java.lang.String,java.lang.String>` `additionalHeaderParameters()` Provide any additional header data that should be stored in the `CommitLogDescriptor`.
`boolean` `contains(CommitLogPosition context)` Check to see if a certain CommitLogPosition is contained by this segment file.
`long` `contentSize()`
`static <K> void` `coverInMap(java.util.concurrent.ConcurrentMap<K,IntegerInterval> map, K key, int value)`
`java.lang.String` `dirtyString()`
`CommitLogSegment.CDCState` `getCDCState()`
`CommitLogPosition` `getCurrentCommitLogPosition()`
`java.util.Collection<java.util.UUID>` `getDirtyCFIDs()`
`java.lang.String` `getName()`
`java.lang.String` `getPath()`
`protected void` `internalClose()` Close the segment file.
`boolean` `isStillAllocating()`
`boolean` `isUnused()`
`void` `markClean(java.util.UUID cfId, CommitLogPosition startPosition, CommitLogPosition endPosition)` Marks the ColumnFamily specified by cfId as clean for this log segment.
`abstract long` `onDiskSize()`
`void` `setCDCState(CommitLogSegment.CDCState newState)` Change the current cdcState on this CommitLogSegment.
`java.lang.String` `toString()`
`protected static void` `writeSyncMarker(long id, java.nio.ByteBuffer buffer, int offset, int filePos, int nextMarker)` Create a sync marker to delineate sections of the commit log, typically created on each sync of the file.

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

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

### Field Detail

#### ENTRY_OVERHEAD_SIZE

    public static final int ENTRY_OVERHEAD_SIZE

See Also:
  Constant Field Values

#### id

    public final long id

#### manager

    protected final AbstractCommitLogSegmentManager manager

#### descriptor

    public final CommitLogDescriptor descriptor

### Method Detail

#### additionalHeaderParameters

    protected java.util.Map<java.lang.String,java.lang.String> additionalHeaderParameters()

Provide any additional header data that should be stored in the `CommitLogDescriptor`.

#### writeSyncMarker

    protected static void writeSyncMarker(long id,
                                          java.nio.ByteBuffer buffer,
                                          int offset,
                                          int filePos,
                                          int nextMarker)

Create a sync marker to delineate sections of the commit log, typically created on each sync of the file. The sync marker consists of a file pointer to where the next sync marker should be (effectively declaring the length of this section), as well as a CRC value.

Parameters:
  `buffer` - buffer in which to write out the sync marker.
  `offset` - Offset into the `buffer` at which to write the sync marker.
  `filePos` - The current position in the target file where the sync marker will be written (most likely different from the buffer position).
  `nextMarker` - The file position of where the next sync marker should be.

#### isStillAllocating

    public boolean isStillAllocating()

#### getCurrentCommitLogPosition

    public CommitLogPosition getCurrentCommitLogPosition()

Returns:
  the current CommitLogPosition 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

#### internalClose

    protected void internalClose()

Close the segment file. Do not call from outside this class, use syncAndClose() instead.

#### coverInMap

    public static <K> void coverInMap(java.util.concurrent.ConcurrentMap<K,IntegerInterval> map,
                                      K key,
                                      int value)

#### markClean

    public void markClean(java.util.UUID cfId,
                          CommitLogPosition startPosition,
                          CommitLogPosition endPosition)

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
  `startPosition` - the start of the range that is clean
  `endPosition` - the end of the range that is clean

#### 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(CommitLogPosition context)

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

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

#### dirtyString

    public java.lang.String dirtyString()

#### onDiskSize

    public abstract long onDiskSize()

#### contentSize

    public long contentSize()

#### toString

    public java.lang.String toString()

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

#### getCDCState

    public CommitLogSegment.CDCState getCDCState()

#### setCDCState

    public void setCDCState(CommitLogSegment.CDCState newState)

Change the current cdcState on this CommitLogSegment. There are some restrictions on state transitions and this method is idempotent.