Fennel: /home/pub/open/dev/fennel/segment/ScratchSegment.cpp 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 #include "fennel/common/CommonPreamble.h" 00025 #include "fennel/segment/ScratchSegment.h" 00026 #include "fennel/segment/ScratchMemExcn.h" 00027 #include "fennel/cache/Cache.h" 00028 #include "fennel/common/FennelExcn.h" 00029 00030 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/segment/ScratchSegment.cpp#18 $"); 00031 00032 ScratchSegment::ScratchSegment( 00033 SharedCache pCache, 00034 uint nPagesMaxInit) 00035 : Segment(pCache) 00036 { 00037 nPagesMax = nPagesMaxInit; 00038 } 00039 00040 void ScratchSegment::closeImpl() 00041 { 00042
00043
00044 clearPages(); 00045 } 00046 00047 void ScratchSegment::clearPages() 00048 { 00049
00050 00051 for (PageListIter ppPage = pages.begin(); ppPage != pages.end(); ++ppPage) { 00052 CachePage &page = **ppPage; 00053 getCache()->unlockPage(page,LOCKMODE_X); 00054 } 00055 pages.clear(); 00056 } 00057 00058 BlockId ScratchSegment::translatePageId(PageId pageId) 00059 { 00060 assert(isPageIdAllocated(pageId)); 00061 BlockId blockId(0); 00062 CompoundId::setDeviceId(blockId,Cache::NULL_DEVICE_ID); 00063 CompoundId::setBlockNum( 00064 blockId, 00065 getLinearBlockNum(pageId)); 00066 return blockId; 00067 } 00068 00069 PageId ScratchSegment::translateBlockId(BlockId blockId) 00070 { 00071 return getLinearPageId(CompoundId::getBlockNum(blockId)); 00072 } 00073 00074 BlockNum ScratchSegment::getAllocatedSizeInPages() 00075 { 00076 return pages.size(); 00077 } 00078 00079 BlockNum ScratchSegment::getNumPagesOccupiedHighWater() 00080 { 00081 return getAllocatedSizeInPages(); 00082 } 00083 00084 BlockNum ScratchSegment::getNumPagesExtended() 00085 { 00086 return BlockNum(0); 00087 } 00088 00089 PageId ScratchSegment::allocatePageId(PageOwnerId) 00090 { 00091 StrictMutexGuard mutexGuard(mutex); 00092 00093
00094 00095 if (getAllocatedSizeInPages() >= nPagesMax) { 00096 return NULL_PAGE_ID; 00097 } 00098 00099 BlockNum blockNum = pages.size(); 00100 CachePage &page = getCache()->lockScratchPage(blockNum); 00101 pages.push_back(&page); 00102 return getLinearPageId(blockNum); 00103 } 00104 00105 void ScratchSegment::deallocatePageRange(PageId startPageId,PageId endPageId) 00106 { 00107 assert(startPageId == NULL_PAGE_ID); 00108 assert(endPageId == NULL_PAGE_ID); 00109 00110 StrictMutexGuard mutexGuard(mutex); 00111 clearPages(); 00112 } 00113 00114 bool ScratchSegment::isPageIdAllocated(PageId pageId) 00115 { 00116 return isLinearPageIdAllocated(pageId); 00117 } 00118 00119 PageId ScratchSegment::getPageSuccessor(PageId pageId) 00120 { 00121 return getLinearPageSuccessor(pageId); 00122 } 00123 00124 void ScratchSegment::setPageSuccessor(PageId pageId,PageId successorId) 00125 { 00126 setLinearPageSuccessor(pageId,successorId); 00127 } 00128 00129 Segment::AllocationOrder ScratchSegment::getAllocationOrder() const 00130 { 00131 return LINEAR_ALLOCATION; 00132 } 00133 00134 CachePage *ScratchSegment::lockPage( 00135 BlockId blockId, 00136 LockMode lockMode, 00137 bool readIfUnmapped, 00138 MappedPageListener *pMappedPageListener, 00139 TxnId txnId) 00140 { 00141 StrictMutexGuard mutexGuard(mutex); 00142 00143 assert(CompoundId::getDeviceId(blockId) == Cache::NULL_DEVICE_ID); 00144 BlockNum blockNum = CompoundId::getBlockNum(blockId); 00145 assert(blockNum < pages.size()); 00146
00147
00148 return pages[blockNum]; 00149 } 00150 00151 void ScratchSegment::unlockPage( 00152 CachePage &, 00153 LockMode, 00154 TxnId) 00155 { 00156
00157 } 00158 00159 00160 00161 void ScratchSegment::discardPage( 00162 BlockId) 00163 { 00164 } 00165 00166 bool ScratchSegment::prefetchPage( 00167 BlockId, 00168 MappedPageListener *) 00169 { 00170 return false; 00171 } 00172 00173 void ScratchSegment::prefetchBatch( 00174 BlockId,uint, 00175 MappedPageListener *) 00176 { 00177 } 00178 00179 void ScratchSegment::flushPage(CachePage &,bool) 00180 { 00181 } 00182 00183 void ScratchSegment::nicePage(CachePage &) 00184 { 00185
00186 } 00187 00188 SharedCache ScratchSegment::getCache() 00189 { 00190 return Segment::getCache(); 00191 } 00192 00193 uint ScratchSegment::getMaxLockedPages() 00194 { 00195 if (isMAXU(nPagesMax)) { 00196 return getCache()->getMaxLockedPages(); 00197 } else { 00198 return nPagesMax; 00199 } 00200 } 00201 00202 void ScratchSegment::setMaxLockedPages(uint nPages) 00203 { 00204 StrictMutexGuard mutexGuard(mutex); 00205 assert(nPages >= pages.size()); 00206 nPagesMax = nPages; 00207 } 00208 00209 void ScratchSegment::setTxnId(TxnId) 00210 { 00211 } 00212 00213 TxnId ScratchSegment::getTxnId() const 00214 { 00215 return IMPLICIT_TXN_ID; 00216 } 00217 00218 void ScratchSegment::getPrefetchParams( 00219 uint &nPagesPerBatch, 00220 uint &nBatchPrefetches) 00221 { 00222 } 00223 00224 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/segment/ScratchSegment.cpp#18 $"); 00225 00226