ExternalSortRunAccessor Class Reference

ExternalSortRunAccessor manages I/O for storing runs and reading them back. More...

#include <ExternalSortRunAccessor.h>

Inheritance diagram for ExternalSortRunAccessor:

ExternalSortSubStream List of all members.

Public Member Functions

 ExternalSortRunAccessor (ExternalSortInfo &)
virtual ~ExternalSortRunAccessor ()
void initRead ()
 Prepares this accessor to read (but does not specify a particular stored run yet).
void startRead (SharedSegStreamAllocation pStoredRunInit)
 Begins reading a particular run.
void resetRead ()
 Terminates read for the current run if any.
void storeRun (ExternalSortSubStream &subStream)
 Stores a run.
SharedSegStreamAllocation getStoredRun ()
 
Returns:
information about run created by storeRun()

void releaseResources ()
 Releases any resources acquired by this accessor.
virtual ExternalSortFetchArraybindFetchArray ()
 Binds the fetch array which will be used implicitly by subsequent calls to fetch().
virtual ExternalSortRC fetch (uint nTuplesRequested)
 Fetches tuples via the previously bound fetch array.

Private Member Functions

void clearFetch ()

Private Attributes

ExternalSortInfosortInfo
 Global information.
TupleAccessor tupleAccessor
ExternalSortFetchArray fetchArray
 Array used to return fetch results.
PBuffer ppTupleBuffers [EXTSORT_FETCH_ARRAY_SIZE]
 Pointer array used to return fetch results.
SharedSegInputStream pSegInputStream
 Helper used for reading stored runs.
SharedSegOutputStream pSegOutputStream
 Helper used for writing stored runs.
SharedSegStreamAllocation pStoredRun
 Information about run being accessed.

Detailed Description

ExternalSortRunAccessor manages I/O for storing runs and reading them back.

Definition at line 37 of file ExternalSortRunAccessor.h.


Constructor & Destructor Documentation

ExternalSortRunAccessor::ExternalSortRunAccessor ( ExternalSortInfo  )  [explicit]

Definition at line 34 of file ExternalSortRunAccessor.cpp.

References TupleAccessor::compute(), releaseResources(), sortInfo, tupleAccessor, and ExternalSortInfo::tupleDesc.

00035     : sortInfo(sortInfoIn)
00036 {
00037     releaseResources();
00038 
00039     tupleAccessor.compute(sortInfo.tupleDesc);
00040 }

ExternalSortRunAccessor::~ExternalSortRunAccessor (  )  [virtual]

Definition at line 42 of file ExternalSortRunAccessor.cpp.

References releaseResources().

00043 {
00044     releaseResources();
00045 }


Member Function Documentation

void ExternalSortRunAccessor::clearFetch (  )  [inline, private]

Definition at line 79 of file ExternalSortRunAccessor.h.

Referenced by releaseResources().

00080     {
00081         fetchArray.nTuples = 0;
00082         fetchArray.ppTupleBuffers = ppTupleBuffers;
00083         memset(ppTupleBuffers,0,sizeof(ppTupleBuffers));
00084     }

void ExternalSortRunAccessor::initRead (  ) 

Prepares this accessor to read (but does not specify a particular stored run yet).

Definition at line 64 of file ExternalSortRunAccessor.cpp.

References TupleAccessor::compute(), releaseResources(), sortInfo, tupleAccessor, and ExternalSortInfo::tupleDesc.

00065 {
00066     releaseResources();
00067     tupleAccessor.compute(sortInfo.tupleDesc);
00068 }

void ExternalSortRunAccessor::startRead ( SharedSegStreamAllocation  pStoredRunInit  ) 

Begins reading a particular run.

Parameters:
pStoredRunInit run to read

Definition at line 52 of file ExternalSortRunAccessor.cpp.

References pStoredRun.

00054 {
00055     pStoredRun = pStoredRunInit;
00056     pStoredRun->getInputStream()->startPrefetch();
00057 }

