Class FileSnap

  • All Implemented Interfaces:
    SnapShot

    public class FileSnap
    extends Object
    implements SnapShot
    This class implements the snapshot interface. it is responsible for storing, serializing and deserializing the right snapshot. and provides access to the snapshots.
    • Field Detail

      • SNAP_MAGIC

        public static final int SNAP_MAGIC
    • Constructor Detail

    • Method Detail

      • getLastSnapshotInfo

        public SnapshotInfo getLastSnapshotInfo()
        get information of the last saved/restored snapshot
        Specified by:
        getLastSnapshotInfo in interface SnapShot
        Returns:
        info of last snapshot
      • deserialize

        public long deserialize​(DataTree dt,
                                Map<Long,​Integer> sessions)
                         throws IOException
        deserialize a data tree from the most recent snapshot
        Specified by:
        deserialize in interface SnapShot
        Parameters:
        dt - the datatree to be deserialized into
        sessions - the sessions to be deserialized into
        Returns:
        the zxid of the snapshot
        Throws:
        IOException
      • deserialize

        public static void deserialize​(DataTree dt,
                                       Map<Long,​Integer> sessions,
                                       InputArchive ia)
                                throws IOException
        deserialize the datatree from an inputarchive
        Parameters:
        dt - the datatree to be serialized into
        sessions - the sessions to be filled up
        ia - the input archive to restore from
        Throws:
        IOException
      • findMostRecentSnapshot

        public File findMostRecentSnapshot()
        find the most recent snapshot in the database.
        Specified by:
        findMostRecentSnapshot in interface SnapShot
        Returns:
        the file containing the most recent snapshot
      • findNValidSnapshots

        protected List<File> findNValidSnapshots​(int n)
        find the last (maybe) valid n snapshots. this does some minor checks on the validity of the snapshots. It just checks for / at the end of the snapshot. This does not mean that the snapshot is truly valid but is valid with a high probability. also, the most recent will be first on the list.
        Parameters:
        n - the number of most recent snapshots
        Returns:
        the last n snapshots (the number might be less than n in case enough snapshots are not available).
      • findNRecentSnapshots

        public List<File> findNRecentSnapshots​(int n)
                                        throws IOException
        find the last n snapshots. this does not have any checks if the snapshot might be valid or not
        Parameters:
        n - the number of most recent snapshots
        Returns:
        the last n snapshots
        Throws:
        IOException
      • serialize

        protected void serialize​(DataTree dt,
                                 Map<Long,​Integer> sessions,
                                 OutputArchive oa,
                                 FileHeader header)
                          throws IOException
        serialize the datatree and sessions
        Parameters:
        dt - the datatree to be serialized
        sessions - the sessions to be serialized
        oa - the output archive to serialize into
        header - the header of this snapshot
        Throws:
        IOException
      • serialize

        public void serialize​(DataTree dt,
                              Map<Long,​Integer> sessions,
                              File snapShot,
                              boolean fsync)
                       throws IOException
        serialize the datatree and session into the file snapshot
        Specified by:
        serialize in interface SnapShot
        Parameters:
        dt - the datatree to be serialized
        sessions - the sessions to be serialized
        snapShot - the file to store snapshot into
        fsync - sync the file immediately after write
        Throws:
        IOException
      • close

        public void close()
                   throws IOException
        synchronized close just so that if serialize is in place the close operation will block and will wait till serialize is done and will set the close flag
        Specified by:
        close in interface SnapShot
        Throws:
        IOException