Class CommitLogSegment
- java.lang.Object
-
- org.apache.cassandra.db.commitlog.CommitLogSegment
-
- Direct Known Subclasses:
DirectIOSegment
,FileDirectSegment
,MemoryMappedSegment
public abstract class CommitLogSegment extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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.protected static class
CommitLogSegment.Builder
static class
CommitLogSegment.CDCState
static class
CommitLogSegment.CommitLogSegmentFileComparator
-
Field Summary
Fields Modifier and Type Field Description CommitLogDescriptor
descriptor
static int
ENTRY_OVERHEAD_SIZE
long
id
protected AbstractCommitLogSegmentManager
manager
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<java.lang.String,java.lang.String>
additionalHeaderParameters()
Provide any additional header data that should be stored in theCommitLogDescriptor
.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)
protected java.nio.ByteBuffer
createBuffer()
java.lang.String
dirtyString()
File
getCDCFile()
File
getCDCIndexFile()
CommitLogSegment.CDCState
getCDCState()
CommitLogPosition
getCurrentCommitLogPosition()
java.util.Collection<TableId>
getDirtyTableIds()
java.lang.String
getName()
java.lang.String
getPath()
protected void
internalClose()
Close the segment file.boolean
isStillAllocating()
boolean
isUnused()
void
markClean(TableId tableId, CommitLogPosition startPosition, CommitLogPosition endPosition)
Marks the ColumnFamily specified by id as clean for this log segment.abstract long
onDiskSize()
CommitLogSegment.CDCState
setCDCState(CommitLogSegment.CDCState newState)
Change the current cdcState on this CommitLogSegment.java.lang.String
toString()
static void
writeCDCIndexFile(CommitLogDescriptor desc, int offset, boolean complete)
We persist the offset of the last data synced to disk so clients can parse only durable data if they choose.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.
-
-
-
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 theCommitLogDescriptor
.
-
createBuffer
protected java.nio.ByteBuffer createBuffer()
-
writeCDCIndexFile
public static void writeCDCIndexFile(CommitLogDescriptor desc, int offset, boolean complete)
We persist the offset of the last data synced to disk so clients can parse only durable data if they choose. Data in shared / memory-mapped buffers reflects un-synced data so we need an external sentinel for clients to read to determine actual durable data persisted.
-
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 thebuffer
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
-
getCDCFile
public File getCDCFile()
- Returns:
- a File object representing the CDC directory and this file name for hard-linking
-
getCDCIndexFile
public File getCDCIndexFile()
- Returns:
- a File object representing the CDC Index file holding the offset and completion status 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(TableId tableId, CommitLogPosition startPosition, CommitLogPosition endPosition)
Marks the ColumnFamily specified by id 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:
tableId
- the table that is now cleanstartPosition
- the start of the range that is cleanendPosition
- the end of the range that is clean
-
getDirtyTableIds
public java.util.Collection<TableId> getDirtyTableIds()
- 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 classjava.lang.Object
-
getCDCState
public CommitLogSegment.CDCState getCDCState()
-
setCDCState
public CommitLogSegment.CDCState setCDCState(CommitLogSegment.CDCState newState)
Change the current cdcState on this CommitLogSegment. There are some restrictions on state transitions and this method is idempotent.- Returns:
- the old cdc state
-
-