Package com.mckoi.store
Class JournalledSystem
- java.lang.Object
-
- com.mckoi.store.JournalledSystem
-
class JournalledSystem extends java.lang.Object
Manages 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 class
JournalledSystem.AbstractResource
An abstract resource.private static class
JournalledSystem.JournalEntry
A JournalEntry represents a modification that has been logging in the journal for a specific page of a resource.private class
JournalledSystem.JournalFile
A JournalFile represents a file in which modification are logged out to when changes are made.private class
JournalledSystem.JournalingThread
Thread that persists the journal in the backgroudn.private static class
JournalledSystem.JournalSummary
Summary information about a journal.private class
JournalledSystem.NonLoggingResource
An implementation of AbstractResource that doesn't log.private class
JournalledSystem.Resource
Represents a resource in this system.
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap
all_resources
The map of all resources that are available.private DebugLogger
debug
A debug log to output information to.private boolean
ENABLE_LOGGING
Set to true for logging behaviour.private java.lang.Object
init_lock
private java.util.ArrayList
journal_archives
The archive of journal files currently pending (JournalFile).private java.util.Comparator
journal_list_comparator
private long
journal_number
The current journal file number.private java.io.File
journal_path
The path to the journal files.private JournalledSystem.JournalingThread
journaling_thread
A thread that runs in the background and persists information that is in the journal.private int
page_size
The page size.private boolean
read_only
If the journal system is in read only mode.private LoggingBufferManager.StoreDataAccessorFactory
sda_factory
A factory that creates StoreDataAccessor objects used to access the resource with the given name.private long
seq_id
The unique sequence id counter for this session.private JournalledSystem.JournalFile
top_journal_file
The current top journal file.private java.lang.Object
top_journal_lock
Mutex 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 JournalledResource
createResource(java.lang.String resource_name)
Creates a resource.private static java.lang.String
getJournalFileName(int number)
Returns a journal file name with the given number.private JournalledSystem.AbstractResource
getResource(java.lang.String resource_name)
Returns the Resource with the given name.private void
newTopJournalFile()
Creates a new top journal file.(package private) void
rollForwardRecover()
Recovers any lost operations that are currently in the journal.(package private) void
setCheckPoint(boolean flush_journals)
Sets a check point in the log.(package private) void
start()
Starts the journal system.(package private) void
stop()
Stops the journal system.private JournalledSystem.JournalFile
topJournal()
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.IOException
Starts 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.IOException
Recovers 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.IOException
Creates 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.IOException
Sets 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.
-
-