public abstract class Stream extends Object implements ICheckpointProtocol
IPSOutputStream, but integrated with the
ICheckpointProtocol and (ideally) the MVCC architecture.| Modifier and Type | Class and Description |
|---|---|
static class |
Stream.CompressionEnum
The type of compression used on the stream.
|
static class |
Stream.StreamIndexMetadata
Metadata for a named solution set.
|
| Modifier and Type | Field and Description |
|---|---|
protected long |
entryCount
The #of entries in the stream.
|
protected Throwable |
error |
protected static String |
ERROR_CLOSED
The index is already closed.
|
protected static String |
ERROR_ERROR_STATE
The index object is no longer valid.
|
protected static String |
ERROR_READ_ONLY
The index is read-only but a mutation operation was requested.
|
protected Stream.StreamIndexMetadata |
metadata
The metadata record for the index.
|
protected AtomicBoolean |
open
true iff the Stream is open. |
protected long |
rootAddr
The address from which the stream may be read.
|
| Constructor and Description |
|---|
Stream(IRawStore store,
Checkpoint checkpoint,
IndexMetadata metadata,
boolean readOnly)
Required constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
assertNotReadOnly() |
protected void |
assertNotTransient()
NOP.
|
void |
clear() |
void |
close()
The contract for
ICheckpointProtocol.close() is to reduce the resource burden of the
index while not rendering the index inoperative. |
static SolutionSetStream |
create(IRawStore store,
Stream.StreamIndexMetadata metadata)
Create a new
SolutionSetStream or derived class. |
protected void |
fireDirtyEvent()
Fire an event to the listener (iff set).
|
protected void |
flush()
Hook to flush anything which is dirty to the backing store.
|
Checkpoint |
getCheckpoint()
Returns the most recent
ICheckpoint record. |
CounterSet |
getCounters()
Return performance counters.
|
IDirtyListener |
getDirtyListener()
Return the
IDirtyListener. |
Stream.StreamIndexMetadata |
getIndexMetadata()
The metadata for the index.
|
long |
getLastCommitTime()
The timestamp associated with the last
IAtomicStore.commit() in
which writes buffered by this index were made restart-safe on the backing
store. |
long |
getMetadataAddr()
The address at which the most recent
IndexMetadata record was
written. |
int |
getReadLockCount()
Return the #of read-locks held by the current thread for a mutable index
view.
|
long |
getRecordVersion()
The value of the record version number that will be assigned to the next
node or leaf written onto the backing store.
|
long |
getRootAddr()
The address of the last written root of the persistent data structure
-or-
0L if there is no root. |
IRawStore |
getStore()
The backing store.
|
long |
handleCommit(long commitTime)
Flush dirty state to the store in preparation for an atomic commit and
return the address from which the persistence capable data structure may
be reloaded.
|
void |
invalidate(Throwable t)
Mark an
ICommitter as invalid. |
boolean |
isOpen()
An "open" index has may have some buffered data.
|
boolean |
isReadOnly()
Return
true iff this B+Tree is read-only. |
static SolutionSetStream |
load(IRawStore store,
long addrCheckpoint,
boolean readOnly)
Load an instance of a
HTree or derived class from the store. |
protected boolean |
needsCheckpoint()
Return true iff changes would be lost unless the
Stream is
flushed to the backing store using writeCheckpoint(). |
long |
rangeCount()
Return the #of entries in the index.
|
Lock |
readLock()
Return a
Lock that may be used to obtain a shared read lock which
is used (in the absence of other concurrency control mechanisms) to
permit concurrent readers on an unisolated index while serializing access
to that index when a writer must run. |
protected int |
recycle(long addr)
Recycle (aka delete) the allocation.
|
void |
removeAll()
Remove all entries in the index.
|
void |
reopen()
(Re-) open the index.
|
abstract ICloseableIterator<?> |
scan()
Visit all entries in the index in the natural order of the index
(dereferencing visited tuples to the application objects stored within
those tuples).
|
protected void |
setCheckpoint(Checkpoint checkpoint)
Sets the
checkpoint and initializes the mutable fields from the
checkpoint record. |
void |
setDirtyListener(IDirtyListener listener)
Set or clear the listener (there can be only one).
|
void |
setLastCommitTime(long lastCommitTime)
Sets the lastCommitTime.
|
protected InputStream |
wrapInputStream(InputStream in)
Wrap for decompression.
|
protected OutputStream |
wrapOutputStream(OutputStream out)
|
abstract void |
write(ICloseableIterator<?> src)
Write entries onto the stream.
|
long |
writeCheckpoint()
Checkpoint operation must
#flush() dirty nodes, dirty persistent
data structures, etc, write a new Checkpoint record on the
backing store, save a reference to the current Checkpoint, and
return the address of that Checkpoint record. |
Checkpoint |
writeCheckpoint2()
Checkpoint operation must
#flush() dirty nodes, dirty persistent
data structures, etc, write a new Checkpoint record on the
backing store, save a reference to the current Checkpoint, and
return the address of that Checkpoint record. |
Lock |
writeLock()
Return a
Lock that may be used to obtain an exclusive write lock
which is used (in the absence of other concurrency control mechanisms) to
serialize all processes accessing an unisolated index when a writer must
run. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdumpPagesprotected static final String ERROR_CLOSED
protected static final String ERROR_READ_ONLY
protected static final String ERROR_ERROR_STATE
protected volatile Throwable error
protected final AtomicBoolean open
true iff the Stream is open.protected long entryCount
protected long rootAddr
Checkpoint record as
Checkpoint.getRootAddr().protected Stream.StreamIndexMetadata metadata
public Stream(IRawStore store, Checkpoint checkpoint, IndexMetadata metadata, boolean readOnly)
Checkpoint record.store - The store.checkpoint - The Checkpoint record.metadata - The metadata record.readOnly - When true the view will be immutable.create(IRawStore, StreamIndexMetadata),
load(IRawStore, long, boolean)public IRawStore getStore()
ISimpleIndexAccessgetStore in interface ISimpleIndexAccessprotected void setCheckpoint(Checkpoint checkpoint)
checkpoint and initializes the mutable fields from the
checkpoint record. In order for this operation to be atomic, the caller
must be synchronized on the BTree or otherwise guaranteed to have
exclusive access, e.g., during the ctor or when the BTree is
mutable and access is therefore required to be single-threaded.public static SolutionSetStream create(IRawStore store, Stream.StreamIndexMetadata metadata)
SolutionSetStream or derived class. This method
works by writing the Stream.StreamIndexMetadata record on the store
and then loading the SolutionSetStream from the
Stream.StreamIndexMetadata record.store - The store.metadata - The metadata record.SolutionSetStream.IllegalStateException - If you attempt to create two HTree objects from the
same metadata record since the metadata address will have
already been noted on the IndexMetadata object. You
can use IndexMetadata.clone() to obtain a new copy of
the metadata object with the metadata address set to
0L.IllegalStateException - if the IndexTypeEnum in the supplied
IndexMetadata object is not
IndexTypeEnum.BTree.load(IRawStore, long, boolean)public static SolutionSetStream load(IRawStore store, long addrCheckpoint, boolean readOnly)
HTree or derived class from the store. The
HTree or derived class MUST declare a constructor with the
following signature:
className(IRawStore store, Checkpoint checkpoint, IndexMetadata metadata, boolean readOnly)
store - The store.addrCheckpoint - The address of a Checkpoint record for the index.readOnly - When true the BTree will be marked as
read-only. Marking has some advantages relating to the locking
scheme used by Node.getChild(int) since the root node
is known to be read-only at the time that it is allocated as
per-child locking is therefore in place for all nodes in the
read-only BTree. It also results in much higher
concurrency for AbstractBTree.touch(AbstractNode).HTree or derived class loaded from that
Checkpoint record.IllegalArgumentException - if store is null.public void clear()
protected OutputStream wrapOutputStream(OutputStream out)
out - The OutputStream.OutputStream.IOExceptionprotected InputStream wrapInputStream(InputStream in)
public final boolean isReadOnly()
true iff this B+Tree is read-only.isReadOnly in interface IReadWriteLockManagerprotected final void assertNotReadOnly()
UnsupportedOperationException - if the B+Tree is read-only.isReadOnly()protected final void assertNotTransient()
public CounterSet getCounters()
ICounterSetAccessgetCounters in interface ICounterSetAccesspublic long handleCommit(long commitTime)
ICommitterhandleCommit in interface ICommittercommitTime - The timestamp assigned to the commit.public void invalidate(Throwable t)
ICommitterICommitter as invalid. This will prevent it from allowing
any writes through to the backing store.invalidate in interface ICommittert - A cause (required).https://jira.blazegraph.com/browse/BLZG-1953public long getRecordVersion()
ICheckpointProtocolgetRecordVersion in interface ICheckpointProtocolpublic final Checkpoint getCheckpoint()
ICheckpointProtocolICheckpoint record.getCheckpoint in interface ICheckpointProtocolICheckpoint record and never
null.public final long writeCheckpoint()
ICheckpointProtocol#flush() dirty nodes, dirty persistent
data structures, etc, write a new Checkpoint record on the
backing store, save a reference to the current Checkpoint, and
return the address of that Checkpoint record.
Note: A checkpoint by itself is NOT an atomic commit. The commit protocol
is at the store level and uses Checkpoints to ensure that the
state of the persistence capable data structure is current on the backing
store.
writeCheckpoint in interface ICheckpointProtocolCheckpoint record for the
persistence capable was written onto the store. The data
structure can be reloaded from this Checkpoint record.public final Checkpoint writeCheckpoint2()
ICheckpointProtocol#flush() dirty nodes, dirty persistent
data structures, etc, write a new Checkpoint record on the
backing store, save a reference to the current Checkpoint, and
return the address of that Checkpoint record.
Note: A checkpoint by itself is NOT an atomic commit. The commit protocol
is at the store level and uses Checkpoints to ensure that the
state of the persistence capable data structure is current on the backing
store.
writeCheckpoint2 in interface ICheckpointProtocolCheckpoint record for the persistent data structure
which was written onto the store. The persistent data structure
can be reloaded from this Checkpoint record.protected boolean needsCheckpoint()
Stream is
flushed to the backing store using writeCheckpoint().true true iff changes would be lost unless the
Stream was flushed to the backing store using
writeCheckpoint().protected void flush()
_writeCheckpoint2().protected int recycle(long addr)
BTreeCounters.addr - The address to be recycled.IAddressManager.NULL.public final long getRootAddr()
0L if there is no root. A 0L return may be
an indication that an empty data structure will be created on demand.getRootAddr in interface ICheckpointProtocolpublic final long getMetadataAddr()
ICheckpointProtocolIndexMetadata record was
written.getMetadataAddr in interface ICheckpointProtocolpublic Stream.StreamIndexMetadata getIndexMetadata()
ICheckpointProtocol
Note: The same method is also declared by IIndex in order to
provide access to the IndexMetadata for remote clients in
scale-out.
getIndexMetadata in interface ICheckpointProtocolIIndex.getIndexMetadata()public final IDirtyListener getDirtyListener()
ICheckpointProtocolIDirtyListener.getDirtyListener in interface ICheckpointProtocolpublic final long getLastCommitTime()
ICheckpointProtocolIAtomicStore.commit() in
which writes buffered by this index were made restart-safe on the backing
store. The lastCommitTime is set when the index is loaded from the
backing store and updated after each commit. It is ZERO (0L) when an
index is first created and will remain ZERO (0L) until the index is
committed. If the backing store does not support atomic commits, then
this value will always be ZERO (0L).getLastCommitTime in interface ICheckpointProtocolpublic final void setLastCommitTime(long lastCommitTime)
ICheckpointProtocol
Note: The lastCommitTime is set by a combination of the
AbstractJournal and Name2Addr based on the actual
commitTime of the commit during which an Name2Addr.Entry for that index was
last committed. It is set for both historical index reads and unisolated
index reads using Name2Addr.Entry.commitTime. The lastCommitTime for an
unisolated index will advance as commits are performed with that index.
setLastCommitTime in interface ICheckpointProtocollastCommitTime - The timestamp of the last committed state of this index.public final void setDirtyListener(IDirtyListener listener)
ICheckpointProtocolsetDirtyListener in interface ICheckpointProtocollistener - The listener.protected final void fireDirtyEvent()
public long rangeCount()
ISimpleIndexAccessNote: If the index supports deletion markers then the range count will be an upper bound and may double count tuples which have been overwritten, including the special case where the overwrite is a delete.
rangeCount in interface ISimpleIndexAccessIRangeQuery.rangeCount()public void removeAll()
ISimpleIndexAccessremoveAll in interface ISimpleIndexAccesspublic void close()
ICheckpointProtocolICheckpointProtocol.close() is to reduce the resource burden of the
index while not rendering the index inoperative. An index that has been
closed MAY be reopened at any time
(conditional on the continued availability of the backing store). Such an
index reference remains valid after a ICheckpointProtocol.close(). A closed index is
transparently reopened by any access to the index data
(scanning the index, probing the index, etc).
Note: A ICheckpointProtocol.close() on a dirty index MUST discard writes rather than
flushing them to the store and MUST NOT update its Checkpoint
record - (ICheckpointProtocol.close() is used to discard indices with partial writes
when an AbstractTask fails). If you are seeking to
ICheckpointProtocol.close() a mutable index view that state can be recovered by
ICheckpointProtocol.reopen() then you MUST write a new Checkpoint record
before closing the index.
close in interface ICheckpointProtocolpublic void reopen()
ICheckpointProtocolICheckpointProtocol.close() /
ICheckpointProtocol.reopen() protocol. That protocol may be used to reduce the
resource burden of an index. This method is automatically invoked by a
variety of methods that need to ensure that the index is available for
use.reopen in interface ICheckpointProtocolICheckpointProtocol.close(),
ICheckpointProtocol.isOpen(),
#getRoot()public boolean isOpen()
ICheckpointProtocolisOpen in interface ICheckpointProtocolICheckpointProtocol.close(),
ICheckpointProtocol.reopen()public abstract ICloseableIterator<?> scan()
ISimpleIndexAccessscan in interface ISimpleIndexAccesspublic abstract void write(ICloseableIterator<?> src)
src - An iterator visiting the entries.public final Lock readLock()
IReadWriteLockManagerLock that may be used to obtain a shared read lock which
is used (in the absence of other concurrency control mechanisms) to
permit concurrent readers on an unisolated index while serializing access
to that index when a writer must run. This is exposed for processes which
need to obtain the write lock to coordinate external operations.
Note: If the persistence capable data structure is read-only then the
returned Lock is a singleton that ignores all lock requests. This
is because our read-only persistence capable data structures are already
thread-safe for concurrent readers.
readLock in interface IReadWriteLockManagerpublic final Lock writeLock()
IReadWriteLockManagerLock that may be used to obtain an exclusive write lock
which is used (in the absence of other concurrency control mechanisms) to
serialize all processes accessing an unisolated index when a writer must
run. This is exposed for processes which need to obtain the write lock to
coordinate external operations.writeLock in interface IReadWriteLockManagerpublic final int getReadLockCount()
IReadWriteLockManagergetReadLockCount in interface IReadWriteLockManagerCopyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.