Class MVTable

All Implemented Interfaces:
HasSQL

public class MVTable extends TableBase
A table stored in a MVStore.
  • Field Details

    • WAITING_FOR_LOCK

      public static final DebuggingThreadLocal<String> WAITING_FOR_LOCK
      The table name this thread is waiting to lock.
    • EXCLUSIVE_LOCKS

      public static final DebuggingThreadLocal<ArrayList<String>> EXCLUSIVE_LOCKS
      The table names this thread has exclusively locked.
    • SHARED_LOCKS

      public static final DebuggingThreadLocal<ArrayList<String>> SHARED_LOCKS
      The tables names this thread has a shared lock on.
    • NO_EXTRA_INFO

      private static final String NO_EXTRA_INFO
      See Also:
    • 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 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 ArrayList<Index> indexes
    • lastModificationId

      private final AtomicLong lastModificationId
    • waitingSessions

      private final 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 AtomicInteger changesUntilAnalyze
    • nextAnalyze

      private int nextAnalyze
    • store

      private final Store store
    • transactionStore

      private final TransactionStore transactionStore
  • Constructor Details

  • Method Details

    • getMapName

      public 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.
      Overrides:
      lock in class Table
      Parameters:
      session - the session
      lockType - the type of lock
      Returns:
      true if the table was already exclusively locked by this session.
    • doLock1

      private void doLock1(SessionLocal session, int lockType)
    • doLock2

      private boolean doLock2(SessionLocal session, int lockType)
    • addLockToDebugList

      private void addLockToDebugList(DebuggingThreadLocal<ArrayList<String>> locks)
    • traceLock

      private void traceLock(SessionLocal session, int lockType, MVTable.TraceLockEvent eventEnum, String extraInfo)
    • unlock

      public void unlock(SessionLocal s)
      Description copied from class: Table
      Release the lock for this session.
      Overrides:
      unlock in class Table
      Parameters:
      s - the session
    • close

      public void close(SessionLocal session)
      Description copied from class: Table
      Close the table object and flush changes.
      Specified by:
      close in class Table
      Parameters:
      session - the session
    • getRow

      public Row getRow(SessionLocal session, long key)
      Description copied from class: Table
      Get the given row.
      Overrides:
      getRow in class Table
      Parameters:
      session - the session
      key - the primary key
      Returns:
      the row
    • addIndex

      public Index addIndex(SessionLocal session, String indexName, int indexId, IndexColumn[] cols, int uniqueColumnCount, IndexType indexType, boolean create, String indexComment)
      Description copied from class: Table
      Create an index for this table
      Specified by:
      addIndex in class Table
      Parameters:
      session - the session
      indexName - the name of the index
      indexId - the id
      cols - the index columns
      uniqueColumnCount - the count of unique columns
      indexType - the index type
      create - whether this is a new index
      indexComment - the comment
      Returns:
      the index
    • rebuildIndex

      private void rebuildIndex(SessionLocal session, MVIndex<?,?> index, 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.
      Specified by:
      removeRow in class Table
      Parameters:
      session - the session
      row - the row
    • truncate

      public long truncate(SessionLocal session)
      Description copied from class: Table
      Remove all rows from the table and indexes.
      Specified by:
      truncate in class Table
      Parameters:
      session - the session
      Returns:
      number of removed rows, possibly including uncommitted rows
    • addRow

      public void addRow(SessionLocal session, Row row)
      Description copied from class: Table
      Add a row to the table and all indexes.
      Specified by:
      addRow in class Table
      Parameters:
      session - the session
      row - the row
    • updateRow

      public void updateRow(SessionLocal session, Row oldRow, Row newRow)
      Description copied from class: Table
      Update a row to the table and all indexes.
      Overrides:
      updateRow in class Table
      Parameters:
      session - the session
      oldRow - the row to update
      newRow - the row with updated values (_rowid_ suppose to be the same)
    • 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.
      Overrides:
      lockRow in class Table
      Parameters:
      session - the session
      row - to lock
      Returns:
      locked row, or null if row does not exist anymore
    • 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 class Table
      Parameters:
      session - the session
      Returns:
      the index
    • getIndexes

      public ArrayList<Index> getIndexes()
      Description copied from class: Table
      Get all indexes for this table.
      Specified by:
      getIndexes in class Table
      Returns:
      the list of indexes
    • getMaxDataModificationId

      public long getMaxDataModificationId()
      Description copied from class: Table
      Get the last data modification id.
      Specified by:
      getMaxDataModificationId in class Table
      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 class Table
      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 class Table
      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 class Table
      Parameters:
      session - the session
      Returns:
      the approximated row count
    • getDiskSpaceUsed

      public long getDiskSpaceUsed()
      Overrides:
      getDiskSpaceUsed in class Table
    • 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 class Table
      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, or SearchRow.ROWID_INDEX.
      Overrides:
      getMainIndexColumn in class Table
      Returns:
      ID of main index column, or SearchRow.ROWID_INDEX
    • addRowsToIndex

      private static void addRowsToIndex(SessionLocal session, ArrayList<Row> list, Index index)
      Appends the specified rows to the specified index.
      Parameters:
      session - the session
      list - the rows, list is cleared on completion
      index - the index to append to
    • getDeadlockDetails

      private static String getDeadlockDetails(ArrayList<SessionLocal> sessions, int lockType)
      Formats details of a deadlock.
      Parameters:
      sessions - the list of sessions
      lockType - the type of lock
      Returns:
      formatted details of a deadlock
    • lockTypeToString

      private static String lockTypeToString(int lockType)
    • sortRows

      private static void sortRows(ArrayList<? extends SearchRow> list, Index index)
      Sorts the specified list of rows for a specified index.
      Parameters:
      list - the list of rows
      index - the index to sort for
    • canDrop

      public boolean canDrop()
      Description copied from class: Table
      Check if this table can be dropped.
      Specified by:
      canDrop in class Table
      Returns:
      true if it can
    • canGetRowCount

      public boolean canGetRowCount(SessionLocal session)
      Description copied from class: Table
      Check if the row count can be retrieved quickly.
      Specified by:
      canGetRowCount in class Table
      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 class Table
      Returns:
      true if it can
    • checkDeadlock

      public ArrayList<SessionLocal> checkDeadlock(SessionLocal session, SessionLocal clash, 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 class Table
      Parameters:
      session - the session to be tested for
      clash - set with sessions already visited, and null when starting verification
      visited - 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 class Table
    • 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 class Table
      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 class Table
      Returns:
      the table type name
    • isDeterministic

      public boolean isDeterministic()
      Description copied from class: Table
      Check if the table is deterministic.
      Specified by:
      isDeterministic in class Table
      Returns:
      true if it is
    • isLockedExclusively

      public boolean isLockedExclusively()
      Description copied from class: Table
      Check if this table is locked exclusively.
      Overrides:
      isLockedExclusively in class Table
      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 class Table
      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 class DbObject
    • toString

      public String toString()
      Overrides:
      toString in class DbObject
    • prepareColumns

      private static IndexColumn[] prepareColumns(Database database, IndexColumn[] cols, IndexType indexType)
      Prepares columns of an index.
      Parameters:
      database - the database
      cols - the index columns
      indexType - the type of an index
      Returns:
      the prepared columns with flags set