Class FileSnap
- java.lang.Object
-
- org.apache.zookeeper.server.persistence.FileSnap
-
-
Field Summary
Fields Modifier and Type Field Description static int
SNAP_MAGIC
static String
SNAPSHOT_FILE_PREFIX
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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 inputarchiveFile
findMostRecentSnapshot()
find the most recent snapshot in the database.List<File>
findNRecentSnapshots(int n)
find the last n snapshots.protected List<File>
findNValidSnapshots(int n)
find the last (maybe) valid n snapshots.SnapshotInfo
getLastSnapshotInfo()
get information of the last saved/restored snapshotvoid
serialize(DataTree dt, Map<Long,Integer> sessions, File snapShot, boolean fsync)
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 Detail
-
SNAP_MAGIC
public static final int SNAP_MAGIC
-
SNAPSHOT_FILE_PREFIX
public static final String SNAPSHOT_FILE_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getLastSnapshotInfo
public SnapshotInfo getLastSnapshotInfo()
get information of the last saved/restored snapshot- Specified by:
getLastSnapshotInfo
in interfaceSnapShot
- 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 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 IOException
deserialize 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
public File findMostRecentSnapshot()
find the most recent snapshot in the database.- Specified by:
findMostRecentSnapshot
in interfaceSnapShot
- 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 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 IOException
serialize 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
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 interfaceSnapShot
- Throws:
IOException
-
-