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 CellInputStream
cell_in
The persistent object we use to read information from a row stream.private DataCellSerialization
data_cell_serializer
The object we use to serialize TObject objects.private VariableSizeDataStore
data_store
A VariableSizeDataStore object that physically contains the information stored in the file system in the contents of the data source.private java.lang.String
file_name
The file name of this store in the conglomerate path.private IndexStore
index_store
An IndexStore object that manages the indexes for this table.private int
OPT_last_col
private int
OPT_last_row
Some variables that are used for optimization in the 'getCellContents' method.private int
OPT_last_skip_offset
private short
s_run_file_hits
private short
s_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 void
checkAndRepair(java.lang.String file_name, UserTerminal terminal)
Performs a complete check and repair of the table.void
checkForCleanup()
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) void
close()
Closes this master table in the file system.(package private) void
commitIndexSet(IndexSet index_set)
Commits changes made to an IndexSet returned by the 'createIndexSet' method.(package private) void
copyTo(java.io.File path)
Copies the persistant information in this table data source to the given directory in the file system.(package private) void
create(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) IndexSet
createIndexSet()
Creates and returns an IndexSet object that is used to create indices for this table source.(package private) long
currentUniqueID()
Atomically returns the current 'unique_id' value for this table.(package private) void
dirtyOpen(java.lang.String file_name)
Opens this source in the most minimal way.(package private) void
dispose(boolean pending_close)
Disposes of all in-memory resources associated with this table and invalidates this object.(package private) boolean
drop()
Disposes and drops this table.(package private) boolean
exists(java.lang.String file_name)
Returns true if the master table data source with the given filename exists.(package private) java.lang.String
getFileName()
Returns the name of the file in the conglomerate that represents this store in the file system.(package private) java.io.File
getPath()
Returns the path of where this table is located.(package private) java.lang.String
getSourceIdent()
Returns a string that uniquely identifies this table within the conglomerate context.(package private) int
internalAddRow(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) void
internalDeleteRow(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) TObject
internalGetCellContents(int column, int row)
Returns the cell contents of the given cell in the table.(package private) DataTableDef
loadDataTableDef()
(package private) long
nextUniqueID()
Atomically returns the next 'unique_id' value from this table.(package private) void
open(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) int
rawDataSectorSize()
Returns the current sector size for this data source.(package private) int
rawRecordSize(int row_number)
Returns the number of bytes the row takes up in the data file.(package private) int
rawRowCount()
Returns the raw count or rows in the table, including uncommited, committed and deleted rows.(package private) int
readRecordType(int row_index)
Reads the record state for the given record in the table.private void
rebuildAllIndices(java.io.File path, java.lang.String file_name)
This may only be called from the 'fix' method.(package private) boolean
recordDeleted(int row_index)
Returns true if the record with the given index is deleted from the table.(package private) void
saveDataTableDef(DataTableDef def)
(package private) void
setUniqueID(long value)
Sets the unique id for this store.(package private) void
shutdownHookCleanup()
Called by the 'shutdown hook' on the conglomerate.(package private) void
synchAll()
java.lang.String
toString()
For diagnostic.(package private) int
writeRecordType(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.IOException
Physically 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.IOException
Returns 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.IOException
Opens 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.IOException
Closes 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.IOException
Returns 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.IOException
Returns 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.IOException
This 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.IOException
Copies 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.IOException
Performs 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:MasterTableDataSource
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.- Specified by:
checkForCleanup
in classMasterTableDataSource
-
getSourceIdent
java.lang.String getSourceIdent()
Description copied from class:MasterTableDataSource
Returns 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:
getSourceIdent
in classMasterTableDataSource
-
synchAll
void synchAll() throws java.io.IOException
- Throws:
java.io.IOException
-
writeRecordType
int writeRecordType(int row_index, int row_state) throws java.io.IOException
Description copied from class:MasterTableDataSource
Sets 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:
writeRecordType
in classMasterTableDataSource
- Throws:
java.io.IOException
-
readRecordType
int readRecordType(int row_index) throws java.io.IOException
Description copied from class:MasterTableDataSource
Reads the record state for the given record in the table.- Specified by:
readRecordType
in classMasterTableDataSource
- Throws:
java.io.IOException
-
recordDeleted
boolean recordDeleted(int row_index) throws java.io.IOException
Description copied from class:MasterTableDataSource
Returns true if the record with the given index is deleted from the table. A deleted row can not be read.- Specified by:
recordDeleted
in classMasterTableDataSource
- Throws:
java.io.IOException
-
rawRowCount
int rawRowCount() throws java.io.IOException
Description copied from class:MasterTableDataSource
Returns 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:
rawRowCount
in classMasterTableDataSource
- Throws:
java.io.IOException
-
internalDeleteRow
void internalDeleteRow(int row_index) throws java.io.IOException
Description copied from class:MasterTableDataSource
Removes the row at the given index so that any resources associated with the row may be immediately available to be recycled.- Specified by:
internalDeleteRow
in classMasterTableDataSource
- Throws:
java.io.IOException
-
createIndexSet
IndexSet createIndexSet()
Description copied from class:MasterTableDataSource
Creates 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:
createIndexSet
in classMasterTableDataSource
-
commitIndexSet
void commitIndexSet(IndexSet index_set)
Description copied from class:MasterTableDataSource
Commits changes made to an IndexSet returned by the 'createIndexSet' method. This method also disposes the IndexSet so it is no longer valid.- Specified by:
commitIndexSet
in 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:MasterTableDataSource
Adds 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:
internalAddRow
in classMasterTableDataSource
- Throws:
java.io.IOException
-
internalGetCellContents
TObject internalGetCellContents(int column, int row)
Description copied from class:MasterTableDataSource
Returns 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:
internalGetCellContents
in classMasterTableDataSource
-
currentUniqueID
long currentUniqueID()
Description copied from class:MasterTableDataSource
Atomically returns the current 'unique_id' value for this table.- Specified by:
currentUniqueID
in classMasterTableDataSource
-
nextUniqueID
long nextUniqueID()
Description copied from class:MasterTableDataSource
Atomically returns the next 'unique_id' value from this table.- Specified by:
nextUniqueID
in classMasterTableDataSource
-
setUniqueID
void setUniqueID(long value)
Description copied from class:MasterTableDataSource
Sets 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:
setUniqueID
in classMasterTableDataSource
-
dispose
void dispose(boolean pending_close) throws java.io.IOException
Description copied from class:MasterTableDataSource
Disposes 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:
dispose
in classMasterTableDataSource
- Throws:
java.io.IOException
-
drop
boolean drop() throws java.io.IOException
Description copied from class:MasterTableDataSource
Disposes 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:
drop
in classMasterTableDataSource
- Throws:
java.io.IOException
-
shutdownHookCleanup
void shutdownHookCleanup()
Description copied from class:MasterTableDataSource
Called 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:
shutdownHookCleanup
in classMasterTableDataSource
-
toString
public java.lang.String toString()
For diagnostic.- Overrides:
toString
in classjava.lang.Object
-
-