Fennel: /home/pub/open/dev/fennel/segment/Segment.h Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 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 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 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
00081 PageId getLinearPageSuccessor(PageId pageId); 00082 00087 void setLinearPageSuccessor(PageId pageId,PageId successorId); 00088 00093 bool isLinearPageIdAllocated(PageId pageId); 00094 00095
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
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