Package io.debezium.connector.cassandra
Class FileOffsetWriter
- java.lang.Object
-
- io.debezium.connector.cassandra.FileOffsetWriter
-
- All Implemented Interfaces:
OffsetWriter
public class FileOffsetWriter extends Object implements OffsetWriter
A concrete implementation ofOffsetWriterwhich tracks the progress of events being processed by theSnapshotProcessorandCommitLogProcessorto property files, snapshot_offset.properties and commitlog_offset.properties, respectively. The property key is the table for the offset, and is serialized in the format of. The property value is the offset position, and is serialized in the format of
: . For snapshots, a table is either fully processed or not processed at all, so offset is given a default value of ":-1" , where the filename is an empty string, and file position is -1. For commit logs, the file_name represents the commit log file name and file position represents bytes read in the commit log. -
-
Field Summary
Fields Modifier and Type Field Description static StringCOMMITLOG_OFFSET_FILEprivate FilecommitLogOffsetFileprivate FileLockcommitLogOffsetFileLockprivate PropertiescommitLogPropsprivate static org.slf4j.LoggerLOGGERprivate FileoffsetDirstatic StringSNAPSHOT_OFFSET_FILEprivate FilesnapshotOffsetFileprivate FileLocksnapshotOffsetFileLockprivate PropertiessnapshotProps
-
Constructor Summary
Constructors Constructor Description FileOffsetWriter(String offsetDir)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close all resources used by this class.voidflush()Flush latest offsets to disk.private FileLockinit(File offsetFile)booleanisOffsetProcessed(String sourceTable, String sourceOffset, boolean isSnapshot)Determine if an offset has been processed based on the table name, offset position, and whether it is from snapshot or not.private voidloadOffset(File offsetFile, Properties props)voidmarkOffset(String sourceTable, String sourceOffset, boolean isSnapshot)Update the offset in memory if the provided offset is greater than the existing offset.private static voidsaveOffset(File offsetFile, Properties props)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
SNAPSHOT_OFFSET_FILE
public static final String SNAPSHOT_OFFSET_FILE
- See Also:
- Constant Field Values
-
COMMITLOG_OFFSET_FILE
public static final String COMMITLOG_OFFSET_FILE
- See Also:
- Constant Field Values
-
snapshotProps
private final Properties snapshotProps
-
commitLogProps
private final Properties commitLogProps
-
offsetDir
private final File offsetDir
-
snapshotOffsetFile
private final File snapshotOffsetFile
-
commitLogOffsetFile
private final File commitLogOffsetFile
-
snapshotOffsetFileLock
private final FileLock snapshotOffsetFileLock
-
commitLogOffsetFileLock
private final FileLock commitLogOffsetFileLock
-
-
Constructor Detail
-
FileOffsetWriter
public FileOffsetWriter(String offsetDir) throws IOException
- Throws:
IOException
-
-
Method Detail
-
markOffset
public void markOffset(String sourceTable, String sourceOffset, boolean isSnapshot)
Description copied from interface:OffsetWriterUpdate the offset in memory if the provided offset is greater than the existing offset.- Specified by:
markOffsetin interfaceOffsetWriter- Parameters:
sourceTable- string in the format of. .
sourceOffset- string in the format of: isSnapshot- whether the offset is coming from a snapshot or commit log-
isOffsetProcessed
public boolean isOffsetProcessed(String sourceTable, String sourceOffset, boolean isSnapshot)
Description copied from interface:OffsetWriterDetermine if an offset has been processed based on the table name, offset position, and whether it is from snapshot or not.- Specified by:
isOffsetProcessedin interfaceOffsetWriter- Parameters:
sourceTable- string in the format of. .
sourceOffset- string in the format of: isSnapshot- whether the offset is coming from a snapshot or commit log- Returns:
- true if the offset has been processed, false otherwise.
-
flush
public void flush()
Description copied from interface:OffsetWriterFlush latest offsets to disk.- Specified by:
flushin interfaceOffsetWriter
-
close
public void close()
Description copied from interface:OffsetWriterClose all resources used by this class.- Specified by:
closein interfaceOffsetWriter
-
saveOffset
private static void saveOffset(File offsetFile, Properties props) throws IOException
- Throws:
IOException
-
loadOffset
private void loadOffset(File offsetFile, Properties props) throws IOException
- Throws:
IOException
-
init
private FileLock init(File offsetFile) throws IOException
- Throws:
IOException
-
-