|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjournal.io.api.Journal
public class Journal
Journal implementation based on append-only rotating logs and checksummed
records, with concurrent writes and reads, dynamic batching and logs
compaction.
Journal records can be written, read and deleted by
providing a Location object.
The whole Journal can be
replayed forward or backward by simply obtaining a redo or undo iterable and
going through it in a for-each block.
| Nested Class Summary | |
|---|---|
static class |
Journal.ReadType
|
static class |
Journal.WriteType
|
| Constructor Summary | |
|---|---|
Journal()
|
|
| Method Summary | |
|---|---|
void |
close()
Close the journal. |
void |
compact()
Compact the journal, reducing size of logs containing deleted entries and completely removing empty (with only deleted entries) logs. |
void |
delete(Location location)
Delete the record at the given Location.Deletes cause first a batch sync and always are logical: records will be actually deleted at log cleanup time. |
File |
getDirectory()
Get the journal directory containing log files. |
File |
getDirectoryArchive()
Get the optional archive directory used to archive cleaned up log files. |
long |
getDisposeInterval()
Get the milliseconds interval for resources disposal. |
String |
getFilePrefix()
Get the prefix for log files. |
Set<File> |
getFiles()
Get the files part of this journal. |
String |
getFileSuffix()
Get the suffix for log files. |
int |
getMaxFileLength()
Get the max length of each log file. |
int |
getMaxWriteBatchSize()
Get the max size in bytes of the write batch: must always be equal or less than the max file length. |
ReplicationTarget |
getReplicationTarget()
Get the ReplicationTarget to replicate batch writes to. |
boolean |
isArchiveFiles()
Return true if cleaned up log files should be archived, false otherwise. |
boolean |
isChecksum()
Return true if records checksum is enabled, false otherwise. |
boolean |
isPhysicalSync()
Return true if every disk write is followed by a physical disk sync, synchronizing file descriptor properties and flushing hardware buffers, false otherwise. |
void |
open()
Open the journal, eventually recovering it if already existent. |
byte[] |
read(Location location,
Journal.ReadType read)
Read the record stored at the given Location, either by syncing
with the disk state (if ReadType.SYNC) or by taking advantage of
speculative disk reads (if ReadType.ASYNC); the latter is faster,
while the former is slower but will suddenly detect deleted records. |
Iterable<Location> |
redo()
Return an iterable to replay the journal by going through all records locations. |
Iterable<Location> |
redo(Location start)
Return an iterable to replay the journal by going through all records locations starting from the given one. |
void |
setArchiveFiles(boolean archiveFiles)
Set true if cleaned up log files should be archived, false otherwise. |
void |
setChecksum(boolean checksumWrites)
Set true if records checksum is enabled, false otherwise. |
void |
setDirectory(File directory)
Set the journal directory containing log files. |
void |
setDirectoryArchive(File directoryArchive)
Set the optional archive directory used to archive cleaned up log files. |
void |
setDisposeInterval(long disposeInterval)
Set the milliseconds interval for resources disposal: i.e., un-accessed files will be closed. |
void |
setDisposer(ScheduledExecutorService disposer)
Set the ScheduledExecutorService to use for internal resources disposing. |
void |
setFilePrefix(String filePrefix)
Set the prefix for log files. |
void |
setFileSuffix(String fileSuffix)
Set the suffix for log files. |
void |
setMaxFileLength(int maxFileLength)
Set the max length of each log file. |
void |
setMaxWriteBatchSize(int maxWriteBatchSize)
Set the max size in bytes of the write batch: must always be equal or less than the max file length. |
void |
setPhysicalSync(boolean physicalSync)
Set true if every disk write must be followed by a physical disk sync, synchronizing file descriptor properties and flushing hardware buffers, false otherwise. |
void |
setRecoveryErrorHandler(RecoveryErrorHandler recoveryErrorHandler)
Set the RecoveryErrorHandler to invoke in case of checksum errors. |
void |
setReplicationTarget(ReplicationTarget replicationTarget)
Set the ReplicationTarget to replicate batch writes to. |
void |
setWriter(Executor writer)
Set the Executor to use for writing new record entries. |
void |
sync()
Sync asynchronously written records on disk. |
String |
toString()
|
void |
truncate()
Truncate the journal, removing all log files. |
Iterable<Location> |
undo()
Return an iterable to replay the journal in reverse, starting with the newest location and ending with the first. |
Iterable<Location> |
undo(Location end)
Return an iterable to replay the journal in reverse, starting with the newest location and ending with the specified end location. |
Location |
write(byte[] data,
Journal.WriteType write)
Write the given byte buffer record, either sync (if WriteType.SYNC) or async (if WriteType.ASYNC), and
returns the stored Location.A sync write causes all previously batched async writes to be synced too. |
Location |
write(byte[] data,
Journal.WriteType write,
WriteCallback callback)
Write the given byte buffer record, either sync (if WriteType.SYNC) or async (if WriteType.ASYNC), and
returns the stored Location.A sync write causes all previously batched async writes to be synced too. The provided callback will be invoked if sync is completed or if some error occurs during syncing. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Journal()
| Method Detail |
|---|
public void open()
throws IOException
IOException
public void close()
throws IOException
IOException
public void compact()
throws ClosedJournalException,
IOException
IOException
ClosedJournalException
public void sync()
throws ClosedJournalException,
IOException
IOException
ClosedJournalException
public void truncate()
throws OpenJournalException,
IOException
IOException
OpenJournalException
public byte[] read(Location location,
Journal.ReadType read)
throws ClosedJournalException,
CompactedDataFileException,
IOException
Location, either by syncing
with the disk state (if ReadType.SYNC) or by taking advantage of
speculative disk reads (if ReadType.ASYNC); the latter is faster,
while the former is slower but will suddenly detect deleted records.
location - read -
IOException
ClosedJournalException
CompactedDataFileException
public Location write(byte[] data,
Journal.WriteType write)
throws ClosedJournalException,
IOException
WriteType.SYNC) or async (if WriteType.ASYNC), and
returns the stored Location.
data - write -
IOException
ClosedJournalException
public Location write(byte[] data,
Journal.WriteType write,
WriteCallback callback)
throws ClosedJournalException,
IOException
WriteType.SYNC) or async (if WriteType.ASYNC), and
returns the stored Location.
data - write - callback -
IOException
ClosedJournalException
public void delete(Location location)
throws ClosedJournalException,
CompactedDataFileException,
IOException
Location.
location -
IOException
ClosedJournalException
CompactedDataFileException
public Iterable<Location> redo()
throws ClosedJournalException,
CompactedDataFileException,
IOException
IOException
ClosedJournalException
CompactedDataFileException
public Iterable<Location> redo(Location start)
throws ClosedJournalException,
CompactedDataFileException,
IOException
start -
IOException
CompactedDataFileException
ClosedJournalException
public Iterable<Location> undo()
throws ClosedJournalException,
CompactedDataFileException,
IOException
IOException
CompactedDataFileException
ClosedJournalException
public Iterable<Location> undo(Location end)
throws ClosedJournalException,
CompactedDataFileException,
IOException
end -
IOException
CompactedDataFileException
ClosedJournalExceptionpublic Set<File> getFiles()
public int getMaxFileLength()
public void setMaxFileLength(int maxFileLength)
public File getDirectory()
public void setDirectory(File directory)
public String getFilePrefix()
public void setFilePrefix(String filePrefix)
filePrefix - public File getDirectoryArchive()
public void setDirectoryArchive(File directoryArchive)
directoryArchive - public boolean isArchiveFiles()
public void setArchiveFiles(boolean archiveFiles)
archiveFiles - public void setReplicationTarget(ReplicationTarget replicationTarget)
ReplicationTarget to replicate batch writes to.
replicationTarget - public ReplicationTarget getReplicationTarget()
ReplicationTarget to replicate batch writes to.
public String getFileSuffix()
public void setFileSuffix(String fileSuffix)
fileSuffix - public boolean isChecksum()
public void setChecksum(boolean checksumWrites)
checksumWrites - public boolean isPhysicalSync()
public void setPhysicalSync(boolean physicalSync)
public int getMaxWriteBatchSize()
public void setMaxWriteBatchSize(int maxWriteBatchSize)
maxWriteBatchSize - public void setDisposeInterval(long disposeInterval)
disposeInterval - public long getDisposeInterval()
public void setWriter(Executor writer)
writer - public void setDisposer(ScheduledExecutorService disposer)
writer - public void setRecoveryErrorHandler(RecoveryErrorHandler recoveryErrorHandler)
recoveryErrorHandler - public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||