#include <SegStreamAllocation.h>
Inheritance diagram for SegStreamAllocation:
Public Member Functions | |
SegStreamAllocation () | |
Initialize a SegStreamAllocation in the UNALLOCATED state. | |
void | beginWrite (SharedSegOutputStream pSegOutputStreamInit) |
Changes state from UNALLOCATED to WRITING. | |
void | endWrite () |
Changes state from WRITING to READING, or directly to UNALLOCATED if no pages were allocated while in WRITING state. | |
SharedSegInputStream const & | getInputStream () const |
| |
BlockNum | getWrittenPageCount () const |
| |
bool | isClosed () const |
| |
void | close () |
Closes this object, releasing any unallocated resources. | |
Static Public Member Functions | |
static SharedSegStreamAllocation | newSegStreamAllocation () |
Creates a shared pointer to a new SegStreamAllocation, initially in the UNALLOCATED state. | |
Protected Member Functions | |
virtual void | closeImpl () |
Must be implemented by derived class to release any resources. | |
Protected Attributes | |
bool | needsClose |
Private Attributes | |
BlockNum | nPagesWritten |
In state READING, a record of number of pages allocated while in state WRITING. | |
SharedSegOutputStream | pSegOutputStream |
Non-singular iff in state WRITING. | |
SharedSegInputStream | pSegInputStream |
Non-singular iff in state READING. |
It supports three states:
Calling close() at any time safely returns it to the UNALLOCATED state.
Definition at line 51 of file SegStreamAllocation.h.
SegStreamAllocation::SegStreamAllocation | ( | ) | [explicit] |
Initialize a SegStreamAllocation in the UNALLOCATED state.
Use this only if you want to use the allocation by value (e.g. on the stack or as a member variable); if you want to manipulate via shared pointers, call newSegStreamAllocation() instead.
Definition at line 37 of file SegStreamAllocation.cpp.
References nPagesWritten.
Referenced by newSegStreamAllocation().
00038 { 00039 nPagesWritten = 0; 00040 }
void SegStreamAllocation::closeImpl | ( | ) | [protected, virtual] |
Must be implemented by derived class to release any resources.
Implements ClosableObject.
Definition at line 81 of file SegStreamAllocation.cpp.
References endWrite(), nPagesWritten, pSegInputStream, and pSegOutputStream.
00082 { 00083 if (pSegOutputStream) { 00084 // state WRITING 00085 assert(!pSegInputStream); 00086 // do a fake read; this won't really read the pages, it will just 00087 // deallocate them 00088 endWrite(); 00089 } 00090 00091 if (pSegInputStream) { 00092 // state READING 00093 assert(!pSegOutputStream); 00094 assert(pSegInputStream->isDeallocating()); 00095 // this will deallocate all remaining pages as a side-effect 00096 pSegInputStream->close(); 00097 pSegInputStream.reset(); 00098 } else { 00099 // state UNALLOCATED: nothing to do 00100 } 00101 00102 nPagesWritten = 0; 00103 }
SharedSegStreamAllocation SegStreamAllocation::newSegStreamAllocation | ( | ) | [static] |
Creates a shared pointer to a new SegStreamAllocation, initially in the UNALLOCATED state.
Use this if you want to create a shared pointer, since it will correctly set up the allocation to close on reset.
Definition at line 30 of file SegStreamAllocation.cpp.
References SegStreamAllocation().
Referenced by LhxPartitionWriter::open(), and ExternalSortRunAccessor::storeRun().
00031 { 00032 return SharedSegStreamAllocation( 00033 new SegStreamAllocation(), 00034 ClosableObjectDestructor()); 00035 }
void SegStreamAllocation::beginWrite | ( | SharedSegOutputStream | pSegOutputStreamInit | ) |
Changes state from UNALLOCATED to WRITING.
pSegOutputStreamInit | writer |
Definition at line 42 of file SegStreamAllocation.cpp.
References ClosableObject::needsClose, pSegInputStream, and pSegOutputStream.
00043 { 00044 // go from state UNALLOCATED 00045 assert(!pSegOutputStream); 00046 assert(!pSegInputStream); 00047 00048 // to state WRITING 00049 needsClose = true; 00050 pSegOutputStream = pSegOutputStreamInit; 00051 }
void SegStreamAllocation::endWrite | ( | ) |
Changes state from WRITING to READING, or directly to UNALLOCATED if no pages were allocated while in WRITING state.
Note that entering the READING state does not actually access any pages yet.
Definition at line 53 of file SegStreamAllocation.cpp.
References SegInputStream::newSegInputStream(), nPagesWritten, NULL_PAGE_ID, pSegInputStream, pSegOutputStream, and SegStream::segmentAccessor.
Referenced by closeImpl().
00054 { 00055 // from state WRITING 00056 assert(pSegOutputStream); 00057 00058 nPagesWritten = pSegOutputStream->getPageCount(); 00059 00060 SegmentAccessor segmentAccessor = pSegOutputStream->getSegmentAccessor(); 00061 PageId firstPageId = pSegOutputStream->getFirstPageId(); 00062 pSegOutputStream->close(); 00063 pSegOutputStream.reset(); 00064 if (firstPageId == NULL_PAGE_ID) { 00065 // go directly to UNALLOCATED 00066 return; 00067 } 00068 00069 // go to state READING 00070 pSegInputStream = SegInputStream::newSegInputStream( 00071 segmentAccessor, 00072 firstPageId); 00073 pSegInputStream->setDeallocate(true); 00074 }
SharedSegInputStream const & SegStreamAllocation::getInputStream | ( | ) | const |
Definition at line 76 of file SegStreamAllocation.cpp.
References pSegInputStream.
00077 { 00078 return pSegInputStream; 00079 }
BlockNum SegStreamAllocation::getWrittenPageCount | ( | ) | const |
Definition at line 105 of file SegStreamAllocation.cpp.
References nPagesWritten, and pSegOutputStream.
00106 { 00107 if (pSegOutputStream) { 00108 return pSegOutputStream->getPageCount(); 00109 } else { 00110 return nPagesWritten; 00111 } 00112 }
bool ClosableObject::isClosed | ( | ) | const [inline, inherited] |
Definition at line 58 of file ClosableObject.h.
00059 { 00060 return !needsClose; 00061 }
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().
00040 { 00041 if (!needsClose) { 00042 return; 00043 } 00044 needsClose = false; 00045 closeImpl(); 00046 }
BlockNum SegStreamAllocation::nPagesWritten [private] |
In state READING, a record of number of pages allocated while in state WRITING.
Definition at line 58 of file SegStreamAllocation.h.
Referenced by closeImpl(), endWrite(), getWrittenPageCount(), and SegStreamAllocation().
Non-singular iff in state WRITING.
Definition at line 63 of file SegStreamAllocation.h.
Referenced by beginWrite(), closeImpl(), endWrite(), and getWrittenPageCount().
Non-singular iff in state READING.
Definition at line 68 of file SegStreamAllocation.h.
Referenced by beginWrite(), closeImpl(), endWrite(), and getInputStream().
bool ClosableObject::needsClose [protected, inherited] |
Definition at line 44 of file ClosableObject.h.
Referenced by beginWrite(), ExecStreamGraphImpl::clear(), ClosableObject::ClosableObject(), ClosableObject::close(), FlatFileBuffer::open(), ExecStreamGraphImpl::open(), ExecStream::open(), and ClosableObject::~ClosableObject().