Package org.h2.mvstore.db
Class MVTable
- java.lang.Object
-
- org.h2.engine.DbObject
-
- org.h2.schema.SchemaObject
-
- org.h2.table.Table
-
- org.h2.table.TableBase
-
- org.h2.mvstore.db.MVTable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MVTable.TraceLockEvent
The type of trace lock events
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicInteger
changesUntilAnalyze
private boolean
containsLargeObject
Whether the table contains a CLOB or BLOB.static DebuggingThreadLocal<java.util.ArrayList<java.lang.String>>
EXCLUSIVE_LOCKS
The table names this thread has exclusively locked.private java.util.ArrayList<Index>
indexes
private java.util.concurrent.atomic.AtomicLong
lastModificationId
private SessionLocal
lockExclusiveSession
The session (if any) that has exclusively locked this table.private java.util.concurrent.ConcurrentHashMap<SessionLocal,SessionLocal>
lockSharedSessions
The set of sessions (if any) that have a shared lock on the table.private int
nextAnalyze
private static java.lang.String
NO_EXTRA_INFO
private MVPrimaryIndex
primaryIndex
private Column
rowIdColumn
static DebuggingThreadLocal<java.util.ArrayList<java.lang.String>>
SHARED_LOCKS
The tables names this thread has a shared lock on.private Store
store
private Trace
traceLock
private TransactionStore
transactionStore
static DebuggingThreadLocal<java.lang.String>
WAITING_FOR_LOCK
The table name this thread is waiting to lock.private java.util.ArrayDeque<SessionLocal>
waitingSessions
The queue of sessions waiting to lock the table.-
Fields inherited from class org.h2.table.Table
columns, compareMode, EXCLUSIVE_LOCK, isHidden, READ_LOCK, TYPE_CACHED, TYPE_MEMORY, WRITE_LOCK
-
Fields inherited from class org.h2.engine.DbObject
AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USER
-
Fields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS
-
-
Constructor Summary
Constructors Constructor Description MVTable(CreateTableData data, Store store)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Index
addIndex(SessionLocal session, java.lang.String indexName, int indexId, IndexColumn[] cols, int uniqueColumnCount, IndexType indexType, boolean create, java.lang.String indexComment)
Create an index for this tableprivate void
addLockToDebugList(DebuggingThreadLocal<java.util.ArrayList<java.lang.String>> locks)
void
addRow(SessionLocal session, Row row)
Add a row to the table and all indexes.private static void
addRowsToIndex(SessionLocal session, java.util.ArrayList<Row> list, Index index)
Appends the specified rows to the specified index.private void
analyzeIfRequired(SessionLocal session)
boolean
canDrop()
Check if this table can be dropped.boolean
canGetRowCount(SessionLocal session)
Check if the row count can be retrieved quickly.boolean
canTruncate()
Check if this table can be truncated.java.util.ArrayList<SessionLocal>
checkDeadlock(SessionLocal session, SessionLocal clash, java.util.Set<SessionLocal> visited)
Check if a deadlock occurred.void
checkSupportAlter()
Check if this table supports ALTER TABLE.void
close(SessionLocal session)
Close the table object and flush changes.void
commit()
Mark the transaction as committed, so that the modification counter of the database is incremented.(package private) DbException
convertException(MVStoreException e)
Convert the MVStoreException to a database exception.private void
doLock1(SessionLocal session, int lockType)
private boolean
doLock2(SessionLocal session, int lockType)
boolean
getContainsLargeObject()
private static java.lang.String
getDeadlockDetails(java.util.ArrayList<SessionLocal> sessions, int lockType)
Formats details of a deadlock.long
getDiskSpaceUsed()
java.util.ArrayList<Index>
getIndexes()
Get all indexes for this table.int
getMainIndexColumn()
Returns ID of main index column, orSearchRow.ROWID_INDEX
.java.lang.String
getMapName()
long
getMaxDataModificationId()
Get the last data modification id.Row
getRow(SessionLocal session, long key)
Get the given row.long
getRowCount(SessionLocal session)
Get the row count for this table.long
getRowCountApproximation(SessionLocal session)
Get the approximated row count for this table.Column
getRowIdColumn()
Get the row id column if this table has one.Index
getScanIndex(SessionLocal session)
Get the scan index to iterate through all rows.TableType
getTableType()
Get the table type name(package private) Transaction
getTransactionBegin()
Get a new transaction.protected void
invalidate()
Set the main attributes to null to make sure the object is no longer used.boolean
isDeterministic()
Check if the table is deterministic.boolean
isLockedExclusively()
Check if this table is locked exclusively.boolean
isLockedExclusivelyBy(SessionLocal session)
Check if the table is exclusively locked by this session.boolean
isRowLockable()
Views, function tables, links, etc.boolean
lock(SessionLocal session, int lockType)
Lock the table for the given session.Row
lockRow(SessionLocal session, Row row)
Locks row, preventing any updated to it, except from the session specified.private static java.lang.String
lockTypeToString(int lockType)
private static IndexColumn[]
prepareColumns(Database database, IndexColumn[] cols, IndexType indexType)
Prepares columns of an index.private void
rebuildIndex(SessionLocal session, MVIndex<?,?> index, java.lang.String indexName)
private void
rebuildIndexBlockMerge(SessionLocal session, MVIndex<?,?> index)
private void
rebuildIndexBuffered(SessionLocal session, Index index)
void
removeChildrenAndResources(SessionLocal session)
Delete all dependent children objects and resources of this object.void
removeRow(SessionLocal session, Row row)
Remove a row from the table and all indexes.private static void
sortRows(java.util.ArrayList<? extends SearchRow> list, Index index)
Sorts the specified list of rows for a specified index.private void
syncLastModificationIdWithDatabase()
java.lang.String
toString()
private void
traceLock(SessionLocal session, int lockType, MVTable.TraceLockEvent eventEnum, java.lang.String extraInfo)
long
truncate(SessionLocal session)
Remove all rows from the table and indexes.void
unlock(SessionLocal s)
Release the lock for this session.void
updateRow(SessionLocal session, Row oldRow, Row newRow)
Update a row to the table and all indexes.-
Methods inherited from class org.h2.table.TableBase
getCreateSQL, getCreateSQLForMeta, getDropSQL, getMainIndexColumn, isGlobalTemporary
-
Methods inherited from class org.h2.table.Table
addConstraint, addDependencies, addDependentView, addSequence, addSynonym, addTrigger, canReference, checkWritingAllowed, compareValues, convertInsertRow, convertUpdateRow, createRow, doesColumnExist, dropMultipleColumnsConstraintsAndIndexes, findColumn, findPrimaryKey, fire, fireAfterRow, fireBeforeRow, fireRow, getBestPlanItem, getCheckForeignKeyConstraints, getChildren, getColumn, getColumn, getColumn, getColumns, getCompareMode, getConstraints, getCreateSQLForCopy, getDependentViews, getIdentityColumn, getIndex, getIndexForColumn, getNullRow, getOnCommitDrop, getOnCommitTruncate, getPrimaryKey, getRowFactory, getScanIndex, getSQLTableType, getTemplateRow, getTemplateSimpleRow, getTriggers, getType, hasSelectTrigger, isHidden, isInsertable, isPersistData, isPersistIndexes, isQueryComparable, isTableExpression, isView, removeColumnExpressionsDependencies, removeConstraint, removeDependentView, removeIndex, removeIndexOrTransferOwnership, removeSequence, removeSynonym, removeTrigger, rename, renameColumn, setCheckForeignKeyConstraints, setColumns, setHidden, setOnCommitDrop, setOnCommitTruncate, setTableExpression, updateRows
-
Methods inherited from class org.h2.schema.SchemaObject
getSchema, getSQL, getSQL
-
Methods inherited from class org.h2.engine.DbObject
checkRename, getComment, getDatabase, getId, getModificationId, getName, isTemporary, isValid, setComment, setModified, setObjectName, setTemporary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
-
-
-
Field Detail
-
WAITING_FOR_LOCK
public static final DebuggingThreadLocal<java.lang.String> WAITING_FOR_LOCK
The table name this thread is waiting to lock.
-
EXCLUSIVE_LOCKS
public static final DebuggingThreadLocal<java.util.ArrayList<java.lang.String>> EXCLUSIVE_LOCKS
The table names this thread has exclusively locked.
-
SHARED_LOCKS
public static final DebuggingThreadLocal<java.util.ArrayList<java.lang.String>> SHARED_LOCKS
The tables names this thread has a shared lock on.
-
NO_EXTRA_INFO
private static final java.lang.String NO_EXTRA_INFO
- See Also:
- Constant Field Values
-
containsLargeObject
private final boolean containsLargeObject
Whether the table contains a CLOB or BLOB.
-
lockExclusiveSession
private volatile SessionLocal lockExclusiveSession
The session (if any) that has exclusively locked this table.
-
lockSharedSessions
private final java.util.concurrent.ConcurrentHashMap<SessionLocal,SessionLocal> lockSharedSessions
The set of sessions (if any) that have a shared lock on the table. Here we are using using a ConcurrentHashMap as a set, as there is no ConcurrentHashSet.
-
rowIdColumn
private Column rowIdColumn
-
primaryIndex
private final MVPrimaryIndex primaryIndex
-
indexes
private final java.util.ArrayList<Index> indexes
-
lastModificationId
private final java.util.concurrent.atomic.AtomicLong lastModificationId
-
waitingSessions
private final java.util.ArrayDeque<SessionLocal> waitingSessions
The queue of sessions waiting to lock the table. It is a FIFO queue to prevent starvation, since Java's synchronized locking is biased.
-
traceLock
private final Trace traceLock
-
changesUntilAnalyze
private final java.util.concurrent.atomic.AtomicInteger changesUntilAnalyze
-
nextAnalyze
private int nextAnalyze
-
store
private final Store store
-
transactionStore
private final TransactionStore transactionStore
-
-
Constructor Detail
-
MVTable
public MVTable(CreateTableData data, Store store)
-
-
Method Detail
-
getMapName
public java.lang.String getMapName()
-
lock
public boolean lock(SessionLocal session, int lockType)
Description copied from class:Table
Lock the table for the given session. This method waits until the lock is granted.
-
doLock1
private void doLock1(SessionLocal session, int lockType)
-
doLock2
private boolean doLock2(SessionLocal session, int lockType)
-
addLockToDebugList
private void addLockToDebugList(DebuggingThreadLocal<java.util.ArrayList<java.lang.String>> locks)
-
traceLock
private void traceLock(SessionLocal session, int lockType, MVTable.TraceLockEvent eventEnum, java.lang.String extraInfo)
-
unlock
public void unlock(SessionLocal s)
Description copied from class:Table
Release the lock for this session.
-
close
public void close(SessionLocal session)
Description copied from class:Table
Close the table object and flush changes.
-
getRow
public Row getRow(SessionLocal session, long key)
Description copied from class:Table
Get the given row.
-
addIndex
public Index addIndex(SessionLocal session, java.lang.String indexName, int indexId, IndexColumn[] cols, int uniqueColumnCount, IndexType indexType, boolean create, java.lang.String indexComment)
Description copied from class:Table
Create an index for this table- Specified by:
addIndex
in classTable
- Parameters:
session
- the sessionindexName
- the name of the indexindexId
- the idcols
- the index columnsuniqueColumnCount
- the count of unique columnsindexType
- the index typecreate
- whether this is a new indexindexComment
- the comment- Returns:
- the index
-
rebuildIndex
private void rebuildIndex(SessionLocal session, MVIndex<?,?> index, java.lang.String indexName)
-
rebuildIndexBlockMerge
private void rebuildIndexBlockMerge(SessionLocal session, MVIndex<?,?> index)
-
rebuildIndexBuffered
private void rebuildIndexBuffered(SessionLocal session, Index index)
-
removeRow
public void removeRow(SessionLocal session, Row row)
Description copied from class:Table
Remove a row from the table and all indexes.
-
truncate
public long truncate(SessionLocal session)
Description copied from class:Table
Remove all rows from the table and indexes.
-
addRow
public void addRow(SessionLocal session, Row row)
Description copied from class:Table
Add a row to the table and all indexes.
-
updateRow
public void updateRow(SessionLocal session, Row oldRow, Row newRow)
Description copied from class:Table
Update a row to the table and all indexes.
-
lockRow
public Row lockRow(SessionLocal session, Row row)
Description copied from class:Table
Locks row, preventing any updated to it, except from the session specified.
-
analyzeIfRequired
private void analyzeIfRequired(SessionLocal session)
-
getScanIndex
public Index getScanIndex(SessionLocal session)
Description copied from class:Table
Get the scan index to iterate through all rows.- Specified by:
getScanIndex
in classTable
- Parameters:
session
- the session- Returns:
- the index
-
getIndexes
public java.util.ArrayList<Index> getIndexes()
Description copied from class:Table
Get all indexes for this table.- Specified by:
getIndexes
in classTable
- Returns:
- the list of indexes
-
getMaxDataModificationId
public long getMaxDataModificationId()
Description copied from class:Table
Get the last data modification id.- Specified by:
getMaxDataModificationId
in classTable
- Returns:
- the modification id
-
removeChildrenAndResources
public void removeChildrenAndResources(SessionLocal session)
Description copied from class:DbObject
Delete all dependent children objects and resources of this object.- Overrides:
removeChildrenAndResources
in classTable
- Parameters:
session
- the session
-
getRowCount
public long getRowCount(SessionLocal session)
Description copied from class:Table
Get the row count for this table.- Specified by:
getRowCount
in classTable
- Parameters:
session
- the session- Returns:
- the row count
-
getRowCountApproximation
public long getRowCountApproximation(SessionLocal session)
Description copied from class:Table
Get the approximated row count for this table.- Specified by:
getRowCountApproximation
in classTable
- Parameters:
session
- the session- Returns:
- the approximated row count
-
getDiskSpaceUsed
public long getDiskSpaceUsed()
- Overrides:
getDiskSpaceUsed
in classTable
-
getTransactionBegin
Transaction getTransactionBegin()
Get a new transaction.- Returns:
- the transaction
-
isRowLockable
public boolean isRowLockable()
Description copied from class:Table
Views, function tables, links, etc. do not support locks- Overrides:
isRowLockable
in classTable
- Returns:
- true if table supports row-level locks
-
commit
public void commit()
Mark the transaction as committed, so that the modification counter of the database is incremented.
-
syncLastModificationIdWithDatabase
private void syncLastModificationIdWithDatabase()
-
convertException
DbException convertException(MVStoreException e)
Convert the MVStoreException to a database exception.- Parameters:
e
- the illegal state exception- Returns:
- the database exception
-
getMainIndexColumn
public int getMainIndexColumn()
Description copied from class:Table
Returns ID of main index column, orSearchRow.ROWID_INDEX
.- Overrides:
getMainIndexColumn
in classTable
- Returns:
- ID of main index column, or
SearchRow.ROWID_INDEX
-
addRowsToIndex
private static void addRowsToIndex(SessionLocal session, java.util.ArrayList<Row> list, Index index)
Appends the specified rows to the specified index.- Parameters:
session
- the sessionlist
- the rows, list is cleared on completionindex
- the index to append to
-
getDeadlockDetails
private static java.lang.String getDeadlockDetails(java.util.ArrayList<SessionLocal> sessions, int lockType)
Formats details of a deadlock.- Parameters:
sessions
- the list of sessionslockType
- the type of lock- Returns:
- formatted details of a deadlock
-
lockTypeToString
private static java.lang.String lockTypeToString(int lockType)
-
sortRows
private static void sortRows(java.util.ArrayList<? extends SearchRow> list, Index index)
Sorts the specified list of rows for a specified index.- Parameters:
list
- the list of rowsindex
- the index to sort for
-
canDrop
public boolean canDrop()
Description copied from class:Table
Check if this table can be dropped.
-
canGetRowCount
public boolean canGetRowCount(SessionLocal session)
Description copied from class:Table
Check if the row count can be retrieved quickly.- Specified by:
canGetRowCount
in classTable
- Parameters:
session
- the session- Returns:
- true if it can
-
canTruncate
public boolean canTruncate()
Description copied from class:Table
Check if this table can be truncated.- Overrides:
canTruncate
in classTable
- Returns:
- true if it can
-
checkDeadlock
public java.util.ArrayList<SessionLocal> checkDeadlock(SessionLocal session, SessionLocal clash, java.util.Set<SessionLocal> visited)
Description copied from class:Table
Check if a deadlock occurred. This method is called recursively. There is a circle if the session to be tested has already being visited. If this session is part of the circle (if it is the clash session), the method must return an empty object array. Once a deadlock has been detected, the methods must add the session to the list. If this session is not part of the circle, or if no deadlock is detected, this method returns null.- Overrides:
checkDeadlock
in classTable
- Parameters:
session
- the session to be tested forclash
- set with sessions already visited, and null when starting verificationvisited
- set with sessions already visited, and null when starting verification- Returns:
- an object array with the sessions involved in the deadlock, or null
-
checkSupportAlter
public void checkSupportAlter()
Description copied from class:Table
Check if this table supports ALTER TABLE.- Specified by:
checkSupportAlter
in classTable
-
getContainsLargeObject
public boolean getContainsLargeObject()
-
getRowIdColumn
public Column getRowIdColumn()
Description copied from class:Table
Get the row id column if this table has one.- Overrides:
getRowIdColumn
in classTable
- Returns:
- the row id column, or null
-
getTableType
public TableType getTableType()
Description copied from class:Table
Get the table type name- Specified by:
getTableType
in classTable
- Returns:
- the table type name
-
isDeterministic
public boolean isDeterministic()
Description copied from class:Table
Check if the table is deterministic.- Specified by:
isDeterministic
in classTable
- Returns:
- true if it is
-
isLockedExclusively
public boolean isLockedExclusively()
Description copied from class:Table
Check if this table is locked exclusively.- Overrides:
isLockedExclusively
in classTable
- Returns:
- true if it is.
-
isLockedExclusivelyBy
public boolean isLockedExclusivelyBy(SessionLocal session)
Description copied from class:Table
Check if the table is exclusively locked by this session.- Overrides:
isLockedExclusivelyBy
in classTable
- Parameters:
session
- the session- Returns:
- true if it is
-
invalidate
protected void invalidate()
Description copied from class:DbObject
Set the main attributes to null to make sure the object is no longer used.- Overrides:
invalidate
in classDbObject
-
prepareColumns
private static IndexColumn[] prepareColumns(Database database, IndexColumn[] cols, IndexType indexType)
Prepares columns of an index.- Parameters:
database
- the databasecols
- the index columnsindexType
- the type of an index- Returns:
- the prepared columns with flags set
-
-