Class TransactionManager

  • All Implemented Interfaces:
    BufferManagerObserver

    public class TransactionManager
    extends java.lang.Object
    implements BufferManagerObserver
    The Transaction Manager is responsible for managing all aspects of proper transaction processing within the database. It works closely with the other components of the Storage Manager to make this happen correctly.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.apache.logging.log4j.Logger logger
      A logging object for reporting anything interesting that happens.
      private java.util.concurrent.atomic.AtomicInteger nextTxnID
      This variable keeps track of the next transaction ID that should be used for a transaction.
      private NanoDBServer server
      A reference to the server that this transaction manager is operating within.
      private StorageManager storageManager
      A reference to the storage manager that this transaction manager is operating within.
      private static java.lang.String TXNSTATE_FILENAME
      This is the name of the file that the Transaction Manager uses to keep track of overall transaction state.
      private LogSequenceNumber txnStateNextLSN
      This is the last value of nextLSN saved to the transaction-state file.
      private WALManager walManager
      The write-ahead logger that records transaction details.
    • Field Detail

      • logger

        private static org.apache.logging.log4j.Logger logger
        A logging object for reporting anything interesting that happens.
      • TXNSTATE_FILENAME

        private static final java.lang.String TXNSTATE_FILENAME
        This is the name of the file that the Transaction Manager uses to keep track of overall transaction state.
        See Also:
        Constant Field Values
      • server

        private NanoDBServer server
        A reference to the server that this transaction manager is operating within.
      • storageManager

        private StorageManager storageManager
        A reference to the storage manager that this transaction manager is operating within.
      • walManager

        private WALManager walManager
        The write-ahead logger that records transaction details.
      • nextTxnID

        private java.util.concurrent.atomic.AtomicInteger nextTxnID
        This variable keeps track of the next transaction ID that should be used for a transaction. It is initialized when the transaction manager is started.
      • txnStateNextLSN

        private LogSequenceNumber txnStateNextLSN
        This is the last value of nextLSN saved to the transaction-state file.
    • Constructor Detail

      • TransactionManager

        public TransactionManager​(NanoDBServer server)
    • Method Detail

      • createTxnStateFile

        private TransactionStatePage createTxnStateFile()
        This helper function initializes a brand new transaction-state file for the transaction manager to use for providing transaction atomicity and durability.
        Returns:
        a DBFile object for the newly created and initialized transaction-state file.
      • storeTxnStateToFile

        private void storeTxnStateToFile()
      • initialize

        public void initialize()
      • getNextTxnID

        private int getNextTxnID()
        Returns the "next transaction ID" value without incrementing it. This operation is thread-safe.
        Returns:
        the next transaction ID to use
      • getAndIncrementNextTxnID

        private int getAndIncrementNextTxnID()
        Returns the "next transaction ID" value, and also increments this value. This operation is thread-safe.
        Returns:
        the next transaction ID to use
      • recordPageUpdate

        public void recordPageUpdate​(DBPage dbPage)
      • beforeWriteDirtyPages

        public void beforeWriteDirtyPages​(java.util.List<DBPage> pages)
        This method is registered on the BufferManager, to ensure that the write-ahead logging rule is enforced. Specifically, all dirty pages to be evicted from the buffer manager must be reflected in the write-ahead log on disk, before they are evicted.
        Specified by:
        beforeWriteDirtyPages in interface BufferManagerObserver
        Parameters:
        pages - the collection of pages that are about to be evicted.
      • forceWAL

        public void forceWAL​(LogSequenceNumber lsn)
        This method forces the write-ahead log out to at least the specified log sequence number, syncing the log to ensure that all essential records have reached the disk itself.
        Parameters:
        lsn - All WAL data up to this value must be forced to disk and sync'd. This value may be one past the end of the current WAL file during normal operation.
      • forceWAL

        public void forceWAL()
        This method forces the entire write-ahead log out to disk, syncing the log as well. This version is intended to be used during shutdown processing in order to record all WAL changes to disk.
        Throws:
        IOException - if an IO error occurs while attempting to force the WAL file to disk. If a failure occurs, the database is probably going to be broken.