Class FileTxnSnapLog


  • public class FileTxnSnapLog
    extends java.lang.Object
    This is a helper class above the implementations of txnlog and snapshot classes
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String version  
      static int VERSION  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileTxnSnapLog​(java.io.File dataDir, java.io.File snapDir)
      the constructor which takes the datadir and snapdir.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean append​(Request si)
      append the request to the transaction logs
      void close()
      close the transaction log files
      void commit()
      commit the transaction of logs
      long fastForwardFromEdits​(DataTree dt, java.util.Map<java.lang.Long,​java.lang.Integer> sessions, FileTxnSnapLog.PlayBackListener listener)
      This function will fast forward the server database to have the latest transactions in it.
      java.io.File findMostRecentSnapshot()
      the most recent snapshot in the snapshot directory
      java.util.List<java.io.File> findNRecentSnapshots​(int n)
      the n most recent snapshots
      java.io.File getDataDir()
      get the datadir used by this filetxn snap log
      long getLastLoggedZxid()
      the last logged zxid on the transaction logs
      java.io.File getSnapDir()
      get the snap dir used by this filetxn snap log
      java.io.File[] getSnapshotLogs​(long zxid)
      get the snapshot logs which may contain transactions newer than the given zxid.
      void processTransaction​(TxnHeader hdr, DataTree dt, java.util.Map<java.lang.Long,​java.lang.Integer> sessions, org.apache.jute.Record txn)
      process the transaction on the datatree
      long restore​(DataTree dt, java.util.Map<java.lang.Long,​java.lang.Integer> sessions, FileTxnSnapLog.PlayBackListener listener)
      this function restores the server database after reading from the snapshots and transaction logs
      void rollLog()
      roll the transaction logs
      void save​(DataTree dataTree, java.util.concurrent.ConcurrentHashMap<java.lang.Long,​java.lang.Integer> sessionsWithTimeouts)
      save the datatree and the sessions into a snapshot
      void setServerStats​(ServerStats serverStats)  
      boolean truncateLog​(long zxid)
      truncate the transaction logs the zxid specified
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileTxnSnapLog

        public FileTxnSnapLog​(java.io.File dataDir,
                              java.io.File snapDir)
                       throws java.io.IOException
        the constructor which takes the datadir and snapdir.
        Parameters:
        dataDir - the trasaction directory
        snapDir - the snapshot directory
        Throws:
        java.io.IOException
    • Method Detail

      • setServerStats

        public void setServerStats​(ServerStats serverStats)
      • getDataDir

        public java.io.File getDataDir()
        get the datadir used by this filetxn snap log
        Returns:
        the data dir
      • getSnapDir

        public java.io.File getSnapDir()
        get the snap dir used by this filetxn snap log
        Returns:
        the snap dir
      • restore

        public long restore​(DataTree dt,
                            java.util.Map<java.lang.Long,​java.lang.Integer> sessions,
                            FileTxnSnapLog.PlayBackListener listener)
                     throws java.io.IOException
        this function restores the server database after reading from the snapshots and transaction logs
        Parameters:
        dt - the datatree to be restored
        sessions - the sessions to be restored
        listener - the playback listener to run on the database restoration
        Returns:
        the highest zxid restored
        Throws:
        java.io.IOException
      • fastForwardFromEdits

        public long fastForwardFromEdits​(DataTree dt,
                                         java.util.Map<java.lang.Long,​java.lang.Integer> sessions,
                                         FileTxnSnapLog.PlayBackListener listener)
                                  throws java.io.IOException
        This function will fast forward the server database to have the latest transactions in it. This is the same as restore, but only reads from the transaction logs and not restores from a snapshot.
        Parameters:
        dt - the datatree to write transactions to.
        sessions - the sessions to be restored.
        listener - the playback listener to run on the database transactions.
        Returns:
        the highest zxid restored.
        Throws:
        java.io.IOException
      • processTransaction

        public void processTransaction​(TxnHeader hdr,
                                       DataTree dt,
                                       java.util.Map<java.lang.Long,​java.lang.Integer> sessions,
                                       org.apache.jute.Record txn)
                                throws KeeperException.NoNodeException
        process the transaction on the datatree
        Parameters:
        hdr - the hdr of the transaction
        dt - the datatree to apply transaction to
        sessions - the sessions to be restored
        txn - the transaction to be applied
        Throws:
        KeeperException.NoNodeException
      • getLastLoggedZxid

        public long getLastLoggedZxid()
        the last logged zxid on the transaction logs
        Returns:
        the last logged zxid
      • save

        public void save​(DataTree dataTree,
                         java.util.concurrent.ConcurrentHashMap<java.lang.Long,​java.lang.Integer> sessionsWithTimeouts)
                  throws java.io.IOException
        save the datatree and the sessions into a snapshot
        Parameters:
        dataTree - the datatree to be serialized onto disk
        sessionsWithTimeouts - the sesssion timeouts to be serialized onto disk
        Throws:
        java.io.IOException
      • truncateLog

        public boolean truncateLog​(long zxid)
                            throws java.io.IOException
        truncate the transaction logs the zxid specified
        Parameters:
        zxid - the zxid to truncate the logs to
        Returns:
        true if able to truncate the log, false if not
        Throws:
        java.io.IOException
      • findMostRecentSnapshot

        public java.io.File findMostRecentSnapshot()
                                            throws java.io.IOException
        the most recent snapshot in the snapshot directory
        Returns:
        the file that contains the most recent snapshot
        Throws:
        java.io.IOException
      • findNRecentSnapshots

        public java.util.List<java.io.File> findNRecentSnapshots​(int n)
                                                          throws java.io.IOException
        the n most recent snapshots
        Parameters:
        n - the number of recent snapshots
        Returns:
        the list of n most recent snapshots, with the most recent in front
        Throws:
        java.io.IOException
      • getSnapshotLogs

        public java.io.File[] getSnapshotLogs​(long zxid)
        get the snapshot logs which may contain transactions newer than the given zxid. This includes logs with starting zxid greater than given zxid, as well as the newest transaction log with starting zxid less than given zxid. The latter log file may contain transactions beyond given zxid.
        Parameters:
        zxid - the zxid that contains logs greater than zxid
        Returns:
      • append

        public boolean append​(Request si)
                       throws java.io.IOException
        append the request to the transaction logs
        Parameters:
        si - the request to be appended returns true iff something appended, otw false
        Throws:
        java.io.IOException
      • commit

        public void commit()
                    throws java.io.IOException
        commit the transaction of logs
        Throws:
        java.io.IOException
      • rollLog

        public void rollLog()
                     throws java.io.IOException
        roll the transaction logs
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        close the transaction log files
        Throws:
        java.io.IOException