public class RootBlockView extends Object implements IRootBlockView
Journal
.Modifier and Type | Field and Description |
---|---|
static int |
currentVersion
The current version for new root blocks.
|
static short |
SIZEOF_ROOT_BLOCK |
NO_BLOCK_SEQUENCE
Constructor and Description |
---|
RootBlockView(boolean rootBlock0,
ByteBuffer buf,
ChecksumUtility checker)
Create a new read-only view from the supplied buffer.
|
RootBlockView(boolean rootBlock0,
int offsetBits,
long nextOffset,
long firstCommitTime,
long lastCommitTime,
long commitCounter,
long commitRecordAddr,
long commitRecordIndexAddr,
UUID uuid,
long blockSequence,
long quorumToken,
long metaStartAddr,
long metaBitsAddr,
StoreTypeEnum storeTypeEnum,
long createTime,
long closeTime,
int version,
ChecksumUtility checker)
Create a new read-only root block image with a unique timestamp.
|
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
asReadOnlyBuffer()
A read-only buffer whose contents are the root block.
|
IRootBlockView |
asRootBlock(boolean rootBlock0)
Return a version of the caller's root block that is flagged as either
rootBlock0 or rootBlock1 as indicated by the argument.
|
int |
calcChecksum(ChecksumUtility checker)
Compute the checksum of the root block (excluding only the field
including the checksum value itself).
|
boolean |
equals(Object o)
Overriden to implement equality based on the data in the
IRootBlockView . |
long |
getBlockSequence()
Return the #of
WriteCache blocks that have been written out as
part of the current write set. |
long |
getChallisField()
The "Challis field" is written at both the head and the tail of each root
block and is a strictly increasing value positive long integer.
|
int |
getChecksum(ChecksumUtility checker)
Return the checksum store in the root block (excluding only the field
including the checksum value itself).
|
long |
getCloseTime()
The timestamp assigned as the time at which writes were disallowed for
the journal.
|
long |
getCommitCounter()
The commit counter is a positive long integer that is strictly local to
the store.
|
long |
getCommitRecordAddr()
Return the address at which the
ICommitRecord for this root block
is stored. |
long |
getCommitRecordIndexAddr()
The address of the root of the
CommitRecordIndex . |
long |
getCreateTime()
The timestamp assigned as the creation time for the journal.
|
long |
getFirstCommitTime()
The database wide timestamp of first commit on the store -or- 0L if there
have been no commits.
|
long |
getLastCommitTime()
The database wide timestamp of the most recent commit on the store or 0L
iff there have been no commits.
|
long |
getLocalTime()
A purely informative field whose value is the system local
timestamp of the last commit as reported by
System.currentTimeMillis() or the time at which the store was
created iff there have been no commits. |
long |
getMetaBitsAddr()
For the
StoreTypeEnum.RW store, where we will read the metadata
bits from. |
long |
getMetaStartAddr()
For the
StoreTypeEnum.RW store, the start of the area of the file
where the allocation blocks are allocated. |
long |
getNextOffset()
The next offset at which a data item would be written on the store.
|
int |
getOffsetBits()
The #of bits in a 64-bit long integer address that are dedicated to the
byte offset into the store.
|
long |
getQuorumToken()
The
Quorum token associated with this commit point or
Quorum.NO_QUORUM if there was no quorum. |
StoreTypeEnum |
getStoreType()
A byte value which specifies whether the backing store is a journal
(log-structured store or WORM) or a read-write store.
|
UUID |
getUUID()
The unique journal identifier
|
int |
getVersion()
The root block version number.
|
int |
hashCode() |
boolean |
isRootBlock0()
There are two root blocks and they are written in an alternating order.
|
String |
toString() |
static String |
toString(long t)
Format a commit time as the raw milliseconds since the epoch value plus a
fully expressed date and time.
|
void |
valid()
Assertion throws exception unless the root block is valid.
|
public static final transient short SIZEOF_ROOT_BLOCK
public static final int currentVersion
currentVersion
.public RootBlockView(boolean rootBlock0, int offsetBits, long nextOffset, long firstCommitTime, long lastCommitTime, long commitCounter, long commitRecordAddr, long commitRecordIndexAddr, UUID uuid, long blockSequence, long quorumToken, long metaStartAddr, long metaBitsAddr, StoreTypeEnum storeTypeEnum, long createTime, long closeTime, int version, ChecksumUtility checker)
offsetBits
- The #of bits out of a 64-bit long integer that are used to
encode the byte offset as an unsigned integer. The remaining
bits are used to encode the byte count (aka record length) as
an unsigned integer.nextOffset
- The next offset at which a record will be written on the
store.firstCommitTime
- The timestamp of the earliest commit on the store or zero (0L)
iff there have been no commits.lastCommitTime
- The timestamp of the most recent commit on the store or zero
(0L) iff there have been no commits. This is distinct from the
values written as part of the Challis algorithm. The latter
exist solely to detect commit failures. This timestamp is
assigned by the transaction commit protocol.commitCounter
- The commit counter. This should be ZERO (0L) for a new
journal. For an existing journal, the value should be
incremented by ONE (1) each time the root block is written (as
part of a commit naturally).commitRecordAddr
- The address at which the ICommitRecord
containing the
root addresses was written or 0L if there are no root
addresses (this is true when the store is first created).commitRecordIndexAddr
- The address at which the IndexMetadata
for the
CommitRecordIndex
was written or 0L if there are no
historical ICommitRecord
s (this is true when the store
is first created).uuid
- The unique journal identifier.blockSequence
- The WriteCache
block sequence number as of the commit
point (origin ZERO(0)).quorumToken
- The current quorum token if this commit point is part of a
Quorum
.metaStartAddr
- For the StoreTypeEnum.RW
store, the start of the area
of the file where the allocation blocks are allocated. This is
also a byte offset into the file and is stored as a 64-bit
integer. It is called metaStartAddr because that is the offset
that is used with the metaBitsAddr to determine how to find
the allocation blocks. The value for a WORM store is ZERO (0).metaBitsAddr
- For the StoreTypeEnum.RW
store, where we will read the
metadata bits from. When we start the store up we need to
retrieve the metabits from this address. This is a byte offset
into the file and is stored as a long integer. Normal
addresses are calculated with reference to the allocation
blocks. The value for a WORM store is ZERO (0).storeTypeEnum
- The kind of persistence store. See StoreTypeEnum
.checker
- An object that is used to compute the checksum to be stored in
the root block (required).createTime
- The timestamp of the creation event for the journal. This is
mainly used by the ResourceManager
to impose a
chronological order on the journals.closeTime
- ZERO(0L) unless the journal has been closed for write
operations, in which case this is the timestamp of the event
that disallowed further writes on this journal. This is mainly
used by the ResourceManager
to indicate that a journal
is no longer available for writing (because it has been
superseded by another journal).version
- public RootBlockView(boolean rootBlock0, ByteBuffer buf, ChecksumUtility checker) throws RootBlockException
rootBlock0
- There are two root blocks and they are written in an
alternating order. For the sake of distinction, the first one
is referred to as "rootBlock0" while the 2nd one is referred
to as "rootBlock1". This parameter allows the caller to store
a transient field on the view that indicates which root block
it represents.buf
- The buffer.checker
- An object used to compute the checksum of the root block
(optional, when null
the checksum stored in the
root block will not be verified).IllegalArgumentException
- if the buffer is null or if the #of bytes remaining in the
buffer is not exactly SIZEOF_ROOT_BLOCK
.RootBlockException
- if the root block is not valid (bad magic, timestamps do
not agree, etc).public boolean isRootBlock0()
IRootBlockView
isRootBlock0
in interface IRootBlockView
public ByteBuffer asReadOnlyBuffer()
IRootBlockView
ByteBuffer
that is
returned by this method.asReadOnlyBuffer
in interface IRootBlockView
public IRootBlockView asRootBlock(boolean rootBlock0)
IRootBlockView
IRootBlockView
in which the sense of the IRootBlockView.isRootBlock0()
flag is now correct.asRootBlock
in interface IRootBlockView
rootBlock0
- Whether you want rootBlock0 or rootBlock1.public int hashCode()
Overridden to implement the hash code as the hash code of the data in the
backing ByteBuffer
. The IRootBlockView
is immutable. The
hash code is computed lazily. Once computed, the hash code is NOT
recomputed for the same IRootBlockView
.
public boolean equals(Object o)
IRootBlockView
.public int getVersion()
IRootBlockView
getVersion
in interface IRootBlockView
public int getOffsetBits()
IRootBlockView
getOffsetBits
in interface IRootBlockView
WormAddressManager
public long getNextOffset()
IRootBlockView
AbstractJournal
so we can directly decide
how many bytes were "written" (for the WORM) or were "allocated" (for the
RWStore, in which case it should probably be the net of the bytes
allocated and released). Update all the locations in the code which rely
on IRootBlockView.getNextOffset()
to compute the #of bytes written onto the
store.getNextOffset
in interface IRootBlockView
public long getLocalTime()
System.currentTimeMillis()
or the time at which the store was
created iff there have been no commits. Unlike
getFirstCommitTime()
and getLastCommitTime()
this field
does NOT provide a guarantee that time is strictly increasing.
Note: This field is stored for post-mortem purposes and is NOT used internally.
public long getFirstCommitTime()
IRootBlockView
getFirstCommitTime
in interface IRootBlockView
public long getLastCommitTime()
IRootBlockView
getLastCommitTime
in interface IRootBlockView
public long getChallisField() throws RootBlockException
RootBlockException
- if the values on the root block do not agree.public long getCommitCounter()
IRootBlockView
Challis field
).getCommitCounter
in interface IRootBlockView
public long getCommitRecordAddr()
IRootBlockView
ICommitRecord
for this root block
is stored. The ICommitRecord
s are stored separately from the
root block so that they may be indexed by the commit timestamps. This is
necessary in order to be able to quickly recover the root addresses for a
given commit timestamp, which is a featured used to support transactional
isolation.
Note: When a logical journal may overflow onto more than one physical
journal then the address of the ICommitRecord
MAY refer to a
historical physical journal and care MUST be exercised to resolve the
address against the appropriate journal file. [This paragraph is probably
not valid. Verify and remove if it is not true.]
getCommitRecordAddr
in interface IRootBlockView
ICommitRecord
for this root
block is stored.public long getCommitRecordIndexAddr()
IRootBlockView
CommitRecordIndex
. The
CommitRecordIndex
contains the ordered addresses of the
historical ICommitRecord
s on the Journal
. The address
of the CommitRecordIndex
is stored directly in the root block
rather than the ICommitRecord
since we can not obtain this
address until after we have formatted and written the
ICommitRecord
.getCommitRecordIndexAddr
in interface IRootBlockView
public void valid()
IRootBlockView
valid
in interface IRootBlockView
public UUID getUUID()
IRootBlockView
getUUID
in interface IRootBlockView
public long getCreateTime()
IRootBlockView
getCreateTime
in interface IRootBlockView
public long getCloseTime()
IRootBlockView
getCloseTime
in interface IRootBlockView
public int getChecksum(ChecksumUtility checker) throws RootBlockException
checker
- An object used to compute the checksum. Note that you can
disable the checksum test by passing in a null
value here.RootBlockException
- if the checksum stored in the root block does not agree
with the checksum computed by
calcChecksum(ChecksumUtility)
.public int calcChecksum(ChecksumUtility checker)
public static String toString(long t)
t
- The commit time.public long getMetaBitsAddr()
IRootBlockView
StoreTypeEnum.RW
store, where we will read the metadata
bits from. When we start the store up we need to retrieve the metabits
from this address. This is a byte offset into the file and is stored as a
long integer. Normal addresses are calculated with reference to the
allocation blocks. The value for a WORM store is ZERO (0).getMetaBitsAddr
in interface IRootBlockView
public long getMetaStartAddr()
IRootBlockView
StoreTypeEnum.RW
store, the start of the area of the file
where the allocation blocks are allocated. This is also a byte offset
into the file and is stored as a 64-bit integer. It is called
metaStartAddr because that is the offset that is used with the
metaBitsAddr to determine how to find the allocation blocks. The value
for a WORM store is ZERO (0).getMetaStartAddr
in interface IRootBlockView
public StoreTypeEnum getStoreType()
Note: The OFFSET_STORETYPE
field was defined in
VERSION1
. The default value for that field before
VERSION1
is StoreTypeEnum.WORM
since only the WORM
persistence store existed in earlier versions of the root block.
getStoreType
in interface IRootBlockView
public long getQuorumToken()
Quorum
token associated with this commit point or
Quorum.NO_QUORUM
if there was no quorum.
Note: If commit points are part of the resynchronization protocol, they MUST NOT use the current quorum token unless the service is synchronized with the quorum at that commit point.
Note: The quorum token was introduced in VERSION2
. The default
value for that field before VERSION2
is {Quorum#NO_QUORUM}.
getQuorumToken
in interface IRootBlockView
public long getBlockSequence()
WriteCache
blocks that have been written out as
part of the current write set. This value is origin ZERO (0) and is reset
to ZERO (0) after each commit or abort.
Note: The write cache block sequence was introduced in VERSION3
.
The default value for that field before VERSION3
is
.
getBlockSequence
in interface IRootBlockView
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.