public class HALogWriter extends Object implements IHALogWriter
The process log stores the HAWriteMessage
and buffers to support
reading and reprocessing as part of the HA synchronization protocol.
The writer encapsulates not only the writing of individual messages but also the closing and creation of new files.
Modifier and Type | Field and Description |
---|---|
static int |
MAGIC
Magic value for HA Log (the root blocks have their own magic value).
|
static int |
VERSION1
HA log version number (version 1).
|
Constructor and Description |
---|
HALogWriter(File logDir,
boolean doubleSync) |
Modifier and Type | Method and Description |
---|---|
void |
closeHALog(IRootBlockView rootBlock)
Write the final root block on the HA log and close the file.
|
void |
createLog(IRootBlockView rootBlock)
Open an HA log file for the write set starting with the given root block.
|
void |
disableHALog()
Disable (and remove) the current log file if one is open (an HALog file
which has been committed by applying its closing root block is NOT
removed).
|
long |
getCommitCounter()
Return the commit counter that is expected for the writes that will be
logged (the same commit counter that is on the opening root block).
|
File |
getFile()
Return the log file (if any).
|
static File |
getHALogFileName(File dir,
long commitCounter)
Return the HALog file associated with the commit counter.
|
IHALogReader |
getReader(long commitCounter)
Return the
IHALogReader for the specified commit counter. |
long |
getSequence()
Return the sequence number that is expected for the next write.
|
boolean |
isHALogOpen()
Return
true iff there is an HALog file that is
currently open for writing. |
String |
toString() |
void |
writeOnHALog(IHAWriteMessage msg,
ByteBuffer data)
Write the message and the data on the live HALog.
|
public static final int MAGIC
public static final int VERSION1
public HALogWriter(File logDir, boolean doubleSync)
logDir
- The directory in which the HALog files reside.doubleSync
- When true
, the HALog is flushed to the disk
before the closing root block is written and then once again
after the closing root block is written. When
false
, the HALog is flushed only once, after the
closing root block is written.public long getCommitCounter()
IHALogWriter
Note: Once the HALog is sealed, the closing root block will have a
commitCounter that is equal to getCommitCounter() + 1
.
Note: The HALog filename contains the closing commit counter - that is, the HALog file is named for the commit counter associated with the closing root block for a given write set.
getCommitCounter
in interface IHALogWriter
public long getSequence()
IHALogWriter
getSequence
in interface IHALogWriter
public boolean isHALogOpen()
IHALogWriter
true
iff there is an HALog file that is
currently open for writing.isHALogOpen
in interface IHALogWriter
public File getFile()
public static File getHALogFileName(File dir, long commitCounter)
dir
- The HALog directory.commitCounter
- The closing commit counter (the HALog file is named for the
commit counter that will be associated with the closing root
block).File
.public void createLog(IRootBlockView rootBlock) throws FileNotFoundException, IOException
rootBlock
- The root block.FileNotFoundException
IOException
public void closeHALog(IRootBlockView rootBlock) throws FileNotFoundException, IOException
closeHALog
in interface IHALogWriter
rootBlock
- The final root block for the write set.IOException
FileNotFoundException
public void writeOnHALog(IHAWriteMessage msg, ByteBuffer data) throws IOException, IllegalStateException
writeOnHALog
in interface IHALogWriter
msg
- The message.data
- The data.IllegalStateException
- if the message is not appropriate for the state of the log.IOException
- if we can not write on the log.public void disableHALog() throws IOException
IHALogWriter
disableHALog
in interface IHALogWriter
IOException
public IHALogReader getReader(long commitCounter) throws FileNotFoundException, IOException
IHALogReader
for the specified commit counter. If the
request identifies the HALog that is currently being written, then an
IHALogReader
will be returned that will "see" newly written
entries on the HALog. If the request identifies a historical HALog that
has been closed and which exists, then a reader will be returned for that
HALog file. Otherwise, an exception is thrown.commitCounter
- The commit counter associated with the commit point at the
close of the write set (the commit counter that is in the file
name).IHALogReader
.IOException
- if the commitCounter identifies an HALog file that does not
exist or can not be read.FileNotFoundException
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.