Class FileSnap
java.lang.Object
org.apache.zookeeper.server.persistence.FileSnap
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
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 flaglong
deserialize
(DataTree dt, Map<Long, Integer> sessions) deserialize a data tree from the most recent snapshotstatic void
deserialize
(DataTree dt, Map<Long, Integer> sessions, InputArchive ia) deserialize the datatree from an inputarchivefind the most recent snapshot in the database.findNRecentSnapshots
(int n) find the last n snapshots.findNValidSnapshots
(int n) find the last (maybe) valid n snapshots.get information of the last saved/restored snapshotvoid
serialize the datatree and session into the file snapshotprotected void
serialize
(DataTree dt, Map<Long, Integer> sessions, OutputArchive oa, FileHeader header) serialize the datatree and sessions
-
Field Details
-
SNAP_MAGIC
public static final int SNAP_MAGIC -
SNAPSHOT_FILE_PREFIX
- See Also:
-
-
Constructor Details
-
FileSnap
-
-
Method Details
-
getLastSnapshotInfo
get information of the last saved/restored snapshot- Specified by:
getLastSnapshotInfo
in interfaceSnapShot
- Returns:
- info of last snapshot
-
deserialize
deserialize a data tree from the most recent snapshot- Specified by:
deserialize
in interfaceSnapShot
- Parameters:
dt
- the datatree to be deserialized intosessions
- 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 IOExceptiondeserialize the datatree from an inputarchive- Parameters:
dt
- the datatree to be serialized intosessions
- the sessions to be filled upia
- the input archive to restore from- Throws:
IOException
-
findMostRecentSnapshot
find the most recent snapshot in the database.- Specified by:
findMostRecentSnapshot
in interfaceSnapShot
- Returns:
- the file containing the most recent snapshot
-
findNValidSnapshots
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
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 IOExceptionserialize the datatree and sessions- Parameters:
dt
- the datatree to be serializedsessions
- the sessions to be serializedoa
- the output archive to serialize intoheader
- the header of this snapshot- Throws:
IOException
-
serialize
public void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot, boolean fsync) throws IOExceptionserialize the datatree and session into the file snapshot- Specified by:
serialize
in interfaceSnapShot
- Parameters:
dt
- the datatree to be serializedsessions
- the sessions to be serializedsnapShot
- the file to store snapshot intofsync
- sync the file immediately after write- Throws:
IOException
-
close
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 interfaceSnapShot
- Throws:
IOException
-