Segment.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/segment/Segment.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_Segment_Included
00025 #define Fennel_Segment_Included
00026 
00027 #include "fennel/cache/MappedPageListener.h"
00028 #include "fennel/common/CompoundId.h"
00029 #include "fennel/common/ClosableObject.h"
00030 
00031 #include <boost/enable_shared_from_this.hpp>
00032 #include <boost/utility.hpp>
00033 #include <hash_map>
00034 
00035 FENNEL_BEGIN_NAMESPACE
00036 
00043 class FENNEL_SEGMENT_EXPORT Segment
00044     : public MappedPageListener,
00045         public boost::noncopyable,
00046         public ClosableObject,
00047         public boost::enable_shared_from_this<Segment>
00048 {
00052     uint cbUsablePerPage;
00053 
00054 protected:
00055 
00056     typedef std::hash_map<PageId,PageId> PageMap;
00057     typedef PageMap::const_iterator PageMapConstIter;
00058 
00062     SharedCache pCache;
00063 
00069     WeakSegment pTracingSegment;
00070 
00071     explicit Segment(SharedCache);
00072     void setUsablePageSize(uint);
00073     PConstBuffer getReadableFooter(CachePage &page);
00074     PBuffer getWritableFooter(CachePage &page);
00075 
00076     // helper methods for LINEAR_ALLOCATION segments
00081     PageId getLinearPageSuccessor(PageId pageId);
00082 
00087     void setLinearPageSuccessor(PageId pageId,PageId successorId);
00088 
00093     bool isLinearPageIdAllocated(PageId pageId);
00094 
00095     // implement ClosableObject
00096     virtual void closeImpl();
00097 
00098 public:
00099 
00105     enum AllocationOrder {
00109         RANDOM_ALLOCATION,
00110 
00115         ASCENDING_ALLOCATION,
00116 
00121         CONSECUTIVE_ALLOCATION,
00122 
00128         LINEAR_ALLOCATION
00129     };
00130 
00136     virtual ~Segment();
00137 
00141     inline SharedCache getCache() const;
00142 
00147     uint getFullPageSize() const;
00148 
00153     inline uint getUsablePageSize() const;
00154 
00159     virtual void initForUse();
00160 
00164     virtual BlockNum getAllocatedSizeInPages() = 0;
00165 
00174     virtual BlockNum getNumPagesOccupiedHighWater() = 0;
00175 
00180     virtual BlockNum getNumPagesExtended() = 0;
00181 
00186     SharedSegment getTracingSegment();
00187 
00193     void setTracingSegment(WeakSegment pTracingSegmentInit);
00194 
00200     void checkpoint(
00201         CheckpointType checkpointType = CHECKPOINT_FLUSH_ALL);
00202 
00211     virtual void delegatedCheckpoint(
00212         Segment &delegatingSegment,
00213         CheckpointType checkpointType);
00214 
00223     virtual PageId getPageSuccessor(PageId pageId) = 0;
00224 
00233     virtual void setPageSuccessor(PageId pageId, PageId successorId) = 0;
00234 
00238     virtual AllocationOrder getAllocationOrder() const = 0;
00239 
00243     virtual BlockId translatePageId(PageId) = 0;
00244 
00248     virtual PageId translateBlockId(BlockId) = 0;
00249 
00259     virtual PageId allocatePageId(PageOwnerId ownerId = ANON_PAGE_OWNER_ID) = 0;
00260 
00270     virtual bool ensureAllocatedSize(BlockNum nPages);
00271 
00293     virtual void deallocatePageRange(
00294         PageId startPageId,
00295         PageId endPageId) = 0;
00296 
00304     virtual bool isPageIdAllocated(PageId pageId) = 0;
00305 
00318     virtual PageId updatePage(PageId pageId, bool needsTranslation = false);
00319 
00327     virtual MappedPageListener *getMappedPageListener(BlockId blockId);
00328 
00332     virtual bool isWriteVersioned();
00333 
00337     static PageId getLinearPageId(BlockNum iPage);
00338 
00342     static BlockNum getLinearBlockNum(PageId pageId);
00343 
00344     // implement MappedPageListener
00345     virtual MappedPageListener *getTracingListener();
00346 };
00347 
00348 inline PageId Segment::getLinearPageId(BlockNum iPage)
00349 {
00350     return PageId(iPage);
00351 }
00352 
00353 inline BlockNum Segment::getLinearBlockNum(PageId pageId)
00354 {
00355     return opaqueToInt(pageId);
00356 }
00357 
00358 inline SharedCache Segment::getCache() const
00359 {
00360     return pCache;
00361 }
00362 
00363 inline uint Segment::getUsablePageSize() const
00364 {
00365     return cbUsablePerPage;
00366 }
00367 
00368 FENNEL_END_NAMESPACE
00369 
00370 #endif
00371 
00372 // End Segment.h

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