public class HALogReader extends Object implements IHALogReader
IHALogReader.hasMoreBuffers()
and if so read the next associated
buffer and process with the returned IHAMessage
. If
IHALogReader.hasMoreBuffers()
is false, then the committing
IRootBlockView
should be used to commit the replayed transaction.HA_LOG_EXT, HALOG_FILTER
Constructor and Description |
---|
HALogReader(File file)
CAUTION: This constructor should not be used in circumstances in
which the
HALogWriter is active since this constructor can not
differentiate atomically between the live HALog and a historical HALog
and will always provide a read-only view, even if the live HALog file is
opened. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the reader iff it is open.
|
void |
computeDigest(MessageDigest digest)
Compute the digest.
|
IRootBlockView |
getClosingRootBlock()
The
IRootBlockView for the committed state AFTER the write set
contained in the HA log file has been applied. |
IRootBlockView |
getOpeningRootBlock()
The
IRootBlockView for the committed state BEFORE the write set
contained in the HA log file. |
boolean |
hasMoreBuffers()
Checks whether we have reached the end of the file (blocking).
|
boolean |
isEmpty()
Return
true if the root blocks in the log file have the same
commit counter. |
boolean |
isLive()
Return
true iff this is was the live HALog at the moment
when it was opened (if true, then this flag will remain true
even if the writer moves onto another HALog file). |
boolean |
isOpen()
Return
true iff the reader is open. |
static void |
main(String[] args)
Utility program will dump log files (or directories containing log files)
provided as arguments.
|
IHAWriteMessage |
processNextBuffer(ByteBuffer clientBuffer)
Attempts to read the next
IHAWriteMessage and then the expected
buffer, that is read into the client buffer. |
static IHAWriteMessage |
processNextBuffer(RandomAccessFile raf,
IReopenChannel<FileChannel> reopener,
StoreTypeEnum storeType,
ByteBuffer clientBuffer) |
public HALogReader(File file) throws IOException
HALogWriter
is active since this constructor can not
differentiate atomically between the live HALog and a historical HALog
and will always provide a read-only view, even if the live HALog file is
opened.file
- The HALog file.IOException
public void close()
IHALogReader
Note: Closing a reader does not have a side-effect on any open reader or writer for the same file. Specifically, if two readers are open for the same file and one is closed, then other will remain open. Likewise, if a reader is open for the live HALog file, closing the writer will not close the reader and closing the reader will not close the writer.
close
in interface IHALogReader
public boolean isOpen()
IHALogReader
true
iff the reader is open.isOpen
in interface IHALogReader
public boolean isLive()
IHALogReader
true
iff this is was the live HALog at the moment
when it was opened (if true, then this flag will remain true
even if the writer moves onto another HALog file).isLive
in interface IHALogReader
public boolean isEmpty()
IHALogReader
true
if the root blocks in the log file have the same
commit counter. Such log files are logically empty regardless of their
length.
FIXME The code disagress and will report [false] if the live log has the
same root blocks but has not yet been closed.isEmpty
in interface IHALogReader
public IRootBlockView getOpeningRootBlock()
IRootBlockView
for the committed state BEFORE the write set
contained in the HA log file.getOpeningRootBlock
in interface IHALogReader
public IRootBlockView getClosingRootBlock()
IHALogReader
IRootBlockView
for the committed state AFTER the write set
contained in the HA log file has been applied.getClosingRootBlock
in interface IHALogReader
public boolean hasMoreBuffers() throws IOException
IHALogReader
Note: This method will block if this is the live HALog. This allows a process to block until the next message is made available on the live HALog by the writer.
Note: This method is non-blocking if this is not the live HALog since the decision can be made deterministically by inspecting the #of messages available (in the closing root block) and the #of messages consumed by the reader.
hasMoreBuffers
in interface IHALogReader
false
if (a) the file is closed on entry to
this method; (b) the live HALog is closed while waiting for more
data to become available; or (c) the end of a historical HALog
file has been reached. Return true
iff more data can
be read from the file.IOException
- if there is an error reading from the backing file.public IHAWriteMessage processNextBuffer(ByteBuffer clientBuffer) throws IOException
IHALogReader
IHAWriteMessage
and then the expected
buffer, that is read into the client buffer. The IHAWriteMessage
is returned to the caller.
Note: The caller's buffer will be filled in IFF the data is on the HALog.
For some IHABufferStrategy
implementations, that data is not
present in the HALog. The caller's buffer will not be modified and the
caller is responsible for getting the data from the
IHABufferStrategy
(e.g., for the WORMStrategy
).
Note: IF the buffer is filled, then the limit will be the #of bytes ready to be transmitted and the position will be zero.
processNextBuffer
in interface IHALogReader
clientBuffer
- A buffer from the DirectBufferPool.INSTANCE
.IOException
public static IHAWriteMessage processNextBuffer(RandomAccessFile raf, IReopenChannel<FileChannel> reopener, StoreTypeEnum storeType, ByteBuffer clientBuffer) throws IOException
IOException
public static void main(String[] args) throws InterruptedException
args
- Zero or more files or directories.IOException
InterruptedException
public void computeDigest(MessageDigest digest) throws DigestException, IOException
IHALogReader
IHALogReader
is backed by the live
HALog, then only the digest of the then current extent will be computed.computeDigest
in interface IHALogReader
DigestException
IOException
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.