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.ObjectA 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[]bufferSmall buffer.private longcur_seq_idThe sequence id for resources modified in this log.private StreamFiledataThe StreamFile object for reading and writing entries to/from the journal.private java.io.DataOutputStreamdata_outA DataOutputStream object used to write entries to the journal file.private java.io.FilefileThe File object of this journal in the file system.private booleanis_openTrue when open.private longjournal_numberThe journal number of this journal.private booleanread_onlyTrue if the journal file is read only.private intreference_countThe number of threads currently looking at info in this journal.private java.util.HashMapresource_id_mapA 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) voidaddReference()Adds a reference preventing the journal file from being deleted.(package private) voidbuildPage(long in_page_number, long position, byte[] buf, int off)Reconstructs a modification that is logged in this journal.(package private) voidclose()Closes the journal file.(package private) voidcloseAndDelete()Closes and deletes the journal file.(package private) voidflushAndSynch()Synchronizes the log.(package private) longgetJournalNumber()Returns the journal number assigned to this journal.(package private) booleanisDeleted()Returns true if the journal is deleted.(package private) JournalledSystem.JournalEntrylogPageModification(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) voidlogResourceDelete(java.lang.String resource_name)Logs that a resource was deleted.(package private) voidlogResourceSizeChange(java.lang.String resource_name, long new_size)Logs a resource size change.(package private) voidopen(long journal_number)Opens the journal file.(package private) JournalledSystem.JournalSummaryopenForRecovery()Opens the journal for recovery.(package private) voidpersist(long start, long end)Plays the log from the given offset in the file to the next checkpoint.(package private) voidremoveReference()Removes a reference, if we are at the last reference the journal file is deleted.(package private) voidsetCheckPoint()Sets a check point.(package private) longsize()Returns the size of the journal file in bytes.java.lang.StringtoString()private java.lang.LongwriteResourceName(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.IOExceptionCloses the journal file.- Throws:
java.io.IOException
-
isDeleted
boolean isDeleted()
Returns true if the journal is deleted.
-
closeAndDelete
void closeAndDelete() throws java.io.IOExceptionCloses 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.IOExceptionRemoves 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.IOExceptionPlays 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.IOExceptionWrites 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.IOExceptionLogs that a resource was deleted.- Throws:
java.io.IOException
-
logResourceSizeChange
void logResourceSizeChange(java.lang.String resource_name, long new_size) throws java.io.IOExceptionLogs a resource size change.- Throws:
java.io.IOException
-
setCheckPoint
void setCheckPoint() throws java.io.IOExceptionSets 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.IOExceptionReconstructs a modification that is logged in this journal.- Throws:
java.io.IOException
-
flushAndSynch
void flushAndSynch() throws java.io.IOExceptionSynchronizes the log.- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-