Fennel: SegInputStream Class Reference (original) (raw)

SegInputStream implements the ByteInputStream interface by reading data previously written via a SegOutputStream. More...

#include <[SegInputStream.h](SegInputStream%5F8h-source.html)>

Inheritance diagram for SegInputStream:

List of all members.

Public Member Functions
void startPrefetch ()
Requests that prefetch be performed in anticipation of forward scan.
void endPrefetch ()
Disables prefetch.
void setDeallocate (bool shouldDeallocate)
Requests that pages be deallocated after the stream is done reading them.
bool isDeallocating ()
**Returns:**true if currently set to deallocate pages as they are read
virtual void getSegPos (SegStreamPosition &pos)
Obtains the current stream position.
void seekSegPos (SegStreamPosition const &pos)
Seeks to a previously recorded stream position.
virtual SharedByteStreamMarker newMarker ()
Creates a new uninitialized marker for this stream.
virtual void mark (ByteStreamMarker &marker)
Marks the current stream position in preparation for a future call to reset().
virtual void reset (ByteStreamMarker const &marker)
Resets stream to a previously marked position.
SharedSegment getSegment () const
**Returns:**segment accessed by this stream
SegmentAccessor const & getSegmentAccessor () const
**Returns:**segment accessor used by this stream
FileSize getOffset () const
**Returns:**current offset from beginning of stream
bool isClosed () const
**Returns:**whether the object has been closed
void close ()
Closes this object, releasing any unallocated resources.
uint readBytes (void *pData, uint cbRequested)
Reads bytes from the stream.
template
uint readValue (T &value)
Reads a fixed-size value from the stream.
PConstBuffer getReadPointer (uint cbRequested, uint *pcbActual=NULL)
Copyless alternative for reading bytes from the stream.
void consumeReadPointer (uint cbUsed)
Advances stream position after a call to getReadPointer.
void seekForward (uint cb)
Skips forward in stream.
void seekBackward (uint cb)
Skips backward in stream.
Static Public Member Functions
static SharedSegInputStream newSegInputStream (SegmentAccessor const &segmentAccessor, PageId beginPageId=FIRST_LINEAR_PAGE_ID)
Creates a new SegInputStream, positioned at beginning-of-stream.
Protected Member Functions
virtual void readNextBuffer ()
Must be implemented by derived class by calling either setBuffer or nullifyBuffer.
virtual void readPrevBuffer ()
Must be implemented by derived class if seekBackward is to be supported.
virtual void closeImpl ()
Must be implemented by derived class to release any resources.
SegInputStream (SegmentAccessor const &, PageId, uint cbExtraHeader=0)
virtual void lockBuffer ()
void setBuffer (PConstBuffer pBuffer, uint cbBuffer)
Sets the current buffer to be read.
void nullifyBuffer ()
Nullifies the current buffer, indicating no more data is available.
uint getBytesAvailable () const
**Returns:**number of bytes remaining in current buffer
uint getBytesConsumed () const
**Returns:**number of bytes already consumed from current buffer
Protected Attributes
SegPageIter pageIter
PageId currPageId
PageId of current page.
bool shouldDeallocate
Whether to deallocate stream pages when no longer needed.
SegmentAccessor segmentAccessor
Accessor for segment containing stream data.
SegStreamLock pageLock
Lock held on current page, if any.
uint cbPageHeader
Number of bytes in page header.
FileSize cbOffset
Byte position in stream.
bool needsClose

Detailed Description

SegInputStream implements the ByteInputStream interface by reading data previously written via a SegOutputStream.

seekBackward is supported, but only if the underlying segment supports CONSECUTIVE_ALLOCATION or LINEAR_ALLOCATION.

Definition at line 39 of file SegInputStream.h.


Constructor & Destructor Documentation

SegInputStream::SegInputStream ( SegmentAccessor const & ,
PageId ,
uint cbExtraHeader = 0
) [explicit, protected]

Member Function Documentation

| void SegInputStream::readNextBuffer | ( | | ) | [protected, virtual] | | ----------------------------------- | - | | - | ---------------------- |

Must be implemented by derived class by calling either setBuffer or nullifyBuffer.

Implements ByteInputStream.

