class PersistentStore extends Object
Modifier and Type | Field and Description |
---|---|
private static ThreadLocal |
lockState
Thread local that tracks if (and how many times) the current thread
has acquired a non-exclusive mutator lock.
|
private ReliableLog |
log
Object we use to reliably and persistently log updates to our
state, or null if not persistent.
|
private static Logger |
logger
Logger for logging messages for this class
|
private LogHandler |
logHandler
Object that handles the recovery of logs, or null if not persistent
|
private ReadersWriter |
mutatorLock
No mutation of persistent state can occur during a snapshot,
however, we can have multiple mutators, use
ReadersWriter object to manage this invariant. |
private NormServerBaseImpl |
server
The NormServer we are part of
|
private File |
storeLocation
Location of the persistent store, or null if not persistent
|
private List |
subStores
A list of all of the sub-stores
|
private int |
updateCount
Number of updates since last snapshot
|
private static Long |
zero
Cache a
Long object with a zero value |
Constructor and Description |
---|
PersistentStore(String logDir,
LogHandler logHandler,
NormServerBaseImpl server)
Construct a store that will persist its data to the specified
directory.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
acquireMutatorLock()
Block until we can acquire a non-exclusive mutator lock on the
server's persistent state.
|
(package private) void |
addSubStore(SubStore subStore)
Inform the store of a sub-store
|
(package private) void |
destroy()
Destroy the store.
|
(package private) void |
releaseMutatorLock()
Release one level of mutator locks if this thread holds at least one.
|
(package private) void |
snapshot()
Generate a snapshot, will perform the necessary locking to ensure no
threads are mutating the state of the server before creating the
snapshot.
|
(package private) void |
update(Object o)
Log an update.
|
private static final Logger logger
private ReliableLog log
private final ReadersWriter mutatorLock
ReadersWriter
object to manage this invariant. Note
as far as the lock is concerned the mutators are the readers and
snapshot thread the writer since for us mutation is the
non-exclusive operation.private static final ThreadLocal lockState
private static final Long zero
Long
object with a zero valueprivate final File storeLocation
private final LogHandler logHandler
private final NormServerBaseImpl server
private int updateCount
private List subStores
PersistentStore(String logDir, LogHandler logHandler, NormServerBaseImpl server) throws StoreException
logDir
- directory where the store should persist its data,
which must exist, unless it is null
, in which case
there is no persistencelogHandler
- object that will process the log and last
snapshot to recover the server's stateserver
- the server is called back after an update so it can
decide whether or not to do a snapshotStoreException
- if there is a problem setting up the storevoid destroy() throws IOException
IOException
- if it has difficulty removing the log filesvoid addSubStore(SubStore subStore) throws StoreException
StoreException
void acquireMutatorLock()
try
block and a releaseMutatorLock
call
should be placed in a finally
block.void releaseMutatorLock()
void update(Object o)
IllegalStateException
- if the current thread does not hold
a non-exclusive mutator lockIOException
ReliableLog.update(java.lang.Object)
void snapshot() throws IOException
IOException
ReliableLog.snapshot()
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.