Class V1MasterTableDataSource
- java.lang.Object
-
- com.mckoi.database.MasterTableDataSource
-
- com.mckoi.database.V1MasterTableDataSource
-
public final class V1MasterTableDataSource extends MasterTableDataSource
A MasterTableDataSource that uses IndexStore and VariableSizeDataStore as its backing mechanism for representing the table structure in a file on disk.The MasterTableDataSource is basically backed by a VariableSizeDataStore for data and an IndexStore for storing indexing information.
-
-
Field Summary
Fields Modifier and Type Field Description private CellInputStreamcell_inThe persistent object we use to read information from a row stream.private DataCellSerializationdata_cell_serializerThe object we use to serialize TObject objects.private VariableSizeDataStoredata_storeA VariableSizeDataStore object that physically contains the information stored in the file system in the contents of the data source.private java.lang.Stringfile_nameThe file name of this store in the conglomerate path.private IndexStoreindex_storeAn IndexStore object that manages the indexes for this table.private intOPT_last_colprivate intOPT_last_rowSome variables that are used for optimization in the 'getCellContents' method.private intOPT_last_skip_offsetprivate shorts_run_file_hitsprivate shorts_run_total_hits-
Fields inherited from class com.mckoi.database.MasterTableDataSource
blob_store_interface, cache, column_count, column_rid_list, DATA_CELL_CACHING, delete_hits_key, file_hits_key, garbage_collector, index_def, insert_hits_key, is_closed, root_lock_key, table_def, table_id, table_indices, total_hits_key
-
-
Constructor Summary
Constructors Constructor Description V1MasterTableDataSource(TransactionSystem system, StoreSystem store_system, OpenTransactionList open_transactions)The Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckAndRepair(java.lang.String file_name, UserTerminal terminal)Performs a complete check and repair of the table.voidcheckForCleanup()Checks to determine if it is safe to clean up any resources in the table, and if it is safe to do so, the space is reclaimed.(package private) voidclose()Closes this master table in the file system.(package private) voidcommitIndexSet(IndexSet index_set)Commits changes made to an IndexSet returned by the 'createIndexSet' method.(package private) voidcopyTo(java.io.File path)Copies the persistant information in this table data source to the given directory in the file system.(package private) voidcreate(int table_id, DataTableDef table_def, int data_sector_size, int index_sector_size)Physically create this master table in the file system at the given path.(package private) IndexSetcreateIndexSet()Creates and returns an IndexSet object that is used to create indices for this table source.(package private) longcurrentUniqueID()Atomically returns the current 'unique_id' value for this table.(package private) voiddirtyOpen(java.lang.String file_name)Opens this source in the most minimal way.(package private) voiddispose(boolean pending_close)Disposes of all in-memory resources associated with this table and invalidates this object.(package private) booleandrop()Disposes and drops this table.(package private) booleanexists(java.lang.String file_name)Returns true if the master table data source with the given filename exists.(package private) java.lang.StringgetFileName()Returns the name of the file in the conglomerate that represents this store in the file system.(package private) java.io.FilegetPath()Returns the path of where this table is located.(package private) java.lang.StringgetSourceIdent()Returns a string that uniquely identifies this table within the conglomerate context.(package private) intinternalAddRow(RowData data)Adds a new row to this table and returns an index that is used to reference this row by the 'getCellContents' method.(package private) voidinternalDeleteRow(int row_index)Removes the row at the given index so that any resources associated with the row may be immediately available to be recycled.(package private) TObjectinternalGetCellContents(int column, int row)Returns the cell contents of the given cell in the table.(package private) DataTableDefloadDataTableDef()(package private) longnextUniqueID()Atomically returns the next 'unique_id' value from this table.(package private) voidopen(java.lang.String file_name)Opens an existing master table from the file system at the path of the conglomerate this belongs to.(package private) intrawDataSectorSize()Returns the current sector size for this data source.(package private) intrawRecordSize(int row_number)Returns the number of bytes the row takes up in the data file.(package private) intrawRowCount()Returns the raw count or rows in the table, including uncommited, committed and deleted rows.(package private) intreadRecordType(int row_index)Reads the record state for the given record in the table.private voidrebuildAllIndices(java.io.File path, java.lang.String file_name)This may only be called from the 'fix' method.(package private) booleanrecordDeleted(int row_index)Returns true if the record with the given index is deleted from the table.(package private) voidsaveDataTableDef(DataTableDef def)(package private) voidsetUniqueID(long value)Sets the unique id for this store.(package private) voidshutdownHookCleanup()Called by the 'shutdown hook' on the conglomerate.(package private) voidsynchAll()java.lang.StringtoString()For diagnostic.(package private) intwriteRecordType(int row_index, int row_state)Sets the record type for the given record in the table and returns the previous state of the record.-
Methods inherited from class com.mckoi.database.MasterTableDataSource
addRootLock, addRow, buildIndex, buildIndexes, cachedTableName, clearAllRootLocks, commitTransactionChange, createSelectableSchemeForColumn, createSelectableSchemeForIndex, createTableDataSourceAtCommit, createTableDataSourceAtCommit, Debug, doOpeningScan, findAllJournalsSince, getCellContents, getDataIndexSetDef, getDataTableDef, getName, getRawDiagnosticTable, getSchema, getSystem, getTableID, getTableName, hardCheckAndReclaimRow, hardRemoveRow, hasTransactionChangesPending, isClosed, isReadOnly, isRootLocked, isWorthCompacting, loadInternal, makeTableFileName, mergeJournalChanges, minimalTableDataSource, recordTypeInfo, removeRootLock, rollbackTransactionChange, setupDataIndexSetDef, setupDataTableDef, storeSystem, transactionChangeString
-
-
-
-
Field Detail
-
file_name
private java.lang.String file_name
The file name of this store in the conglomerate path.
-
data_store
private VariableSizeDataStore data_store
A VariableSizeDataStore object that physically contains the information stored in the file system in the contents of the data source.
-
index_store
private IndexStore index_store
An IndexStore object that manages the indexes for this table.
-
data_cell_serializer
private final DataCellSerialization data_cell_serializer
The object we use to serialize TObject objects.
-
cell_in
private CellInputStream cell_in
The persistent object we use to read information from a row stream.
-
s_run_total_hits
private short s_run_total_hits
-
s_run_file_hits
private short s_run_file_hits
-
OPT_last_row
private int OPT_last_row
Some variables that are used for optimization in the 'getCellContents' method.
-
OPT_last_col
private int OPT_last_col
-
OPT_last_skip_offset
private int OPT_last_skip_offset
-
-
Constructor Detail
-
V1MasterTableDataSource
public V1MasterTableDataSource(TransactionSystem system, StoreSystem store_system, OpenTransactionList open_transactions)
The Constructor.
-
-
Method Detail
-
getFileName
java.lang.String getFileName()
Returns the name of the file in the conglomerate that represents this store in the file system.
-
getPath
java.io.File getPath()
Returns the path of where this table is located.
-
create
void create(int table_id, DataTableDef table_def, int data_sector_size, int index_sector_size) throws java.io.IOExceptionPhysically create this master table in the file system at the given path. This will initialise the various file objects and result in a new empty master table to store data in.The 'data_sector_size' and 'index_sector_size' are for fine grain performance and size optimization of the data files. The default 'index_sector_size' is 1024.
- Parameters:
data_sector_size- used to configure the size of the sectors in the data files. For tables with small records this number should be low.index_sector_size- used to configure the size of the sectors in the index file. For small tables it is best to keep the index sector size low. Recommend 1024 for normal use, 128 for minimalist use.- Throws:
java.io.IOException
-
exists
boolean exists(java.lang.String file_name) throws java.io.IOExceptionReturns true if the master table data source with the given filename exists.- Throws:
java.io.IOException
-
open
void open(java.lang.String file_name) throws java.io.IOException
Opens an existing master table from the file system at the path of the conglomerate this belongs to. This will set up the internal state of this object with the data read in.- Throws:
java.io.IOException
-
dirtyOpen
void dirtyOpen(java.lang.String file_name) throws java.io.IOExceptionOpens this source in the most minimal way. This should only be used for diagnostics of the data. This will not load the index.- Throws:
java.io.IOException
-
close
void close() throws java.io.IOExceptionCloses this master table in the file system. This frees up all the resources associated with this master table.This method is typically called when the database is shut down.
- Throws:
java.io.IOException
-
rawRecordSize
int rawRecordSize(int row_number) throws java.io.IOExceptionReturns the number of bytes the row takes up in the data file. This is the actual space used. If a cell is compressed then it includes the compressed size, not the uncompressed.- Throws:
java.io.IOException
-
rawDataSectorSize
int rawDataSectorSize() throws java.io.IOExceptionReturns the current sector size for this data source.- Throws:
java.io.IOException
-
rebuildAllIndices
private void rebuildAllIndices(java.io.File path, java.lang.String file_name) throws java.io.IOExceptionThis may only be called from the 'fix' method. It performs a full scan of the records and rebuilds all the index information from the information.This should only be used as a recovery mechanism and may not accurately rebuild in some cases (but should rebuild as best as possible non the less).
- Throws:
java.io.IOException
-
copyTo
void copyTo(java.io.File path) throws java.io.IOExceptionCopies the persistant information in this table data source to the given directory in the file system. This makes an exact copy of the table as it currently is. It is recommended that when this is used, there is a lock to prevent committed changes to the database.- Throws:
java.io.IOException
-
checkAndRepair
public void checkAndRepair(java.lang.String file_name, UserTerminal terminal) throws java.io.IOExceptionPerforms a complete check and repair of the table. The table must not have been opened before this method is called. The given UserTerminal parameter is an implementation of a user interface that is used to ask any questions and output the results of the check.- Throws:
java.io.IOException
-
checkForCleanup
public void checkForCleanup()
Description copied from class:MasterTableDataSourceChecks to determine if it is safe to clean up any resources in the table, and if it is safe to do so, the space is reclaimed.- Specified by:
checkForCleanupin classMasterTableDataSource
-
getSourceIdent
java.lang.String getSourceIdent()
Description copied from class:MasterTableDataSourceReturns a string that uniquely identifies this table within the conglomerate context. For example, the filename of the table. This string can be used to open and initialize the table also.- Specified by:
getSourceIdentin classMasterTableDataSource
-
synchAll
void synchAll() throws java.io.IOException- Throws:
java.io.IOException
-
writeRecordType
int writeRecordType(int row_index, int row_state) throws java.io.IOExceptionDescription copied from class:MasterTableDataSourceSets the record type for the given record in the table and returns the previous state of the record. This is used to change the state of a row in the table.- Specified by:
writeRecordTypein classMasterTableDataSource- Throws:
java.io.IOException
-
readRecordType
int readRecordType(int row_index) throws java.io.IOExceptionDescription copied from class:MasterTableDataSourceReads the record state for the given record in the table.- Specified by:
readRecordTypein classMasterTableDataSource- Throws:
java.io.IOException
-
recordDeleted
boolean recordDeleted(int row_index) throws java.io.IOExceptionDescription copied from class:MasterTableDataSourceReturns true if the record with the given index is deleted from the table. A deleted row can not be read.- Specified by:
recordDeletedin classMasterTableDataSource- Throws:
java.io.IOException
-
rawRowCount
int rawRowCount() throws java.io.IOExceptionDescription copied from class:MasterTableDataSourceReturns the raw count or rows in the table, including uncommited, committed and deleted rows. This is basically the maximum number of rows we can iterate through.- Specified by:
rawRowCountin classMasterTableDataSource- Throws:
java.io.IOException
-
internalDeleteRow
void internalDeleteRow(int row_index) throws java.io.IOExceptionDescription copied from class:MasterTableDataSourceRemoves the row at the given index so that any resources associated with the row may be immediately available to be recycled.- Specified by:
internalDeleteRowin classMasterTableDataSource- Throws:
java.io.IOException
-
createIndexSet
IndexSet createIndexSet()
Description copied from class:MasterTableDataSourceCreates and returns an IndexSet object that is used to create indices for this table source. The IndexSet represents a snapshot of the table and the given point in time.NOTE: Not synchronized because we synchronize in the IndexStore object.
- Specified by:
createIndexSetin classMasterTableDataSource
-
commitIndexSet
void commitIndexSet(IndexSet index_set)
Description copied from class:MasterTableDataSourceCommits changes made to an IndexSet returned by the 'createIndexSet' method. This method also disposes the IndexSet so it is no longer valid.- Specified by:
commitIndexSetin classMasterTableDataSource
-
loadDataTableDef
DataTableDef loadDataTableDef() throws java.io.IOException
- Throws:
java.io.IOException
-
saveDataTableDef
void saveDataTableDef(DataTableDef def) throws java.io.IOException
- Throws:
java.io.IOException
-
internalAddRow
int internalAddRow(RowData data) throws java.io.IOException
Description copied from class:MasterTableDataSourceAdds a new row to this table and returns an index that is used to reference this row by the 'getCellContents' method.Note that this method will not effect the master index or column schemes. This is a low level mechanism for adding unreferenced data into a conglomerate. The data is referenced by committing the change where it eventually migrates into the master index and schemes.
- Specified by:
internalAddRowin classMasterTableDataSource- Throws:
java.io.IOException
-
internalGetCellContents
TObject internalGetCellContents(int column, int row)
Description copied from class:MasterTableDataSourceReturns the cell contents of the given cell in the table. It is the responsibility of the implemented method to perform caching as it deems fit. Some representations may not require such extensive caching as others.- Specified by:
internalGetCellContentsin classMasterTableDataSource
-
currentUniqueID
long currentUniqueID()
Description copied from class:MasterTableDataSourceAtomically returns the current 'unique_id' value for this table.- Specified by:
currentUniqueIDin classMasterTableDataSource
-
nextUniqueID
long nextUniqueID()
Description copied from class:MasterTableDataSourceAtomically returns the next 'unique_id' value from this table.- Specified by:
nextUniqueIDin classMasterTableDataSource
-
setUniqueID
void setUniqueID(long value)
Description copied from class:MasterTableDataSourceSets the unique id for this store. This must only be used under extraordinary circumstances, such as restoring from a backup, or converting from one file to another.- Specified by:
setUniqueIDin classMasterTableDataSource
-
dispose
void dispose(boolean pending_close) throws java.io.IOExceptionDescription copied from class:MasterTableDataSourceDisposes of all in-memory resources associated with this table and invalidates this object. If 'pending_drop' is true then the table is to be disposed pending a call to 'drop'. If 'pending_drop' is true then any persistant resources that are allocated may be freed.- Specified by:
disposein classMasterTableDataSource- Throws:
java.io.IOException
-
drop
boolean drop() throws java.io.IOExceptionDescription copied from class:MasterTableDataSourceDisposes and drops this table. If the dispose failed for any reason, it returns false, otherwise true. If the drop failed, it should be retried at a later time.- Specified by:
dropin classMasterTableDataSource- Throws:
java.io.IOException
-
shutdownHookCleanup
void shutdownHookCleanup()
Description copied from class:MasterTableDataSourceCalled by the 'shutdown hook' on the conglomerate. This method should block until the table can by put into a safe mode and then prevent any further access to the object after it returns. It must operate very quickly.- Specified by:
shutdownHookCleanupin classMasterTableDataSource
-
toString
public java.lang.String toString()
For diagnostic.- Overrides:
toStringin classjava.lang.Object
-
-