Package com.mckoi.store
Class JournalledSystem
- java.lang.Object
-
- com.mckoi.store.JournalledSystem
-
class JournalledSystem extends java.lang.ObjectManages a journalling data store management system. All operations are written out to a log that can be easily recovered from if a crash occurs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classJournalledSystem.AbstractResourceAn abstract resource.private static classJournalledSystem.JournalEntryA JournalEntry represents a modification that has been logging in the journal for a specific page of a resource.private classJournalledSystem.JournalFileA JournalFile represents a file in which modification are logged out to when changes are made.private classJournalledSystem.JournalingThreadThread that persists the journal in the backgroudn.private static classJournalledSystem.JournalSummarySummary information about a journal.private classJournalledSystem.NonLoggingResourceAn implementation of AbstractResource that doesn't log.private classJournalledSystem.ResourceRepresents a resource in this system.
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMapall_resourcesThe map of all resources that are available.private DebugLoggerdebugA debug log to output information to.private booleanENABLE_LOGGINGSet to true for logging behaviour.private java.lang.Objectinit_lockprivate java.util.ArrayListjournal_archivesThe archive of journal files currently pending (JournalFile).private java.util.Comparatorjournal_list_comparatorprivate longjournal_numberThe current journal file number.private java.io.Filejournal_pathThe path to the journal files.private JournalledSystem.JournalingThreadjournaling_threadA thread that runs in the background and persists information that is in the journal.private intpage_sizeThe page size.private booleanread_onlyIf the journal system is in read only mode.private LoggingBufferManager.StoreDataAccessorFactorysda_factoryA factory that creates StoreDataAccessor objects used to access the resource with the given name.private longseq_idThe unique sequence id counter for this session.private JournalledSystem.JournalFiletop_journal_fileThe current top journal file.private java.lang.Objecttop_journal_lockMutex when accessing the top journal file.
-
Constructor Summary
Constructors Constructor Description JournalledSystem(java.io.File journal_path, boolean read_only, int page_size, LoggingBufferManager.StoreDataAccessorFactory sda_factory, DebugLogger debug, boolean enable_logging)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JournalledResourcecreateResource(java.lang.String resource_name)Creates a resource.private static java.lang.StringgetJournalFileName(int number)Returns a journal file name with the given number.private JournalledSystem.AbstractResourcegetResource(java.lang.String resource_name)Returns the Resource with the given name.private voidnewTopJournalFile()Creates a new top journal file.(package private) voidrollForwardRecover()Recovers any lost operations that are currently in the journal.(package private) voidsetCheckPoint(boolean flush_journals)Sets a check point in the log.(package private) voidstart()Starts the journal system.(package private) voidstop()Stops the journal system.private JournalledSystem.JournalFiletopJournal()Returns the current top journal file.
-
-
-
Field Detail
-
ENABLE_LOGGING
private final boolean ENABLE_LOGGING
Set to true for logging behaviour.
-
journal_path
private final java.io.File journal_path
The path to the journal files.
-
read_only
private final boolean read_only
If the journal system is in read only mode.
-
page_size
private final int page_size
The page size.
-
all_resources
private java.util.HashMap all_resources
The map of all resources that are available. (resource_name -> Resource)
-
seq_id
private long seq_id
The unique sequence id counter for this session.
-
journal_archives
private final java.util.ArrayList journal_archives
The archive of journal files currently pending (JournalFile).
-
top_journal_file
private JournalledSystem.JournalFile top_journal_file
The current top journal file.
-
journal_number
private long journal_number
The current journal file number.
-
sda_factory
private final LoggingBufferManager.StoreDataAccessorFactory sda_factory
A factory that creates StoreDataAccessor objects used to access the resource with the given name.
-
top_journal_lock
private final java.lang.Object top_journal_lock
Mutex when accessing the top journal file.
-
journaling_thread
private JournalledSystem.JournalingThread journaling_thread
A thread that runs in the background and persists information that is in the journal.
-
debug
private final DebugLogger debug
A debug log to output information to.
-
init_lock
private final java.lang.Object init_lock
-
journal_list_comparator
private java.util.Comparator journal_list_comparator
-
-
Constructor Detail
-
JournalledSystem
JournalledSystem(java.io.File journal_path, boolean read_only, int page_size, LoggingBufferManager.StoreDataAccessorFactory sda_factory, DebugLogger debug, boolean enable_logging)
-
-
Method Detail
-
getJournalFileName
private static java.lang.String getJournalFileName(int number)
Returns a journal file name with the given number. The journal number must be between 10 and 63
-
start
void start() throws java.io.IOExceptionStarts the journal system.- Throws:
java.io.IOException
-
stop
void stop() throws java.io.IOException
Stops the journal system. This will persist any pending changes up to the last check point and then finish.- Throws:
java.io.IOException
-
rollForwardRecover
void rollForwardRecover() throws java.io.IOExceptionRecovers any lost operations that are currently in the journal. This retries all logged entries. This would typically be called before any other IO operations.- Throws:
java.io.IOException
-
newTopJournalFile
private void newTopJournalFile() throws java.io.IOExceptionCreates a new top journal file.- Throws:
java.io.IOException
-
topJournal
private JournalledSystem.JournalFile topJournal()
Returns the current top journal file.
-
createResource
public JournalledResource createResource(java.lang.String resource_name)
Creates a resource.
-
setCheckPoint
void setCheckPoint(boolean flush_journals) throws java.io.IOExceptionSets a check point in the log. If 'flush_journals' is true then when the method returns we are guarenteed that all the journals are flushed and the data is absolutely current. If 'flush_journals' is false then we can't assume the journals will be empty when the method returns.- Throws:
java.io.IOException
-
getResource
private JournalledSystem.AbstractResource getResource(java.lang.String resource_name)
Returns the Resource with the given name.
-
-