void ExternalSortRunAccessor::resetRead (  ) 

Terminates read for the current run if any.

Definition at line 59 of file ExternalSortRunAccessor.cpp.

References fetchArray, and ExternalSortFetchArray::nTuples.

00060 {
00061     fetchArray.nTuples = 0;
00062 }

void ExternalSortRunAccessor::storeRun ( ExternalSortSubStream subStream  ) 

Stores a run.

Parameters:
subStream substream whose contents are to be fetched and stored as a run

Definition at line 76 of file ExternalSortRunAccessor.cpp.

References ExternalSortSubStream::bindFetchArray(), ExternalSortInfo::externalSegmentAccessor, EXTSORT_ENDOFDATA, EXTSORT_FETCH_ARRAY_SIZE, EXTSORT_SUCCESS, ExternalSortSubStream::fetch(), fetchArray, TupleAccessor::getBufferByteCount(), SegOutputStream::newSegOutputStream(), SegStreamAllocation::newSegStreamAllocation(), ExternalSortFetchArray::nTuples, ExternalSortFetchArray::ppTupleBuffers, pSegOutputStream, pStoredRun, sortInfo, and tupleAccessor.

00078 {
00079     pStoredRun = SegStreamAllocation::newSegStreamAllocation();
00080 
00081     SharedSegOutputStream pSegOutputStream =
00082         SegOutputStream::newSegOutputStream(
00083             sortInfo.externalSegmentAccessor);
00084     pStoredRun->beginWrite(pSegOutputStream);
00085 
00086     ExternalSortFetchArray &fetchArray = pObjLoad.bindFetchArray();
00087 
00088     ExternalSortRC rc;
00089     uint iTuple = 0;
00090     do {
00091         for (; iTuple < fetchArray.nTuples; iTuple++) {
00092             PBuffer pSrcBuf = fetchArray.ppTupleBuffers[iTuple];
00093             uint cbTuple = tupleAccessor.getBufferByteCount(pSrcBuf);
00094             PBuffer pTarget = pSegOutputStream->getWritePointer(cbTuple);
00095             memcpy(pTarget,pSrcBuf,cbTuple);
00096             pSegOutputStream->consumeWritePointer(cbTuple);
00097         }
00098         iTuple = 0;
00099 
00100         rc = pObjLoad.fetch(EXTSORT_FETCH_ARRAY_SIZE);
00101     } while (rc == EXTSORT_SUCCESS);
00102 
00103     assert(rc == EXTSORT_ENDOFDATA);
00104 
00105     pStoredRun->endWrite();
00106 }

SharedSegStreamAllocation ExternalSortRunAccessor::getStoredRun (  ) 

Returns:
information about run created by storeRun()

Definition at line 47 of file ExternalSortRunAccessor.cpp.

References pStoredRun.

00048 {
00049     return pStoredRun;
00050 }

void ExternalSortRunAccessor::releaseResources (  ) 

Releases any resources acquired by this accessor.

Definition at line 70 of file ExternalSortRunAccessor.cpp.

References clearFetch(), and pStoredRun.

Referenced by ExternalSortRunAccessor(), initRead(), and ~ExternalSortRunAccessor().

00071 {
00072     pStoredRun.reset();
00073     clearFetch();
00074 }

ExternalSortFetchArray & ExternalSortRunAccessor::bindFetchArray (  )  [virtual]

Binds the fetch array which will be used implicitly by subsequent calls to fetch().

Returns:
bound fetch array

Implements ExternalSortSubStream.

Definition at line 108 of file ExternalSortRunAccessor.cpp.

References fetchArray.

00109 {
00110     return fetchArray;
00111 }

ExternalSortRC ExternalSortRunAccessor::fetch ( uint  nTuplesRequested  )  [virtual]

Fetches tuples via the previously bound fetch array.

