The secondary storage strategy is to record values in files using a representation of the caller's choosing. Two sorts of files are kept: snapshots and logs. At any instant, one snapshot is current. The log consists of a sequence of updates that have occurred since the current snapshot was taken. The current stable state is the value of the snapshot, as modified by the sequence of updates in the log. From time to time, the client of a ReliableLog instructs the package to make a new snapshot and clear the log. A ReliableLog arranges disk writes such that updates are stable (as long as the changes are force-written to disk) and atomic : no update is lost, and each update either is recorded completely in the log or not at all. Making a new snapshot is also atomic.
Normal use for maintaining the recoverable store is as follows: The client maintains the relevant data structure in virtual memory. As updates happen to the structure, the client informs the ReliableLog (all it "log") by calling log.update. Periodically, the client calls log.snapshot to provide the current value of the data structure. On restart, the client calls log.recover to obtain the latest snapshot and the following sequences of updates; the client applies the updates to the snapshot to obtain the state that existed before the crash.
The current logfile format is:
LogHandler
| Modifier and Type | Class and Description |
|---|---|
| public static class | ReliableLog.
ReliableLog's log file implementation. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private File | |
| private static long | |
| private LogHandler | |
| private final byte[] | |
| private static int | |
| private long | |
| private long | |
| private ReliableLog. | |
| private long | |
| private static final Constructor | logClassConstructor
Constructor for the log file. |
| private int | |
| private static String | |
| private String | |
| private int | |
| private int | |
| private static String | |
| public static final int | |
| public static final int | |
| private long | |
| private static String | |
| private int | |
| private static String |
| Access | Constructor and Description |
|---|---|
| public | ReliableLog(String
path to the stable storage directory dirPath, LogHandler the closure object containing callbacks for logging and
recovery handler, boolean ignored pad)Creates a ReliableLog to handle checkpoints and logging in a stable storage directory. |
| public | ReliableLog(String
path to the stable storage directory dirPath, LogHandler the closure object containing callbacks for logging and
recovery handler)Creates a ReliableLog to handle checkpoints and logging in a stable storage directory. |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private String | |
| private static Constructor | getLogClassConstructor()
Returns the constructor for the log file if the system property sun.rmi.log.class is non-null and the class specified by the property a) can be loaded, b) is a subclass of LogFile, and c) has a public two-arg constructor (String, String); otherwise returns null. |
| private void | |
| private void | |
| private void | initializeLogFile()
Creates a new log file, truncated and initialized with the format version number preferred by this implementation. |
| public long | |
| private void | openLogFile(boolean
if true and file exists, file is truncated to zero
length truncate)Opens the log file in read/write mode. |
| private int | Returns: the versionthe name of the version file name)Reads version number from a file. |
| public synchronized Object | |
| private Object | Returns: the resulting state of the object after all updatesthe most recent snapshot state)Applies outstanding updates to the snapshot. |
| public synchronized void | |
| public long | |
| public synchronized void | |
| public synchronized void | |
| private String | versionName(String
version file name name)Generates a version 0 filename prepended with the stable storage directory path |
| private String | versionName(String prefix, int
a version number ver)Generates a version filename prepended with the stable storage directory path with the version number as a suffix. |
| private void | writeInt(DataOutput
output stream out, int int value val)Write an int value in single write operation. |
| private void | writeVersionFile(boolean
if true, writes to a new version file newVersion)Writes out version number to file. |
| Debug | back to summary |
|---|---|
| private boolean Debug | |
| dir | back to summary |
|---|---|
| private File dir | |
| diskPageSize | back to summary |
|---|---|
| private static long diskPageSize | |
| handler | back to summary |
|---|---|
| private LogHandler handler | |
| intBuf | back to summary |
|---|---|
| private final byte[] intBuf | |
| intBytes | back to summary |
|---|---|
| private static int intBytes | |
| lastLog | back to summary |
|---|---|
| private long lastLog | |
| lastSnapshot | back to summary |
|---|---|
| private long lastSnapshot | |
| log | back to summary |
|---|---|
| private ReliableLog. | |
| logBytes | back to summary |
|---|---|
| private long logBytes | |
| logClassConstructor | back to summary |
|---|---|
| private static final Constructor<? extends ReliableLog. Constructor for the log file. If the system property sun.rmi.log.class is non-null and the class specified by this property a) can be loaded, b) is a subclass of LogFile, and c) has a public two-arg constructor (String, String), ReliableLog uses the constructor to construct the LogFile. | |
| logEntries | back to summary |
|---|---|
| private int logEntries | |
| logfilePrefix | back to summary |
|---|---|
| private static String logfilePrefix | |
| logName | back to summary |
|---|---|
| private String logName | |
| majorFormatVersion | back to summary |
|---|---|
| private int majorFormatVersion | |
| minorFormatVersion | back to summary |
|---|---|
| private int minorFormatVersion | |
| newVersionFile | back to summary |
|---|---|
| private static String newVersionFile | |
| PreferredMajorVersion | back to summary |
|---|---|
| public static final int PreferredMajorVersion | |
| PreferredMinorVersion | back to summary |
|---|---|
| public static final int PreferredMinorVersion | |
| snapshotBytes | back to summary |
|---|---|
| private long snapshotBytes | |
| snapshotPrefix | back to summary |
|---|---|
| private static String snapshotPrefix | |
| version | back to summary |
|---|---|
| private int version | |
| versionFile | back to summary |
|---|---|
| private static String versionFile | |
| ReliableLog | back to summary |
|---|---|
| public ReliableLog(String dirPath, LogHandler handler, boolean pad) throws IOException Creates a ReliableLog to handle checkpoints and logging in a stable storage directory.
| |
| ReliableLog | back to summary |
|---|---|
| public ReliableLog(String dirPath, LogHandler handler) throws IOException Creates a ReliableLog to handle checkpoints and logging in a stable storage directory.
| |
| close | back to summary |
|---|---|
| public synchronized void close() throws IOException Close the stable storage directory in an orderly manner.
| |
| commitToNewVersion | back to summary |
|---|---|
| private void commitToNewVersion() throws IOException Commits (atomically) the new version.
| |
| createFirstVersion | back to summary |
|---|---|
| private void createFirstVersion() throws IOException Creates the initial version file
| |
| deleteFile | back to summary |
|---|---|
| private void deleteFile(String name) throws IOException Delete a file.
| |
| deleteLogFile | back to summary |
|---|---|
| private void deleteLogFile(int ver) throws IOException Removes the log file.
| |
| deleteNewVersionFile | back to summary |
|---|---|
| private void deleteNewVersionFile() throws IOException Removes the new version number file.
| |
| deleteSnapshot | back to summary |
|---|---|
| private void deleteSnapshot(int ver) throws IOException Removes the snapshot file.
| |
| fName | back to summary |
|---|---|
| private String fName(String name) Generates a filename prepended with the stable storage directory path.
| |
| getLogClassConstructor | back to summary |
|---|---|
| private static Constructor Returns the constructor for the log file if the system property sun.rmi.log.class is non-null and the class specified by the property a) can be loaded, b) is a subclass of LogFile, and c) has a public two-arg constructor (String, String); otherwise returns null. | |
| getVersion | back to summary |
|---|---|
| private void getVersion() throws IOException Sets the version. If version file does not exist, the initial version file is created.
| |
| incrVersion | back to summary |
|---|---|
| private void incrVersion() Increments the directory version number. | |
| initializeLogFile | back to summary |
|---|---|
| private void initializeLogFile() throws IOException Creates a new log file, truncated and initialized with the format version number preferred by this implementation. Environment: inited, synchronized Precondition valid: log, log contains nothing useful Postcondition: if successful, log is initialised with the format version number (Preferred{Major,Minor}Version), and logBytes is set to the resulting size of the updatelog, and logEntries is set to zero. Otherwise, log is in an indeterminate state, and logBytes is unchanged, and logEntries is unchanged.
| |
| logSize | back to summary |
|---|---|
| public long logSize() Returns the size of the log file in bytes; | |
| openLogFile | back to summary |
|---|---|
| private void openLogFile(boolean truncate) throws IOException Opens the log file in read/write mode. If file does not exist, it is created.
| |
| readVersion | back to summary |
|---|---|
| private int readVersion(String name) throws IOException Reads version number from a file.
| |
| recover | back to summary |
|---|---|
| public synchronized Object recover() throws IOException Returns an object which is the value recorded in the current snapshot. This snapshot is recovered by calling the client supplied callback "recover" and then subsequently invoking the "readUpdate" callback to apply any logged updates to the state.
| |
| recoverUpdates | back to summary |
|---|---|
| private Object recoverUpdates(Object state) throws IOException Applies outstanding updates to the snapshot.
| |
| snapshot | back to summary |
|---|---|
| public synchronized void snapshot(Object value) throws IOException Records this value as the current snapshot by invoking the client supplied "snapshot" callback and then empties the log.
| |
| snapshotSize | back to summary |
|---|---|
| public long snapshotSize() Returns the size of the snapshot file in bytes; | |
| update | back to summary |
|---|---|
| public synchronized void update(Object value) throws IOException Records this update in the log file (does not force update to disk). The update is recorded by calling the client's "writeUpdate" callback. This method must not be called until this log's recover method has been invoked (and completed).
| |
| update | back to summary |
|---|---|
| public synchronized void update(Object value, boolean forceToDisk) throws IOException Records this update in the log file. The update is recorded by calling the client's writeUpdate callback. This method must not be called until this log's recover method has been invoked (and completed).
| |
| versionName | back to summary |
|---|---|
| private String versionName(String name) Generates a version 0 filename prepended with the stable storage directory path
| |
| versionName | back to summary |
|---|---|
| private String versionName(String prefix, int ver) Generates a version filename prepended with the stable storage directory path with the version number as a suffix.
| |
| writeInt | back to summary |
|---|---|
| private void writeInt(DataOutput out, int val) throws IOException Write an int value in single write operation. This method assumes that the caller is synchronized on the log file.
| |
| writeVersionFile | back to summary |
|---|---|
| private void writeVersionFile(boolean newVersion) throws IOException Writes out version number to file.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final FileDescriptor |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | checkSpansBoundary(long fp)
Returns true if writing 4 bytes starting at the specified file position, would span a 512 byte sector boundary; otherwise returns false. |
| protected void |
| fd | back to summary |
|---|---|
| private final FileDescriptor fd Hides java. | |
| LogFile | back to summary |
|---|---|
| public LogFile(String name, String mode) throws FileNotFoundException, IOException Constructs a LogFile and initializes the file descriptor. | |
| checkSpansBoundary | back to summary |
|---|---|
| protected boolean checkSpansBoundary(long fp) Returns true if writing 4 bytes starting at the specified file position, would span a 512 byte sector boundary; otherwise returns false. | |
| sync | back to summary |
|---|---|
| protected void sync() throws IOException Invokes sync on the file descriptor for this log file. | |