Class CheckpointRecord
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable
,TableLocationState
public class CheckpointRecord extends TableLocationStateHolder implements com.fishlib.base.log.LogOutputAppendable
Checkpoint record to group information for a table writer to safely resume after a process or system crash. Concurrent accesses should be externally synchronized.
Currently stores:
- The table location's state (see
TableLocationState
) - The corresponding size (in bytes) of the data region of all data files, e.g. column .dat, .sym, .bytes, and .sym.bytes files
- Current source file name and position (optional)
- Import state (optional)
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CheckpointRecord.DataFileSizeRecord
Marker interface for data file size records.static class
CheckpointRecord.Flag
Enumeration of flags that can be set on a checkpoint record.static class
CheckpointRecord.SimpleFileSizeRecord
Simple, immutable FileSizeRecord implementation.static interface
CheckpointRecord.SourceFileSizeRecord
Marker interface for source file size records. -
Field Summary
Fields Modifier and Type Field Description static int
COLUMN_FORMAT_1_HEADERS
Version 1 columns contain a 128KB header on .dat and .sym files, and stored grouping as serialized hashmaps in the metadata of .dat files.static int
COLUMN_FORMAT_2_HEADERLESS
Version 2 eliminates the column file headers and stores groupings as adjacent tables per columnstatic int
CURRENT_COLUMN_FORMAT
The current column format version for newly written tablesstatic int
CURRENT_VERSION
The current version that will be output.static ByteOrder
NEW_COLUMN_BYTE_ORDER
static int
NULL_VERSION
Null version number/static int
VERSION_0_TABLE_LOCATION_SIZE_ONLY
Version "0" only had an int table location size, and no other metadata.static int
VERSION_1_ATOMIC_STATE
Version "1" has modification time, data file sizes, source file state, and import state, all updated atomically.static int
VERSION_2_NULL_SIZE_ON_TRUNCATE
Version "2" uses a null size when truncating a location via data-driven command.static int
VERSION_3_TRUNCATE_MARKER
Version "3" adds a "truncated location" marker.static int
VERSION_4_GROUPING_TABLES
Version "4" eliminates the 128k header bytes in column files and writes Grouping / Indexes as tables adjacent to the historical tables.static int
VERSION_5_DATA_INDEX
Version "5" adds the concept of a Data Index, which can be thought of as traditional database indexes.Fields inherited from interface com.illumon.iris.db.v2.locations.TableLocationState
NULL_SIZE, NULL_TIME, REMOVE_SIZE
-
Constructor Summary
Constructors Constructor Description CheckpointRecord()
Construct a new, cleared checkpoint record. -
Method Summary
Modifier and Type Method Description com.fishlib.base.log.LogOutput
append(com.fishlib.base.log.LogOutput logOutput)
void
clear()
Clear the checkpoint record, forgetting any externally set/put data providers.void
clearFlags()
Clear all flags on this checkpoint record.ByteOrder
getByteOrder()
Get the byte order of the data stored in this location.int
getColumnVersion()
Get the column version for the table at this location.CheckpointRecord.DataFileSizeRecord
getDataFileSizeRecord(String name)
Get the file size record for a given file name, or null if not put or read since the checkpoint record was last cleared.List<String[]>
getDataIndexes()
EnumSet<CheckpointRecord.Flag>
getFlags()
return the flags set on this checkpoint record as a set.Properties
getImportDetails()
Get the import details derived from the import state, or null if the import state is null.ImportState
getImportState()
Get the import state, or null if not set or read since the checkpoint record was last cleared.List<SortPair>
getSortedColumns()
Get the ordered list of sorted columns for this location.CheckpointRecord.SourceFileSizeRecord
getSourceFileSizeRecord()
Get the file size record for the source file, or null if not set or read since the checkpoint record was last cleared.TableLocationState
getTableLocationState()
Get the table location state, or null if not set or read since the checkpoint record was last cleared.int
getVersion()
Get the version this checkpoint record was written with, orNULL_VERSION
if not or read since the checkpoint record was last cleared.boolean
hasColumnData()
Test whether this record contains any column data.boolean
hasCurrentVersion()
Determine whether the version this checkpoint record was written is the current version.boolean
hasNullVersion()
Determine whether this checkpoint record has a null version.static void
main(String... args)
Main - print the specified checkpoint record files to standard out.void
putDataFileSizeRecord(CheckpointRecord.DataFileSizeRecord dataFileSizeRecord)
Put a file size record.void
readRecordForConcurrentConsumers(DataInputStream in)
Read all fields of interest to concurrent consumer applications into this record from a DataInputStream.void
readRecordForImporters(DataInputStream in)
Read all fields of interest to importers (i.e.void
readRecordForSerialConsumers(DataInputStream in)
Read all fields of interest to serial consumer applications (i.e.void
setByteOrder(ByteOrder order)
Set the byte order for data that will be stored in this location.void
setColumnVersion(int columnVersion)
Set the column version.void
setDataIndexes(List<String[]> dataIndexes)
void
setFlags(EnumSet<CheckpointRecord.Flag> flags)
Set the flags on this checkpoint record.void
setImportState(ImportState importState)
Set the import state.void
setSortedColumns(List<SortPair> sortedColumns)
Set the sorted columns for this table location.void
setSourceFileSizeRecord(CheckpointRecord.SourceFileSizeRecord sourceFileSizeRecord)
Set the source file size record.void
setTableLocationState(TableLocationState tableLocationState)
Set the table location state.String
toString()
void
writeRecord(DataOutputStream out)
Write all fields out from this record to a DataOutputStream.Methods inherited from class com.illumon.iris.db.v2.locations.TableLocationStateHolder
clearValues, getLastModifiedTimeMillis, getSize, getStateLock, readValuesFrom, setValues
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.illumon.iris.db.v2.locations.TableLocationState
copyStateValuesTo, getSizeStr, writeStateValuesTo
-
Field Details
-
NEW_COLUMN_BYTE_ORDER
-
NULL_VERSION
public static final int NULL_VERSIONNull version number/- See Also:
- Constant Field Values
-
VERSION_0_TABLE_LOCATION_SIZE_ONLY
public static final int VERSION_0_TABLE_LOCATION_SIZE_ONLYVersion "0" only had an int table location size, and no other metadata.- See Also:
- Constant Field Values
-
VERSION_1_ATOMIC_STATE
public static final int VERSION_1_ATOMIC_STATEVersion "1" has modification time, data file sizes, source file state, and import state, all updated atomically.- See Also:
- Constant Field Values
-
VERSION_2_NULL_SIZE_ON_TRUNCATE
public static final int VERSION_2_NULL_SIZE_ON_TRUNCATEVersion "2" uses a null size when truncating a location via data-driven command.- See Also:
- Constant Field Values
-
VERSION_3_TRUNCATE_MARKER
public static final int VERSION_3_TRUNCATE_MARKERVersion "3" adds a "truncated location" marker.- See Also:
- Constant Field Values
-
VERSION_4_GROUPING_TABLES
public static final int VERSION_4_GROUPING_TABLESVersion "4" eliminates the 128k header bytes in column files and writes Grouping / Indexes as tables adjacent to the historical tables.- See Also:
- Constant Field Values
-
VERSION_5_DATA_INDEX
public static final int VERSION_5_DATA_INDEXVersion "5" adds the concept of a Data Index, which can be thought of as traditional database indexes. Unlike Groupings they are not necessarily contiguous.- See Also:
- Constant Field Values
-
CURRENT_VERSION
public static final int CURRENT_VERSIONThe current version that will be output.- See Also:
- Constant Field Values
-
COLUMN_FORMAT_1_HEADERS
public static final int COLUMN_FORMAT_1_HEADERSVersion 1 columns contain a 128KB header on .dat and .sym files, and stored grouping as serialized hashmaps in the metadata of .dat files.- See Also:
- Constant Field Values
-
COLUMN_FORMAT_2_HEADERLESS
public static final int COLUMN_FORMAT_2_HEADERLESSVersion 2 eliminates the column file headers and stores groupings as adjacent tables per column- See Also:
- Constant Field Values
-
CURRENT_COLUMN_FORMAT
public static final int CURRENT_COLUMN_FORMATThe current column format version for newly written tables- See Also:
- Constant Field Values
-
-
Constructor Details
-
CheckpointRecord
public CheckpointRecord()Construct a new, cleared checkpoint record.
-
-
Method Details
-
getVersion
public int getVersion()Get the version this checkpoint record was written with, orNULL_VERSION
if not or read since the checkpoint record was last cleared.- Returns:
- The version
-
hasCurrentVersion
public boolean hasCurrentVersion()Determine whether the version this checkpoint record was written is the current version. Non-current records may require updating before data can be read or appended to.
Should only be called on a record that was just re-read from persistent storage.
- Returns:
- Whether this record was written with the current version
-
hasNullVersion
public boolean hasNullVersion()Determine whether this checkpoint record has a null version. Records with a null version are generally empty and should be treated as non-existent for purposes of appending or reading.
Should only be called on a record that was just re-read from persistent storage.
- Returns:
- Whether this record has the null version
-
getFlags
return the flags set on this checkpoint record as a set.- Returns:
- the set of flags set.
-
setFlags
Set the flags on this checkpoint record. The new set replaces any existing flags. -
clearFlags
public void clearFlags()Clear all flags on this checkpoint record. -
getTableLocationState
Get the table location state, or null if not set or read since the checkpoint record was last cleared.- Returns:
- The table location state
-
setTableLocationState
Set the table location state.- Parameters:
tableLocationState
- The table location state
-
getDataFileSizeRecord
Get the file size record for a given file name, or null if not put or read since the checkpoint record was last cleared.- Parameters:
name
- The file name- Returns:
- The data file size record
-
putDataFileSizeRecord
Put a file size record.- Parameters:
dataFileSizeRecord
- The data file size record
-
hasColumnData
public boolean hasColumnData()Test whether this record contains any column data.- Returns:
- True if this record contains any column data, i.e. if it has at least one column data file with non-zero size
-
getSourceFileSizeRecord
Get the file size record for the source file, or null if not set or read since the checkpoint record was last cleared.- Returns:
- The source file size record
-
setSourceFileSizeRecord
public void setSourceFileSizeRecord(@NotNull CheckpointRecord.SourceFileSizeRecord sourceFileSizeRecord)Set the source file size record.- Parameters:
sourceFileSizeRecord
- The source file size record
-
getImportState
Get the import state, or null if not set or read since the checkpoint record was last cleared.- Returns:
- The import state
-
setImportState
Set the import state.- Parameters:
importState
- The import state
-
getImportDetails
Get the import details derived from the import state, or null if the import state is null.- Returns:
- The import details
-
getByteOrder
Get the byte order of the data stored in this location.- Returns:
- the byte order
-
setByteOrder
Set the byte order for data that will be stored in this location.- Parameters:
order
- the new byte order
-
getColumnVersion
public int getColumnVersion()Get the column version for the table at this location.- Returns:
- the column format version for this location
-
setColumnVersion
public void setColumnVersion(int columnVersion)Set the column version.- Parameters:
columnVersion
- the column version
-
setSortedColumns
Set the sorted columns for this table location. The input is copied internally and is expected to be in the same order in which the columns are sorted.- Parameters:
sortedColumns
- the set of sorted columns
-
getSortedColumns
Get the ordered list of sorted columns for this location.- Returns:
- an unmodifiable list of the sorted columns.
-
setDataIndexes
-
getDataIndexes
-
clear
public void clear()Clear the checkpoint record, forgetting any externally set/put data providers. -
append
public com.fishlib.base.log.LogOutput append(@NotNull com.fishlib.base.log.LogOutput logOutput)- Specified by:
append
in interfacecom.fishlib.base.log.LogOutputAppendable
-
toString
-
writeRecord
Write all fields out from this record to a DataOutputStream. This is only called by importer applications.- Parameters:
out
- The output stream- Throws:
IOException
-
readRecordForSerialConsumers
Read all fields of interest to serial consumer applications (i.e. those that don't concurrently import data) into this record from a DataInputStream.
It's expected that this will be called on a
clear()
ed record.- Parameters:
in
- The input stream- Throws:
IOException
-
readRecordForConcurrentConsumers
Read all fields of interest to concurrent consumer applications into this record from a DataInputStream.
It's expected that this will be called on a
clear()
ed record.- Parameters:
in
- The input stream- Throws:
IOException
-
readRecordForImporters
public void readRecordForImporters(@NotNull DataInputStream in) throws IOException, ClassNotFoundExceptionRead all fields of interest to importers (i.e. all fields) into this record from a DataInputStream.
It's expected that this will be called on a
clear()
ed record.- Parameters:
in
- The input stream- Throws:
IOException
ClassNotFoundException
-
main
Main - print the specified checkpoint record files to standard out.- Parameters:
args
- Array of checkpoint record directories or file names
-