Definition at line 71 of file SegInputStream.cpp.

References currPageId, SegPageLock::deallocateLockedPage(), SegStream::getSegment(), SegPageLock::isLocked(), SegPageIter::isSingular(), lockBuffer(), NULL_PAGE_ID, ByteInputStream::nullifyBuffer(), pageIter, SegStream::pageLock, shouldDeallocate, and SegPageLock::unlock().

| void SegInputStream::readPrevBuffer | ( | | ) | [protected, virtual] | | ----------------------------------- | - | | - | ---------------------- |

| void SegInputStream::closeImpl | ( | | ) | [protected, virtual] | | ------------------------------ | - | | - | ---------------------- |

| void SegInputStream::lockBuffer | ( | | ) | [protected, virtual] | | ------------------------------- | - | | - | ---------------------- |

Creates a new SegInputStream, positioned at beginning-of-stream.

Parameters:

segmentAccessor accessor for the segment containing the stream data
beginPageId the first page of stream data; if the default FIRST_LINEAR_PAGE_ID is passed, the segment must support LINEAR_ALLOCATION, and the stream starts at the first page of the segment; if NULL_PAGE_ID is passed, an empty stream is returned

Returns:

shared_ptr to new SegInputStream

Definition at line 29 of file SegInputStream.cpp.

References SegInputStream(), and SegStream::segmentAccessor.

Referenced by SegBufferWriter::closeImpl(), SegStreamAllocation::endWrite(), SpillOutputStream::getInputStream(), VariableBuildLevel::getParentKeyStream(), SegBufferReader::open(), LogicalRecoveryLog::openLongLogStream(), BTreeTest::testBulkLoad(), SegStreamTest::testMarkReset(), BTreeReadersTest::testReaders(), and SegStreamTest::testReadSeg().

| void SegInputStream::startPrefetch | ( | | ) | | ---------------------------------- | - | | - |

| void SegInputStream::endPrefetch | ( | | ) | | -------------------------------- | - | | - |

void SegInputStream::setDeallocate ( bool shouldDeallocate )

Requests that pages be deallocated after the stream is done reading them.

If in effect, any unread pages will also be deallocated when the stream is closed. Note that usage of deallocation may cause other methods such as seekSegPos and seekBackward to fail.

Parameters:

shouldDeallocate whether to deallocate pages

Definition at line 145 of file SegInputStream.cpp.

References shouldDeallocate.

| bool SegInputStream::isDeallocating | ( | | ) | | ----------------------------------- | - | | - |

Seeks to a previously recorded stream position.

Parameters:

pos the new position, previously returned by getSegPos

Definition at line 130 of file SegInputStream.cpp.

References SegStreamPosition::cbOffset, ByteStream::cbOffset, ByteInputStream::consumeReadPointer(), currPageId, CompoundId::getByteOffset(), ByteInputStream::getBytesAvailable(), CompoundId::getPageId(), SegPageIter::isSingular(), lockBuffer(), CompoundId::MAX_BYTE_OFFSET, pageIter, and SegStreamPosition::segByteId.

Referenced by reset().

Creates a new uninitialized marker for this stream.

The returned marker must be passed to mark() in order to initialize it.

Returns:

shared pointer to new marker

Reimplemented from ByteInputStream.

Definition at line 156 of file SegInputStream.cpp.

| SegmentAccessor const & SegStream::getSegmentAccessor | ( | | ) | const [inherited] | | ----------------------------------------------------------------------------------- | - | | - | ------------------- |

| FileSize ByteStream::getOffset | ( | | ) | const [inline, inherited] | | ---------------------------------------------------------------------------------- | - | | - | --------------------------- |

| bool ClosableObject::isClosed | ( | | ) | const [inline, inherited] | | ----------------------------- | - | | - | --------------------------- |

Returns:

whether the object has been closed

Definition at line 58 of file ClosableObject.h.

| void ClosableObject::close | ( | | ) | [inherited] | | -------------------------- | - | | - | ------------- |

Closes this object, releasing any unallocated resources.

Reimplemented in CollectExecStream, CorrelationJoinExecStream, LcsClusterAppendExecStream, and LcsClusterReplaceExecStream.

Definition at line 39 of file ClosableObject.cpp.

