com.mckoi.database
Class V2MasterTableDataSource

java.lang.Object
  extended by com.mckoi.database.V2MasterTableDataSource

public final class V2MasterTableDataSource
extends java.lang.Object

A MasterTableDataSource that is backed by a non-shared com.mckoi.store.Store object. The store interface allows us a great deal of flexibility because we can map a store around different underlying devices. For example, a store could map to a memory region, a memory mapped file, or a standard random access file.

Unlike V1MasterTableDataSource, this manages data and index information in a single store which can be backed by a single file in the file system.

The structure of the store comprises of a header block that contains the following information;

       HEADER BLOCK
   +-------------------------------+
   | version                       |
   | table id                      |
   | table sequence id             |
   | pointer to DataTableDef       |
   | pointer to DataIndexSetDef    |
   | pointer to index block        |
   | LIST BLOCK HEADER pointer     |
   +-------------------------------+
 

Each record is comprised of a header which contains offsets to the fields in the record, and a serializable of the fields themselves.

Author:
Tobias Downer

Field Summary
protected  BlobStoreInterface blob_store_interface
          An abstracted reference to a BlobStore for managing blob references and blob data.
protected  com.mckoi.database.DataCellCache cache
          A reference to the DataCellCache object.
protected  int column_count
          The number of columns in this table.
protected  com.mckoi.database.RIDList[] column_rid_list
          The list of RIDList objects for each column in this table.
protected  boolean DATA_CELL_CACHING
          Set to false to disable cell caching.
protected  java.lang.String delete_hits_key
           
protected  java.lang.String file_hits_key
           
protected  com.mckoi.database.MasterTableGarbageCollector garbage_collector
          Manages scanning and deleting of rows marked as deleted within this data source.
protected  DataIndexSetDef index_def
          A DataIndexSetDef object that describes the indexes on the table.
protected  java.lang.String insert_hits_key
           
protected  boolean is_closed
          True if this table source is closed.
protected  java.lang.String root_lock_key
          The keys we use for Database.stats() for information for this table.
protected  DataTableDef table_def
          A DataTableDef object that describes the table topology.
protected  int table_id
          An integer that uniquely identifies this data source within the conglomerate.
protected  com.mckoi.database.MultiVersionTableIndices table_indices
          A multi-version representation of the table indices kept for this table including the row list and the scheme indices.
protected  java.lang.String total_hits_key
           
 
Constructor Summary
V2MasterTableDataSource(TransactionSystem system, com.mckoi.database.StoreSystem store_system, com.mckoi.database.OpenTransactionList open_transactions, BlobStoreInterface blob_store_interface)
          The Constructor.
 
Method Summary
 void checkAndRepair(java.lang.String file_name, UserTerminal terminal)
          Performs a complete check and repair of the table.
protected  void clearAllRootLocks()
          Clears all root locks on the table.
 DebugLogger Debug()
          Returns the DebugLogger object that can be used to log debug messages.
protected  void doOpeningScan()
          This is called by the 'open' method.
 java.lang.String getName()
          Returns the name of this table source.
 java.lang.String getSchema()
          Returns the schema name of this table source.
 TransactionSystem getSystem()
          Returns the TransactionSystem for this table.
 TableName getTableName()
          Returns the TableName of this table source.
protected  void loadInternal()
          Loads the internal variables.
protected static java.lang.String makeTableFileName(TransactionSystem system, int table_id, TableName table_name)
          Creates a unique table name to give a file.
protected  TableDataSource minimalTableDataSource(IntegerListInterface master_index)
          Creates a minimal TableDataSource object that represents this MasterTableDataSource.
 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.
 void scanForLeaks()
          Looks for any leaks in the file.
protected  void setupDataIndexSetDef()
          Sets up the DataIndexSetDef object from the information set in this object.
protected  void setupDataTableDef(DataTableDef table_def)
          Sets up the DataTableDef.
protected  com.mckoi.database.StoreSystem storeSystem()
          Returns the StoreSystem object used to manage stores in the persistence system.
 java.lang.String toString()
          For diagnostic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

table_id

protected int table_id
An integer that uniquely identifies this data source within the conglomerate.


is_closed

