T
- type of record this WAL is forpublic final class MinimalLockingWriteAheadLog<T> extends java.lang.Object implements WriteAheadRepository<T>
This implementation provides as little Locking as possible in order to provide the highest throughput possible. However, this implementation is ONLY appropriate if it can be guaranteed that only a single thread will ever issue updates for a given Record at any one time.
Constructor and Description |
---|
MinimalLockingWriteAheadLog(java.nio.file.Path path,
int partitionCount,
SerDe<T> serde,
SyncListener syncListener) |
MinimalLockingWriteAheadLog(java.nio.file.Path path,
int partitionCount,
SerDeFactory<T> serdeFactory,
SyncListener syncListener) |
MinimalLockingWriteAheadLog(java.util.SortedSet<java.nio.file.Path> paths,
int partitionCount,
SerDe<T> serde,
SyncListener syncListener) |
MinimalLockingWriteAheadLog(java.util.SortedSet<java.nio.file.Path> paths,
int partitionCount,
SerDeFactory<T> serdeFactory,
SyncListener syncListener) |
Modifier and Type | Method and Description |
---|---|
int |
checkpoint()
Compacts the contents of the Repository so that rather than having a
Snapshot and an Edit Log indicating many Updates to the Snapshot, the
Snapshot is updated to contain the current state of the Repository, and
the edit log is purged.
|
java.util.Set<java.lang.String> |
getRecoveredSwapLocations()
Recovers all External Swap locations that were persisted.
|
int |
getVersion() |
java.util.Collection<T> |
recoverRecords()
Recovers all records from the persisted state.
|
void |
shutdown()
Causes the repository to checkpoint and then close any open resources.
|
int |
update(java.util.Collection<T> records,
boolean forceSync)
Updates the repository with the specified Records.
|
public MinimalLockingWriteAheadLog(java.nio.file.Path path, int partitionCount, SerDe<T> serde, SyncListener syncListener) throws java.io.IOException
java.io.IOException
public MinimalLockingWriteAheadLog(java.nio.file.Path path, int partitionCount, SerDeFactory<T> serdeFactory, SyncListener syncListener) throws java.io.IOException
java.io.IOException
public MinimalLockingWriteAheadLog(java.util.SortedSet<java.nio.file.Path> paths, int partitionCount, SerDe<T> serde, SyncListener syncListener) throws java.io.IOException
java.io.IOException
public MinimalLockingWriteAheadLog(java.util.SortedSet<java.nio.file.Path> paths, int partitionCount, SerDeFactory<T> serdeFactory, SyncListener syncListener) throws java.io.IOException
paths
- a sorted set of Paths to use for the partitions/journals and
the snapshot. The snapshot will always be written to the first path
specified.partitionCount
- the number of partitions/journals to use. For best
performance, this should be close to the number of threads that are
expected to update the repository simultaneouslyserdeFactory
- the factory for the serializer/deserializer for recordssyncListener
- the listenerjava.io.IOException
- if unable to initialize due to IO issuepublic int update(java.util.Collection<T> records, boolean forceSync) throws java.io.IOException
WriteAheadRepository
Updates the repository with the specified Records. The Collection must not contain multiple records with the same ID
update
in interface WriteAheadRepository<T>
records
- the records to updateforceSync
- specifies whether or not the Repository forces the data
to be flushed to disk. If false, the data may be stored in Operating
System buffers, which improves performance but could cause loss of data
if power is lost or the Operating System crashesjava.io.IOException
- if failure to update repopublic java.util.Collection<T> recoverRecords() throws java.io.IOException
WriteAheadRepository
Recovers all records from the persisted state. This method must be called before any updates are issued to the Repository.
recoverRecords
in interface WriteAheadRepository<T>
java.io.IOException
- if failure to read from repopublic java.util.Set<java.lang.String> getRecoveredSwapLocations() throws java.io.IOException
WriteAheadRepository
Recovers all External Swap locations that were persisted. If this method
is to be called, it must be called AFTER WriteAheadRepository.recoverRecords()
and
BEFORE update
.
getRecoveredSwapLocations
in interface WriteAheadRepository<T>
java.io.IOException
- if failure reading swap locationspublic int checkpoint() throws java.io.IOException
WriteAheadRepository
Compacts the contents of the Repository so that rather than having a Snapshot and an Edit Log indicating many Updates to the Snapshot, the Snapshot is updated to contain the current state of the Repository, and the edit log is purged.
checkpoint
in interface WriteAheadRepository<T>
java.io.IOException
- if failure during checkpointpublic void shutdown() throws java.io.IOException
WriteAheadRepository
Causes the repository to checkpoint and then close any open resources.
shutdown
in interface WriteAheadRepository<T>
java.io.IOException
- if failure to shutdown cleanlypublic int getVersion()