SegmentFactory.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/segment/SegmentFactory.h#18 $
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_SegmentFactory_Included
00025 #define Fennel_SegmentFactory_Included
00026 
00027 #include "fennel/common/CompoundId.h"
00028 #include "fennel/common/ClosableObject.h"
00029 #include "fennel/common/ConfigMap.h"
00030 #include "fennel/synch/SynchObj.h"
00031 #include "fennel/segment/TracingSegment.h"
00032 #include "fennel/segment/SnapshotRandomAllocationSegment.h"
00033 #include "fennel/device/DeviceMode.h"
00034 
00035 #include <boost/dynamic_bitset.hpp>
00036 #include <boost/utility.hpp>
00037 #include <boost/enable_shared_from_this.hpp>
00038 
00039 FENNEL_BEGIN_NAMESPACE
00040 
00041 class LinearDeviceSegmentParams;
00042 class PseudoUuid;
00043 
00049 class FENNEL_SEGMENT_EXPORT SegmentFactory
00050     : public boost::noncopyable,
00051         public boost::enable_shared_from_this<SegmentFactory>
00052 {
00053     friend class TempSegDestructor;
00054 
00055     static ParamName paramTraceSegments;
00056 
00060     SharedTraceTarget pTraceTarget;
00061 
00062     boost::dynamic_bitset<> tempDeviceIdBitset;
00063 
00064     DeviceId firstTempDeviceId;
00065 
00066     StrictMutex mutex;
00067 
00068     ConfigMap configMap;
00069 
00070     DeviceId allocateTempDeviceId();
00071 
00072     void deallocateTempDeviceId(DeviceId);
00073 
00074     explicit SegmentFactory(
00075         ConfigMap const &configMap,
00076         SharedTraceTarget pTraceTarget);
00077 public:
00089     static SharedSegmentFactory newSegmentFactory(
00090         ConfigMap const &configMap,
00091         SharedTraceTarget pTraceTarget);
00092 
00093     virtual ~SegmentFactory();
00094 
00098     ConfigMap const &getConfigMap() const;
00099 
00109     SharedSegment newLinearDeviceSegment(
00110         SharedCache cache,
00111         LinearDeviceSegmentParams const &params);
00112 
00128     SharedSegment newRandomAllocationSegment(
00129         SharedSegment delegateSegment,
00130         bool bFormat,
00131         bool deferInit = false);
00132 
00151     SharedSegment newVersionedRandomAllocationSegment(
00152         SharedSegment delegateSegment,
00153         SharedSegment pTempSegment,
00154         bool bFormat,
00155         bool deferInit = false);
00156 
00175     SharedSegment newSnapshotRandomAllocationSegment(
00176         SharedSegment delegateSegment,
00177         SharedSegment versionedSegment,
00178         TxnId snapshotCsn,
00179         bool readOnlyCommittedData = false);
00180 
00188     SharedSegment newDynamicDelegatingSegment(SharedSegment delegateSegment);
00189 
00199     SharedSegment newWALSegment(
00200         SharedSegment logSegment);
00201 
00212     SharedSegment newLinearViewSegment(
00213         SharedSegment delegateSegment,
00214         PageId firstPageId);
00215 
00234     SharedSegment newCircularSegment(
00235         SharedSegment delegateSegment,
00236         SharedCheckpointProvider pCheckpointProvider,
00237         PageId oldestPageId = NULL_PAGE_ID,
00238         PageId newestPageId = NULL_PAGE_ID);
00239 
00255     SharedSegment newVersionedSegment(
00256         SharedSegment dataSegment,
00257         SharedSegment logSegment,
00258         PseudoUuid const &onlineUuid,
00259         SegVersionNum versionNumber);
00260 
00272     SegmentAccessor newScratchSegment(
00273         SharedCache pCache,
00274         uint nPagesMax = MAXU);
00275 
00288     SharedSegment newTracingSegment(
00289         SharedSegment pSegment,
00290         std::string sourceName,
00291         bool qualifySourceName = true);
00292 
00306     SharedSegment newTempDeviceSegment(
00307         SharedCache pCache,
00308         DeviceMode deviceMode,
00309         std::string deviceFileName);
00310 
00335     template <class PDerivedSegment>
00336     static PDerivedSegment dynamicCast(SharedSegment pSegment)
00337     {
00338         PDerivedSegment pDerived = dynamic_cast<PDerivedSegment>(
00339             pSegment.get());
00340         if (pDerived) {
00341             return pDerived;
00342         }
00343         TracingSegment *pTracing = dynamic_cast<TracingSegment *>(
00344             pSegment.get());
00345         if (pTracing) {
00346             pDerived = dynamic_cast<PDerivedSegment>(
00347                 pTracing->getDelegateSegment().get());
00348         }
00349         return pDerived;
00350     }
00351 
00361     static SnapshotRandomAllocationSegment *getSnapshotSegment(
00362         SharedSegment pSegment);
00363 };
00364 
00365 class FENNEL_SEGMENT_EXPORT TempSegDestructor
00366     : public ClosableObjectDestructor
00367 {
00368     SharedSegmentFactory pSegmentFactory;
00369 
00370 public:
00371     explicit TempSegDestructor(SharedSegmentFactory);
00372     void operator()(Segment *pSegment);
00373 };
00374 
00375 FENNEL_END_NAMESPACE
00376 
00377 #endif
00378 
00379 // End SegmentFactory.h

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