Class LocalAppendableTable
java.lang.Object
com.illumon.iris.db.tables.appendable.local.LocalAppendableTable
- All Implemented Interfaces:
AppendableTable<LocalAppendableColumn>,BufferedAppendable,BufferedAppendableTable<LocalAppendableColumn>,TableTransactionProcessor
public class LocalAppendableTable extends Object implements BufferedAppendableTable<LocalAppendableColumn>, TableTransactionProcessor
AppendableTable for output to a local table location.
In general only one thread at a time should call any of the methods that change the underlying table.
Acceptable patterns include:
- A single thread appends all rows, occasionally flushing, eventually terminating with close and/or release. Other threads may call call force asynchronously.
- Many threads append to the columns individually, with a central thread eventually closing after all writes are done.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLocalAppendableTable.TableDefinitionMismatchException -
Field Summary
Fields Modifier and Type Field Description static intOPTION_APPENDOption for tables that should append to existing data.static intOPTION_SKIP_PREPARE_LOCATIONOption for utilities that take care of preparing the writable location before constructing an appendable table.static intOPTION_WRITE_THROUGHOption for tables that should write through to concurrently-readable data stores.static intOPTIONS_DEFAULTOption for tables that should truncate existing data and not write through to concurrently-readable data stores. -
Constructor Summary
Constructors Constructor Description LocalAppendableTable(TableDefinition inputDefinition, WritableLocalTableLocation location, int options, StringCacheProvider stringCacheProvider)Construct a LocalAppendableTable for the supplied definition, location, options, and string caching. -
Method Summary
Modifier and Type Method Description voidabortTransaction()Abort the current pending transaction.voidclose()Flush all appended data to the underlying store, release any resources held, and force all appended data to be persisted to permanent storage.voidfinishTransaction()Finish the current pending transaction.voidflush()Write all appended data to the underlying store and prepare for subsequent writes.voidforce()Force all flushed data to be persisted to permanent storage.LocalAppendableColumngetColumn(String columnName)Get a column for this table by name.Map<String,LocalAppendableColumn>getColumnMap()Get a map of all of theAppendableTables by name.LocalAppendableColumn[]getColumns()Get an array of all of theAppendableTables for this table.TableDefinitiongetDefinition()WritableLocalTableLocationgetTableLocation()Get theTableLocationfor this appendable table.booleaninTransaction()booleanmaybeForce()Perform aBufferedAppendable.force()if there is data pending persistence.voidprepareCheckpoint()Optional operation.static longprepareLocation(WritableLocalTableLocation location, TableDefinition definition, boolean append, boolean writeThrough)Prepare the location and its checkpoint record for writing.voidrelease()Release any resources held.voidsetDataIndexes(List<String[]> dataIndexes)Set the list of data indices for this location.voidsetImportDetails(Properties importDetails)Set a trivial import state object wrapping the supplied import details to be part of checkpoints for the output table location.voidsetImportState(ImportState importState)Set an import state object to be part of checkpoints for the output table location, and invoke the appropriateImportState.onResume(FullTableLocationKey).voidsetSortedColumns(List<SortPair> sortedColumns)Set the ordered list of sorted columns for this location.longsize()voidstartTransaction()Begin a new transaction.voidupdateImportState(UnaryOperator<ImportState> updater)Set the import state object (as insetImportState(ImportState)) after applying the supplied updater function to the existing import state object.voidupdateSize(long size)Set the size of this appendable table in rows.
-
Field Details
-
OPTIONS_DEFAULT
public static final int OPTIONS_DEFAULTOption for tables that should truncate existing data and not write through to concurrently-readable data stores.- See Also:
- Constant Field Values
-
OPTION_APPEND
public static final int OPTION_APPENDOption for tables that should append to existing data.- See Also:
- Constant Field Values
-
OPTION_WRITE_THROUGH
public static final int OPTION_WRITE_THROUGHOption for tables that should write through to concurrently-readable data stores.- See Also:
- Constant Field Values
-
OPTION_SKIP_PREPARE_LOCATION
public static final int OPTION_SKIP_PREPARE_LOCATIONOption for utilities that take care of preparing the writable location before constructing an appendable table. Such utilities must callprepareLocation(WritableLocalTableLocation, TableDefinition, boolean, boolean)appropriately.- See Also:
- Constant Field Values
-
-
Constructor Details
-
LocalAppendableTable
public LocalAppendableTable(@NotNull TableDefinition inputDefinition, @NotNull WritableLocalTableLocation location, int options, @NotNull StringCacheProvider stringCacheProvider)Construct a LocalAppendableTable for the supplied definition, location, options, and string caching.
Note that the table name used for persisting a per-location writable table definition will be derived from inputDefinition and location according to
findTableName(TableDefinition, LocalTableLocation).- Parameters:
inputDefinition- The definitionlocation- The destinationoptions- Options bitmapstringCacheProvider- String cache provider to use
-
-
Method Details
-
prepareLocation
public static long prepareLocation(@NotNull WritableLocalTableLocation location, @NotNull TableDefinition definition, boolean append, boolean writeThrough)Prepare the location and its checkpoint record for writing.- Parameters:
location- TheWritableLocalTableLocationdefinition- TheTableDefinitionappend- Whether this utility will specifyOPTION_APPENDwriteThrough- Whether this utility will specifyOPTION_WRITE_THROUGH- Returns:
- The visible size of the location after preparation.
-
getDefinition
- Specified by:
getDefinitionin interfaceAppendableTable<LocalAppendableColumn>
-
getColumns
Description copied from interface:AppendableTableGet an array of all of theAppendableTables for this table.- Specified by:
getColumnsin interfaceAppendableTable<LocalAppendableColumn>- Returns:
- an array of
AppendableTable
-
getColumn
Description copied from interface:AppendableTableGet a column for this table by name.- Specified by:
getColumnin interfaceAppendableTable<LocalAppendableColumn>- Parameters:
columnName- The column name- Returns:
- The desired column
-
getColumnMap
Description copied from interface:AppendableTableGet a map of all of theAppendableTables by name.- Specified by:
getColumnMapin interfaceAppendableTable<LocalAppendableColumn>- Returns:
- a map of column name to column
-
size
public long size()- Specified by:
sizein interfaceAppendableTable<LocalAppendableColumn>- Returns:
- The size of this appendable table in rows
-
updateSize
public void updateSize(long size)Description copied from interface:AppendableTableSet the size of this appendable table in rows. This is for use by utilities that write directly to an AppendableTable's columns, in order to record that a set of rows has been added to all columns and should be available for checkpointing or reading. All columns should be flushed before this call, either externally or via theAppendableTable.flush()method.- Specified by:
updateSizein interfaceAppendableTable<LocalAppendableColumn>- Parameters:
size- The new size
-
setSortedColumns
Description copied from interface:AppendableTableSet the ordered list of sorted columns for this location.- Specified by:
setSortedColumnsin interfaceAppendableTable<LocalAppendableColumn>- Parameters:
sortedColumns- the ordered list of sorted columns
-
setDataIndexes
Description copied from interface:AppendableTableSet the list of data indices for this location.- Specified by:
setDataIndexesin interfaceAppendableTable<LocalAppendableColumn>- Parameters:
dataIndexes- the data indices.
-
updateImportState
Set the import state object (as insetImportState(ImportState)) after applying the supplied updater function to the existing import state object.- Parameters:
updater- The import state updater
-
setImportState
Set an import state object to be part of checkpoints for the output table location, and invoke the appropriateImportState.onResume(FullTableLocationKey).- Parameters:
importState- The import state
-
setImportDetails
Set a trivial import state object wrapping the supplied import details to be part of checkpoints for the output table location.- Parameters:
importDetails- The import details
-
inTransaction
public boolean inTransaction()- Specified by:
inTransactionin interfaceTableTransactionProcessor- Returns:
- True if this processor is currently in a transaction, else false
-
startTransaction
public void startTransaction()Description copied from interface:TableTransactionProcessorBegin a new transaction. Causes any existing pending transaction to be aborted.- Specified by:
startTransactionin interfaceTableTransactionProcessor
-
abortTransaction
public void abortTransaction()Description copied from interface:TableTransactionProcessorAbort the current pending transaction.
This should not be called if there is no current transaction.
- Specified by:
abortTransactionin interfaceTableTransactionProcessor
-
finishTransaction
public void finishTransaction()Description copied from interface:TableTransactionProcessorFinish the current pending transaction.
This makes the rows that were part of the transaction eligible to be made visible and durable, but does not in itself make them visible or durable.
This should not be called if there is no current transaction.
- Specified by:
finishTransactionin interfaceTableTransactionProcessor
-
flush
public void flush()Description copied from interface:BufferedAppendableWrite all appended data to the underlying store and prepare for subsequent writes. Does not implyBufferedAppendable.force().- Specified by:
flushin interfaceAppendableTable<LocalAppendableColumn>- Specified by:
flushin interfaceBufferedAppendable
-
prepareCheckpoint
public void prepareCheckpoint()Optional operation. Prepare a checkpoint snapshot for the next call toBufferedAppendable.force(). Should be called directly afterBufferedAppendable.flush(), with no intervening modification operations. Callers should userelease()in the event that this method throws, rather thanclose().- Specified by:
prepareCheckpointin interfaceBufferedAppendable
-
force
public void force()Description copied from interface:BufferedAppendableForce all flushed data to be persisted to permanent storage. Will consistently and atomically persist the last prepared checkpoint in implementations that implementBufferedAppendable.prepareCheckpoint(). Does not implyBufferedAppendable.flush(), as this is a distinct operation in all implementations. May be called concurrently by threads other than the "writing thread".- Specified by:
forcein interfaceBufferedAppendable
-
maybeForce
public boolean maybeForce()Description copied from interface:BufferedAppendablePerform aBufferedAppendable.force()if there is data pending persistence. Implementations that don't keep track of pending data explicitly will always invokeBufferedAppendable.force()pessimistically.- Specified by:
maybeForcein interfaceBufferedAppendable- Returns:
- Whether this call may have done any actual work (i.e. there was data pending or assumed to be pending)
-
close
public void close()Description copied from interface:BufferedAppendableFlush all appended data to the underlying store, release any resources held, and force all appended data to be persisted to permanent storage. This should be the final access to this appendable (if successful) with the exception of any asynchronousBufferedAppendable.force()operations. ABufferedAppendable.release()is appropriate afterwards, especially on error.- Specified by:
closein interfaceAppendableTable<LocalAppendableColumn>- Specified by:
closein interfaceBufferedAppendable
-
release
public void release()Description copied from interface:BufferedAppendableRelease any resources held. Called after an error in preparation for termination. For external callers, this should be done as the final access to this column with the exception of any asynchronousBufferedAppendable.force()operations.- Specified by:
releasein interfaceBufferedAppendable
-
getTableLocation
Get theTableLocationfor this appendable table.- Returns:
-