RandomAllocationSegment.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/segment/RandomAllocationSegment.cpp#13 $
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 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/segment/RandomAllocationSegmentBaseImpl.h"
00026 #include "fennel/segment/RandomAllocationSegmentImpl.h"
00027 
00028 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/segment/RandomAllocationSegment.cpp#13 $");
00029 
00030 RandomAllocationSegment::RandomAllocationSegment(
00031     SharedSegment delegateSegment)
00032     : RandomAllocationSegmentBase(delegateSegment)
00033 {
00034     nPagesPerExtent = (getUsablePageSize() - sizeof(ExtentAllocationNode))
00035         / sizeof(PageEntry);
00036 
00037     // + 1 is for SegAllocNode itself
00038     nPagesPerSegAlloc = nPagesPerExtent*nExtentsPerSegAlloc + 1;
00039 }
00040 
00041 void RandomAllocationSegment::formatPageExtents(
00042     SegmentAllocationNode &segAllocNode,
00043     ExtentNum &extentNum)
00044 {
00045     formatPageExtentsTemplate<
00046             ExtentAllocationNode,
00047             ExtentAllocLock,
00048             PageEntry>(
00049         segAllocNode,
00050         extentNum);
00051 }
00052 
00053 PageId RandomAllocationSegment::allocatePageId(PageOwnerId ownerId)
00054 {
00055     return allocatePageIdFromSegment(ownerId, getTracingSegment());
00056 }
00057 
00058 PageId RandomAllocationSegment::getSegAllocPageIdForWrite(
00059     PageId origSegAllocPageId)
00060 {
00061     return origSegAllocPageId;
00062 }
00063 
00064 void RandomAllocationSegment::undoSegAllocPageWrite(PageId segAllocPageId)
00065 {
00066 }
00067 
00068 PageId RandomAllocationSegment::getExtAllocPageIdForWrite(ExtentNum extentNum)
00069 {
00070     return getExtentAllocPageId(extentNum);
00071 }
00072 
00073 PageId RandomAllocationSegment::getSegAllocPageIdForRead(
00074     PageId origSegAllocPageId,
00075     SharedSegment &allocNodeSegment)
00076 {
00077     allocNodeSegment = getTracingSegment();
00078     return origSegAllocPageId;
00079 }
00080 
00081 PageId RandomAllocationSegment::getExtAllocPageIdForRead(
00082     ExtentNum extentNum,
00083     SharedSegment &allocNodeSegment)
00084 {
00085     allocNodeSegment = getTracingSegment();
00086     return getExtentAllocPageId(extentNum);
00087 }
00088 
00089 void RandomAllocationSegment::getPageEntryCopy(
00090     PageId pageId,
00091     PageEntry &pageEntryCopy,
00092     bool isAllocated,
00093     bool thisSegment)
00094 {
00095     getPageEntryCopyTemplate<ExtentAllocationNode, ExtentAllocLock, PageEntry>(
00096         pageId,
00097         pageEntryCopy,
00098         isAllocated,
00099         thisSegment);
00100 }
00101 
00102 PageId RandomAllocationSegment::allocateFromNewExtent(
00103     ExtentNum extentNum,
00104     PageOwnerId ownerId)
00105 {
00106     return
00107         allocateFromNewExtentTemplate<
00108                 ExtentAllocationNode,
00109                 ExtentAllocLock,
00110                 PageEntry>(
00111             extentNum,
00112             ownerId,
00113             getTracingSegment());
00114 }
00115 
00116 PageId RandomAllocationSegment::allocateFromExtent(
00117     ExtentNum extentNum,
00118     PageOwnerId ownerId)
00119 {
00120     return
00121         allocateFromExtentTemplate<
00122                 ExtentAllocationNode,
00123                 ExtentAllocLock,
00124                 PageEntry>(
00125             extentNum,
00126             ownerId,
00127             getTracingSegment());
00128 }
00129 
00130 void RandomAllocationSegment::freePageEntry(
00131     ExtentNum extentNum,
00132     BlockNum iPageInExtent)
00133 {
00134     freePageEntryTemplate<
00135             ExtentAllocationNode,
00136             ExtentAllocLock,
00137             PageEntry>(
00138         extentNum,
00139         iPageInExtent);
00140 }
00141 
00142 PageId RandomAllocationSegment::getPageSuccessor(PageId pageId)
00143 {
00144     PageEntry pageEntry;
00145 
00146     getPageEntryCopy(pageId, pageEntry, true, true);
00147     return pageEntry.successorId;
00148 }
00149 
00150 void RandomAllocationSegment::setPageSuccessor(
00151     PageId pageId,
00152     PageId successorId)
00153 {
00154     setPageSuccessorTemplate<ExtentAllocationNode, ExtentAllocLock>(
00155         pageId,
00156         successorId,
00157         getTracingSegment());
00158 }
00159 
00160 PageOwnerId RandomAllocationSegment::getPageOwnerId(
00161     PageId pageId,
00162     bool thisSegment)
00163 {
00164     return getPageOwnerIdTemplate<PageEntry>(pageId, thisSegment);
00165 }
00166 
00167 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/segment/RandomAllocationSegment.cpp#13 $");
00168 
00169 // End RandomAllocationSegment.cpp

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