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 ClassesModifier and TypeClassDescriptionstatic class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Option for tables that should append to existing data.static final int
Option for utilities that take care of preparing the writable location before constructing an appendable table.static final int
Option for tables that should write through to concurrently-readable data stores.static final int
Option for tables that should truncate existing data and not write through to concurrently-readable data stores. -
Constructor Summary
ConstructorsConstructorDescriptionLocalAppendableTable
(TableDefinition inputDefinition, WritableLocalTableLocation location, int options, StringCacheProvider stringCacheProvider) Construct a LocalAppendableTable for the supplied definition, location, options, and string caching. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Abort the current pending transaction.void
close()
Flush all appended data to the underlying store, release any resources held, and force all appended data to be persisted to permanent storage.void
Finish the current pending transaction.void
flush()
Write all appended data to the underlying store and prepare for subsequent writes.void
force()
Force all flushed data to be persisted to permanent storage.Get a column for this table by name.Get a map of all of theAppendableTable
s by name.Get an array of all of theAppendableTable
s for this table.Get theTableLocation
for this appendable table.boolean
boolean
Perform aBufferedAppendable.force()
if there is data pending persistence.void
Optional operation.static long
prepareLocation
(WritableLocalTableLocation location, TableDefinition definition, boolean append, boolean writeThrough) Prepare the location and its checkpoint record for writing.void
release()
Release any resources held.void
setDataIndexes
(List<String[]> dataIndexes) Set the list of data indices for this location.void
setImportDetails
(Properties importDetails) Set a trivial import state object wrapping the supplied import details to be part of checkpoints for the output table location.void
setImportState
(ImportState importState) Set an import state object to be part of checkpoints for the output table location, and invoke the appropriateImportState.onResume(FullTableLocationKey)
.void
setSortedColumns
(List<SortPair> sortedColumns) Set the ordered list of sorted columns for this location.long
size()
void
Begin a new transaction.void
updateImportState
(UnaryOperator<ImportState> updater) Set the import state object (as insetImportState(ImportState)
) after applying the supplied updater function to the existing import state object.void
updateSize
(long size) Set the size of this appendable table in rows.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.illumon.iris.db.tables.appendable.AppendableTable
addRecords
-
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:
-
OPTION_APPEND
public static final int OPTION_APPENDOption for tables that should append to existing data.- See Also:
-
OPTION_WRITE_THROUGH
public static final int OPTION_WRITE_THROUGHOption for tables that should write through to concurrently-readable data stores.- See Also:
-
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:
-
-
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
- TheWritableLocalTableLocation
definition
- TheTableDefinition
append
- Whether this utility will specifyOPTION_APPEND
writeThrough
- Whether this utility will specifyOPTION_WRITE_THROUGH
- Returns:
- The visible size of the location after preparation.
-
getDefinition
- Specified by:
getDefinition
in interfaceAppendableTable<LocalAppendableColumn>
-
getColumns
Description copied from interface:AppendableTable
Get an array of all of theAppendableTable
s for this table.- Specified by:
getColumns
in interfaceAppendableTable<LocalAppendableColumn>
- Returns:
- an array of
AppendableTable
-
getColumn
Description copied from interface:AppendableTable
Get a column for this table by name.- Specified by:
getColumn
in interfaceAppendableTable<LocalAppendableColumn>
- Parameters:
columnName
- The column name- Returns:
- The desired column
-
getColumnMap
Description copied from interface:AppendableTable
Get a map of all of theAppendableTable
s by name.- Specified by:
getColumnMap
in interfaceAppendableTable<LocalAppendableColumn>
- Returns:
- a map of column name to column
-
size
public long size()- Specified by:
size
in interfaceAppendableTable<LocalAppendableColumn>
- Returns:
- The size of this appendable table in rows
-
updateSize
public void updateSize(long size) Description copied from interface:AppendableTable
Set 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:
updateSize
in interfaceAppendableTable<LocalAppendableColumn>
- Parameters:
size
- The new size
-
setSortedColumns
Description copied from interface:AppendableTable
Set the ordered list of sorted columns for this location.- Specified by:
setSortedColumns
in interfaceAppendableTable<LocalAppendableColumn>
- Parameters:
sortedColumns
- the ordered list of sorted columns
-
setDataIndexes
Description copied from interface:AppendableTable
Set the list of data indices for this location.- Specified by:
setDataIndexes
in 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:
inTransaction
in interfaceTableTransactionProcessor
- Returns:
- True if this processor is currently in a transaction, else false
-
startTransaction
public void startTransaction()Description copied from interface:TableTransactionProcessor
Begin a new transaction. Causes any existing pending transaction to be aborted.- Specified by:
startTransaction
in interfaceTableTransactionProcessor
-
abortTransaction
public void abortTransaction()Description copied from interface:TableTransactionProcessor
Abort the current pending transaction.
This should not be called if there is no current transaction.
- Specified by:
abortTransaction
in interfaceTableTransactionProcessor
-
finishTransaction
public void finishTransaction()Description copied from interface:TableTransactionProcessor
Finish 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:
finishTransaction
in interfaceTableTransactionProcessor
-
flush
public void flush()Description copied from interface:BufferedAppendable
Write all appended data to the underlying store and prepare for subsequent writes. Does not implyBufferedAppendable.force()
.- Specified by:
flush
in interfaceAppendableTable<LocalAppendableColumn>
- Specified by:
flush
in 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:
prepareCheckpoint
in interfaceBufferedAppendable
-
force
public void force()Description copied from interface:BufferedAppendable
Force 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:
force
in interfaceBufferedAppendable
-
maybeForce
public boolean maybeForce()Description copied from interface:BufferedAppendable
Perform 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:
maybeForce
in 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:BufferedAppendable
Flush 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:
close
in interfaceAppendableTable<LocalAppendableColumn>
- Specified by:
close
in interfaceBufferedAppendable
-
release
public void release()Description copied from interface:BufferedAppendable
Release 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:
release
in interfaceBufferedAppendable
-
getTableLocation
Get theTableLocation
for this appendable table.- Returns:
-