00001 /* 00002 // $Id: //open/dev/fennel/segment/SpillOutputStream.h#10 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 The Eigenbase Project 00005 // Copyright (C) 2005-2009 SQLstream, Inc. 00006 // Copyright (C) 2005-2009 LucidEra, Inc. 00007 // Portions Copyright (C) 1999-2009 John V. Sichi 00008 // 00009 // This program is free software; you can redistribute it and/or modify it 00010 // under the terms of the GNU General Public License as published by the Free 00011 // Software Foundation; either version 2 of the License, or (at your option) 00012 // any later version approved by The Eigenbase Project. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 #ifndef Fennel_SpillOutputStream_Included 00025 #define Fennel_SpillOutputStream_Included 00026 00027 #include "fennel/common/ByteOutputStream.h" 00028 #include "fennel/segment/SegPageLock.h" 00029 00030 FENNEL_BEGIN_NAMESPACE 00031 00032 class LogicalTxn; 00033 00040 class FENNEL_SEGMENT_EXPORT SpillOutputStream 00041 : public ByteOutputStream 00042 { 00046 SharedSegmentFactory pSegmentFactory; 00047 00051 SharedCacheAccessor pCacheAccessor; 00052 00056 SharedSegOutputStream pSegOutputStream; 00057 00061 uint cbBuffer; 00062 00066 SegmentAccessor scratchAccessor; 00067 00071 SegPageLock scratchPageLock; 00072 00076 std::string spillFileName; 00077 00078 // implement the ByteOutputStream interface 00079 virtual void flushBuffer(uint cbRequested); 00080 virtual void closeImpl(); 00081 00082 void spill(); 00083 void updatePage(); 00084 00085 explicit SpillOutputStream( 00086 SharedSegmentFactory, 00087 SharedCacheAccessor, 00088 std::string); 00089 00090 public: 00101 static SharedSpillOutputStream newSpillOutputStream( 00102 SharedSegmentFactory pSegmentFactory, 00103 SharedCacheAccessor pCacheAccessor, 00104 std::string spillFileName); 00105 00106 virtual ~SpillOutputStream(); 00107 00119 SharedByteInputStream getInputStream( 00120 SeekPosition seekPosition = SEEK_STREAM_BEGIN); 00121 00128 SharedSegment getSegment(); 00129 00136 SharedSegOutputStream getSegOutputStream(); 00137 00138 // override ByteOutputStream 00139 virtual void setWriteLatency(WriteLatency writeLatency); 00140 }; 00141 00142 FENNEL_END_NAMESPACE 00143 00144 #endif 00145 00146 // End SpillOutputStream.h