protected boolean is_closed
True if this table source is closed.


table_def

protected DataTableDef table_def
A DataTableDef object that describes the table topology. This includes the name and columns of the table.


index_def

protected DataIndexSetDef index_def
A DataIndexSetDef object that describes the indexes on the table.


table_indices

protected com.mckoi.database.MultiVersionTableIndices table_indices
A multi-version representation of the table indices kept for this table including the row list and the scheme indices. This contains the transaction journals.


column_rid_list

protected com.mckoi.database.RIDList[] column_rid_list
The list of RIDList objects for each column in this table. This is a sorting optimization.


DATA_CELL_CACHING

protected boolean DATA_CELL_CACHING
Set to false to disable cell caching.


cache

protected final com.mckoi.database.DataCellCache cache
A reference to the DataCellCache object.


column_count

protected int column_count
The number of columns in this table. This is a cached optimization.


garbage_collector

protected com.mckoi.database.MasterTableGarbageCollector garbage_collector
Manages scanning and deleting of rows marked as deleted within this data source.


blob_store_interface

protected BlobStoreInterface blob_store_interface
An abstracted reference to a BlobStore for managing blob references and blob data.


root_lock_key

protected java.lang.String root_lock_key
The keys we use for Database.stats() for information for this table.


total_hits_key

protected java.lang.String total_hits_key

file_hits_key

protected java.lang.String file_hits_key

delete_hits_key

protected java.lang.String delete_hits_key

insert_hits_key

protected java.lang.String insert_hits_key
Constructor Detail

V2MasterTableDataSource

public V2MasterTableDataSource(TransactionSystem system,
                               com.mckoi.database.StoreSystem store_system,
                               com.mckoi.database.OpenTransactionList open_transactions,
                               BlobStoreInterface blob_store_interface)
The Constructor.

Method Detail

open

public 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

scanForLeaks

public void scanForLeaks()
                  throws java.io.IOException
Looks for any leaks in the file. This works by walking through the file and index area graph and 'remembering' all areas that were read. The store is then checked that all other areas except these are deleted.

Assumes the master table is open.

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

toString

public java.lang.String toString()
For diagnostic.

Overrides:
toString in class java.lang.Object

getSystem

public final TransactionSystem getSystem()
Returns the TransactionSystem for this table.


Debug

public final DebugLogger Debug()
Returns the DebugLogger object that can be used to log debug messages.


getTableName

public TableName getTableName()
Returns the TableName of this table source.


getName

public java.lang.String getName()
Returns the name of this table source.


getSchema

public java.lang.String getSchema()
Returns the schema name of this table source.


makeTableFileName

protected static java.lang.String makeTableFileName(TransactionSystem system,
                                                    int table_id,
                                                    TableName table_name)
Creates a unique table name to give a file. This could be changed to suit a particular OS's style of filesystem namespace. Or it could return some arbitarily unique number. However, for debugging purposes it's often a good idea to return a name that a user can recognise.

The 'table_id' is a guarenteed unique number between all tables.


minimalTableDataSource

protected TableDataSource minimalTableDataSource(IntegerListInterface master_index)
Creates a minimal TableDataSource object that represents this MasterTableDataSource. It does not implement the 'getColumnScheme' method.


setupDataIndexSetDef

protected void setupDataIndexSetDef()
Sets up the DataIndexSetDef object from the information set in this object. This will only setup a default IndexSetDef on the information in the DataTableDef.


setupDataTableDef

protected void setupDataTableDef(DataTableDef table_def)
Sets up the DataTableDef. This would typically only ever be called from the 'create' method.


loadInternal

protected void loadInternal()
Loads the internal variables.


storeSystem

protected com.mckoi.database.StoreSystem storeSystem()
Returns the StoreSystem object used to manage stores in the persistence system.


doOpeningScan

protected void doOpeningScan()
                      throws java.io.IOException
This is called by the 'open' method. It performs a scan of the records and marks any rows that are uncommitted as deleted. It also checks that the row is not within the master index.

Throws:
java.io.IOException

clearAllRootLocks

protected void clearAllRootLocks()
Clears all root locks on the table. Should only be used during cleanup of the table and will by definition invalidate the table.