ExternalSortExecStreamImpl.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/sorter/ExternalSortExecStreamImpl.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_ExternalSortExecStreamImpl_Included
00025 #define Fennel_ExternalSortExecStreamImpl_Included
00026 
00027 #include "fennel/sorter/ExternalSortExecStream.h"
00028 #include "fennel/synch/SynchObj.h"
00029 #include "fennel/synch/ThreadPool.h"
00030 
00031 #include <boost/scoped_ptr.hpp>
00032 
00033 #include "fennel/sorter/ExternalSortInfo.h"
00034 #include "fennel/sorter/ExternalSortRunLoader.h"
00035 #include "fennel/sorter/ExternalSortRunAccessor.h"
00036 #include "fennel/sorter/ExternalSortMerger.h"
00037 #include "fennel/sorter/ExternalSortOutput.h"
00038 #include "fennel/sorter/ExternalSortTask.h"
00039 
00040 FENNEL_BEGIN_NAMESPACE
00041 
00042 class ExternalSortRunLoader;
00043 typedef boost::shared_ptr<ExternalSortRunLoader>
00044 SharedExternalSortRunLoader;
00045 
00052 class FENNEL_SORTER_EXPORT ExternalSortExecStreamImpl
00053     : public ExternalSortExecStream
00054 {
00055     friend class ExternalSortTask;
00056 
00060     SharedSegment pTempSegment;
00061 
00065     ExternalSortInfo sortInfo;
00066 
00070     uint nParallel;
00071 
00079     boost::scoped_array<SharedExternalSortRunLoader> runLoaders;
00080 
00084     ThreadPool<ExternalSortTask> threadPool;
00085 
00090     LocalCondition runLoaderAvailable;
00091 
00095     StrictMutex runLoaderMutex;
00096 
00100     boost::scoped_ptr<ExternalSortRunAccessor> pFinalRunAccessor;
00101 
00105     boost::scoped_ptr<ExternalSortMerger> pMerger;
00106 
00110     boost::scoped_ptr<ExternalSortOutput> pOutputWriter;
00111 
00115     StrictMutex storedRunMutex;
00116 
00120     std::vector<SharedSegStreamAllocation> storedRuns;
00121 
00125     bool resultsReady;
00126 
00131     bool storeFinalRun;
00132 
00137     int estimatedNumRows;
00138 
00142     bool earlyClose;
00143 
00144 // ----------------------------------------------------------------------
00145 // private methods
00146 // ----------------------------------------------------------------------
00147 
00148     // TODO jvs 10-Nov-2004:  rework comments
00153     void computeFirstResult();
00154 
00159     void computeFirstResultParallel();
00160 
00166     void sortRun(ExternalSortRunLoader &runLoader);
00167 
00174     void storeRun(ExternalSortSubStream &subStream);
00175 
00179     void mergeFirstResult();
00180 
00184     void optimizeRunOrder();
00185 
00193     void deleteStoredRunInfo(uint iFirstRun, uint nRuns);
00194 
00201     ExternalSortRunLoader &reserveRunLoader();
00202 
00209     void unreserveRunLoader(ExternalSortRunLoader &runLoader);
00210 
00214     void releaseResources();
00215 
00216     // implement ExecStream
00217     virtual void closeImpl();
00218 
00219 public:
00220     explicit ExternalSortExecStreamImpl();
00221 
00222     // implement ExecStream
00223     virtual void prepare(ExternalSortExecStreamParams const &params);
00224     virtual void open(bool restart);
00225     virtual ExecStreamResult execute(ExecStreamQuantum const &quantum);
00226     virtual void getResourceRequirements(
00227         ExecStreamResourceQuantity &minQuantity,
00228         ExecStreamResourceQuantity &optQuantity,
00229         ExecStreamResourceSettingType &optType);
00230     virtual void setResourceAllocation(
00231         ExecStreamResourceQuantity &quantity);
00232 };
00233 
00234 FENNEL_END_NAMESPACE
00235 
00236 #endif
00237 
00238 // End ExternalSortExecStreamImpl.h

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