References ClosableObject::closeImpl(), and ClosableObject::needsClose.

Referenced by CacheImpl< PageT, VictimPolicyT >::allocatePages(), LcsRowScanBaseExecStream::closeImpl(), ExecStreamGraphImpl::closeImpl(), FlatFileBuffer::open(), ClosableObjectDestructor::operator()(), and Segment::~Segment().

void ByteInputStream::setBuffer ( PConstBuffer pBuffer,
uint cbBuffer
) [inline, protected, inherited]

| void ByteInputStream::nullifyBuffer | ( | | ) | [inline, protected, inherited] | | ----------------------------------- | - | | - | -------------------------------- |

| uint ByteInputStream::getBytesAvailable | ( | | ) | const [inline, protected, inherited] | | ---------------------------------------------------------------------------------------------------- | - | | - | -------------------------------------- |

| uint ByteInputStream::getBytesConsumed | ( | | ) | const [inline, protected, inherited] | | --------------------------------------------------------------------------------------------------- | - | | - | -------------------------------------- |

uint ByteInputStream::readBytes ( void * pData,
uint cbRequested
) [inherited]

template

uint ByteInputStream::readValue ( T & value ) [inline, inherited]

Reads a fixed-size value from the stream.

Parameters:

value value to write; type must be memcpy-safe

Returns:

number of bytes actually read

Definition at line 112 of file ByteInputStream.h.

Referenced by FtrsTableWriterFactory::loadIndex(), LogicalTxnTest::loadParticipant(), FtrsTableWriterFactory::loadParticipant(), BTreeRecoveryFactory::loadParticipant(), TupleProjection::readPersistent(), TupleDescriptor::readPersistent(), LogicalTxnTest::redoLogicalAction(), DatabaseTest::redoLogicalAction(), LogicalTxnTest::undoLogicalAction(), and DatabaseTest::undoLogicalAction().

00113 { 00114 return readBytes(&value,sizeof(value)); 00115 }

PConstBuffer ByteInputStream::getReadPointer ( uint cbRequested,
uint * pcbActual = NULL
) [inline, inherited]

Copyless alternative for reading bytes from the stream.

Provides direct access to the stream's internal buffer, but doesn't move the stream position (see consumeReadPointer).

Note that it is in general dangerous to assume that getReadPointer will be able to access desired data items contiguously. For example, a stream created by calling ByteOutputStream::write is likely to have data items split across buffers. The assumption MAY be valid for streams created by calling ByteOutputStream::getWritePointer with matching values for cbRequested; it depends on the stream implementation.

Parameters:

cbRequested number of contiguous bytes to access; if a non-zero number of bytes are currently available in the buffer, cbRequested must be no greater than the number of available bytes (otherwise an assertion violation will result)
pcbActual if non-NULL, receives actual number of contiguous bytes available, which will always be greater than or equal to cbRequested except 0 for end-of-stream

Returns:

pointer to cbActual bytes of available data, or NULL for end-of-stream

Definition at line 209 of file ByteInputStream.h.

References ByteInputStream::getBytesAvailable(), ByteInputStream::pEndByte, ByteInputStream::pNextByte, and ByteInputStream::readNextBuffer().

Referenced by BTreeWriter::deleteLogged(), BTreeWriter::insertLogged(), and BTreeBuildLevel::processInput().

void ByteInputStream::consumeReadPointer ( uint cbUsed ) [inline, inherited]
void ByteInputStream::seekForward ( uint cb ) [inline, inherited]
void ByteInputStream::seekBackward ( uint cb ) [inherited]

Member Data Documentation

Byte position in stream.

Definition at line 41 of file ByteStream.h.

Referenced by ByteStream::ByteStream(), ByteInputStream::consumeReadPointer(), ByteOutputStream::consumeWritePointer(), ByteStream::getOffset(), SegOutputStream::getSegPos(), getSegPos(), ByteInputStream::readBytes(), ByteInputStream::reset(), ByteArrayInputStream::resetArray(), ByteInputStream::seekBackward(), seekSegPos(), and ByteOutputStream::writeBytes().


The documentation for this class was generated from the following files:


Generated on Mon Jun 22 04:00:45 2009 for Fennel by doxygen 1.5.1