Package com.mckoi.store
Class JournalledSystem.JournalFile
- java.lang.Object
-
- com.mckoi.store.JournalledSystem.JournalFile
-
- Enclosing class:
- JournalledSystem
private final class JournalledSystem.JournalFile extends java.lang.Object
A JournalFile represents a file in which modification are logged out to when changes are made. A JournalFile contains instructions for rebuilding a resource to a known stable state.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
buffer
Small buffer.private long
cur_seq_id
The sequence id for resources modified in this log.private StreamFile
data
The StreamFile object for reading and writing entries to/from the journal.private java.io.DataOutputStream
data_out
A DataOutputStream object used to write entries to the journal file.private java.io.File
file
The File object of this journal in the file system.private boolean
is_open
True when open.private long
journal_number
The journal number of this journal.private boolean
read_only
True if the journal file is read only.private int
reference_count
The number of threads currently looking at info in this journal.private java.util.HashMap
resource_id_map
A map between a resource name and an id for this journal file.
-
Constructor Summary
Constructors Constructor Description JournalFile(java.io.File file, boolean read_only)
Constructs the journal file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addReference()
Adds a reference preventing the journal file from being deleted.(package private) void
buildPage(long in_page_number, long position, byte[] buf, int off)
Reconstructs a modification that is logged in this journal.(package private) void
close()
Closes the journal file.(package private) void
closeAndDelete()
Closes and deletes the journal file.(package private) void
flushAndSynch()
Synchronizes the log.(package private) long
getJournalNumber()
Returns the journal number assigned to this journal.(package private) boolean
isDeleted()
Returns true if the journal is deleted.(package private) JournalledSystem.JournalEntry
logPageModification(java.lang.String resource_name, long page_number, byte[] buf, int off, int len)
Logs a page modification to the end of the log and returns a pointer in the file to the modification.(package private) void
logResourceDelete(java.lang.String resource_name)
Logs that a resource was deleted.(package private) void
logResourceSizeChange(java.lang.String resource_name, long new_size)
Logs a resource size change.(package private) void
open(long journal_number)
Opens the journal file.(package private) JournalledSystem.JournalSummary
openForRecovery()
Opens the journal for recovery.(package private) void
persist(long start, long end)
Plays the log from the given offset in the file to the next checkpoint.(package private) void
removeReference()
Removes a reference, if we are at the last reference the journal file is deleted.(package private) void
setCheckPoint()
Sets a check point.(package private) long
size()
Returns the size of the journal file in bytes.java.lang.String
toString()
private java.lang.Long
writeResourceName(java.lang.String resource_name, java.io.DataOutputStream out)
Writes a resource identifier to the stream for the resource with the given name.
-
-
-
Field Detail
-
file
private java.io.File file
The File object of this journal in the file system.
-
read_only
private boolean read_only
True if the journal file is read only.
-
data
private StreamFile data
The StreamFile object for reading and writing entries to/from the journal.
-
data_out
private java.io.DataOutputStream data_out
A DataOutputStream object used to write entries to the journal file.
-
buffer
private byte[] buffer
Small buffer.
-
resource_id_map
private java.util.HashMap resource_id_map
A map between a resource name and an id for this journal file.
-
cur_seq_id
private long cur_seq_id
The sequence id for resources modified in this log.
-
journal_number
private long journal_number
The journal number of this journal.
-
is_open
private boolean is_open
True when open.
-
reference_count
private int reference_count
The number of threads currently looking at info in this journal.
-
-
Method Detail
-
size
long size()
Returns the size of the journal file in bytes.
-
getJournalNumber
long getJournalNumber()
Returns the journal number assigned to this journal.
-
open
void open(long journal_number) throws java.io.IOException
Opens the journal file. If the journal file exists then an error is generated.- Throws:
java.io.IOException
-
openForRecovery
JournalledSystem.JournalSummary openForRecovery() throws java.io.IOException
Opens the journal for recovery. This scans the journal and generates some statistics about the journal file such as the last check point and the journal number. If the journal file doesn't exist then an error is generated.- Throws:
java.io.IOException
-
close
void close() throws java.io.IOException
Closes the journal file.- Throws:
java.io.IOException
-
isDeleted
boolean isDeleted()
Returns true if the journal is deleted.
-
closeAndDelete
void closeAndDelete() throws java.io.IOException
Closes and deletes the journal file. This may not immediately close and delete the journal file if there are currently references to it (for example, in the middle of a read operation).- Throws:
java.io.IOException
-
addReference
void addReference()
Adds a reference preventing the journal file from being deleted.
-
removeReference
void removeReference() throws java.io.IOException
Removes a reference, if we are at the last reference the journal file is deleted.- Throws:
java.io.IOException
-
persist
void persist(long start, long end) throws java.io.IOException
Plays the log from the given offset in the file to the next checkpoint. This will actually persist the log. Returns -1 if the end of the journal is reached.NOTE: This will not verify that the journal is correct. Verification should be done before the persist.
- Throws:
java.io.IOException
-
writeResourceName
private java.lang.Long writeResourceName(java.lang.String resource_name, java.io.DataOutputStream out) throws java.io.IOException
Writes a resource identifier to the stream for the resource with the given name.- Throws:
java.io.IOException
-
logResourceDelete
void logResourceDelete(java.lang.String resource_name) throws java.io.IOException
Logs that a resource was deleted.- Throws:
java.io.IOException
-
logResourceSizeChange
void logResourceSizeChange(java.lang.String resource_name, long new_size) throws java.io.IOException
Logs a resource size change.- Throws:
java.io.IOException
-
setCheckPoint
void setCheckPoint() throws java.io.IOException
Sets a check point. This will add an entry to the log.- Throws:
java.io.IOException
-
logPageModification
JournalledSystem.JournalEntry logPageModification(java.lang.String resource_name, long page_number, byte[] buf, int off, int len) throws java.io.IOException
Logs a page modification to the end of the log and returns a pointer in the file to the modification.- Throws:
java.io.IOException
-
buildPage
void buildPage(long in_page_number, long position, byte[] buf, int off) throws java.io.IOException
Reconstructs a modification that is logged in this journal.- Throws:
java.io.IOException
-
flushAndSynch
void flushAndSynch() throws java.io.IOException
Synchronizes the log.- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-