Parameters:
nTuplesRequested maximum number of tuples to be returned from fetch (actual count may be less at callee's discretion; this does not indicate end of stream)
Returns:
result of fetch (either EXTSORT_ENDOFDATA or EXTSORT_SUCCESS)

Implements ExternalSortSubStream.

Definition at line 113 of file ExternalSortRunAccessor.cpp.

References ExecStream::checkAbort(), EXTSORT_ENDOFDATA, EXTSORT_FETCH_ARRAY_SIZE, EXTSORT_SUCCESS, fetchArray, TupleAccessor::getBufferByteCount(), ExternalSortFetchArray::nTuples, ppTupleBuffers, pSegInputStream, pStoredRun, sortInfo, ExternalSortInfo::stream, and tupleAccessor.

00114 {
00115     sortInfo.stream.checkAbort();
00116 
00117     if (nTuplesRequested > EXTSORT_FETCH_ARRAY_SIZE) {
00118         nTuplesRequested = EXTSORT_FETCH_ARRAY_SIZE;
00119     }
00120 
00121     uint cb;
00122     SharedSegInputStream const &pSegInputStream = pStoredRun->getInputStream();
00123     PConstBuffer pStart = pSegInputStream->getReadPointer(1,&cb);
00124     PConstBuffer pBuf = pStart;
00125     if (!pBuf) {
00126         return EXTSORT_ENDOFDATA;
00127     }
00128     PConstBuffer pStopMark = pBuf + cb;
00129     uint cbTuple;
00130 
00131     fetchArray.nTuples = 0;
00132     while (nTuplesRequested-- && (pBuf < pStopMark)) {
00133         ppTupleBuffers[fetchArray.nTuples] = const_cast<PBuffer>(pBuf);
00134         cbTuple = tupleAccessor.getBufferByteCount(pBuf);
00135         pBuf += cbTuple;
00136         fetchArray.nTuples++;
00137     }
00138     pSegInputStream->consumeReadPointer(pBuf - pStart);
00139 
00140     return EXTSORT_SUCCESS;
00141 }


Member Data Documentation

ExternalSortInfo& ExternalSortRunAccessor::sortInfo [private]

Global information.

Definition at line 43 of file ExternalSortRunAccessor.h.

Referenced by ExternalSortRunAccessor(), fetch(), initRead(), and storeRun().

TupleAccessor ExternalSortRunAccessor::tupleAccessor [private]

Definition at line 46 of file ExternalSortRunAccessor.h.

Referenced by ExternalSortRunAccessor(), fetch(), initRead(), and storeRun().

ExternalSortFetchArray ExternalSortRunAccessor::fetchArray [private]

Array used to return fetch results.

This is permanently bound to ppTupleBuffers.

Definition at line 52 of file ExternalSortRunAccessor.h.

Referenced by bindFetchArray(), fetch(), resetRead(), and storeRun().

PBuffer ExternalSortRunAccessor::ppTupleBuffers[EXTSORT_FETCH_ARRAY_SIZE] [private]

Pointer array used to return fetch results.

These pointers get bound to contiguous tuples on stored run pages as they are read in.

Definition at line 58 of file ExternalSortRunAccessor.h.

Referenced by fetch().

SharedSegInputStream ExternalSortRunAccessor::pSegInputStream [private]

Helper used for reading stored runs.

Definition at line 63 of file ExternalSortRunAccessor.h.

Referenced by fetch().

SharedSegOutputStream ExternalSortRunAccessor::pSegOutputStream [private]

Helper used for writing stored runs.

Definition at line 68 of file ExternalSortRunAccessor.h.

Referenced by storeRun().

SharedSegStreamAllocation ExternalSortRunAccessor::pStoredRun [private]

Information about run being accessed.

Definition at line 73 of file ExternalSortRunAccessor.h.

Referenced by fetch(), getStoredRun(), releaseResources(), startRead(), and storeRun().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:32 2009 for Fennel by  doxygen 1.5.1