ExternalSortRunLoader.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/sorter/ExternalSortRunLoader.h#2 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2009-2009 SQLstream, Inc.
00006 // Copyright (C) 2004-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 2004-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_ExternalSortRunLoader_Included
00025 #define Fennel_ExternalSortRunLoader_Included
00026 
00027 #include "fennel/tuple/TupleAccessor.h"
00028 #include "fennel/tuple/TupleProjectionAccessor.h"
00029 #include "fennel/tuple/TupleData.h"
00030 #include "fennel/segment/SegPageLock.h"
00031 #include "fennel/sorter/ExternalSortSubStream.h"
00032 
00033 #include <vector>
00034 
00035 FENNEL_BEGIN_NAMESPACE
00036 
00037 class ExternalSortInfo;
00038 
00052 class FENNEL_SORTER_EXPORT ExternalSortRunLoader
00053     : public ExternalSortSubStream
00054 {
00058     ExternalSortInfo &sortInfo;
00059 
00063     SegPageLock bufferLock;
00064 
00068     uint nMemPagesMax;
00069 
00074     std::vector<PBuffer> freeBuffers;
00075 
00082     std::vector<PBuffer> indexBuffers;
00083 
00088     std::vector<PBuffer> dataBuffers;
00089 
00094     uint indexToPageShift;
00095 
00100     uint indexPageMask;
00101 
00105     PBuffer pDataBuffer;
00106 
00110     PBuffer pDataBufferEnd;
00111 
00115     PBuffer pIndexBuffer;
00116 
00120     PBuffer pIndexBufferEnd;
00121 
00125     uint nTuplesLoaded;
00126 
00130     uint nTuplesFetched;
00131 
00136     ExternalSortFetchArray fetchArray;
00137 
00138     // TODO:  comment or replace
00139     TupleAccessor tupleAccessor;
00140     TupleAccessor tupleAccessor2;
00141     TupleProjectionAccessor keyAccessor;
00142     TupleProjectionAccessor keyAccessor2;
00143     TupleData keyData;
00144     TupleData keyData2;
00145 
00146 // ----------------------------------------------------------------------
00147 // private methods
00148 // ----------------------------------------------------------------------
00149 
00155     PBuffer allocateBuffer();
00156 
00162     bool allocateDataBuffer();
00163 
00169     bool allocateIndexBuffer();
00170 
00178     inline PBuffer &getPointerArrayEntry(uint iTuple);
00179 
00180     inline void quickSortSwap(uint l,uint r);
00181     uint quickSortPartition(uint i,uint j,PBuffer pivot);
00182     PBuffer quickSortFindPivot(uint l,uint r);
00183     void quickSort(uint l,uint r);
00184 
00185 public:
00192     bool runningParallelTask;
00193 
00194     explicit ExternalSortRunLoader(ExternalSortInfo &info);
00195     virtual ~ExternalSortRunLoader();
00196 
00200     void startRun();
00201 
00205     bool isStarted();
00206 
00214     ExternalSortRC loadRun(ExecStreamBufAccessor &bufAccessor);
00215 
00219     void sort();
00220 
00224     uint getLoadedTupleCount();
00225 
00229     void releaseResources();
00230 
00231     // implement ExternalSortSubStream
00232     virtual ExternalSortFetchArray &bindFetchArray();
00233     virtual ExternalSortRC fetch(uint nTuplesRequested);
00234 };
00235 
00236 FENNEL_END_NAMESPACE
00237 
00238 #endif
00239 
00240 // End ExternalSortRunLoader.h

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