Cache.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/cache/Cache.h#20 $
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_Cache_Included
00025 #define Fennel_Cache_Included
00026 
00027 #include "fennel/common/ClosableObject.h"
00028 #include "fennel/device/DeviceAccessScheduler.h"
00029 #include "fennel/cache/CacheAccessor.h"
00030 #include "fennel/common/StatsSource.h"
00031 
00032 #include <boost/enable_shared_from_this.hpp>
00033 
00034 FENNEL_BEGIN_NAMESPACE
00035 
00036 class CacheParams;
00037 class PagePredicate;
00038 class CacheAllocator;
00039 class CacheStats;
00040 
00056 class FENNEL_CACHE_EXPORT Cache
00057     : public ClosableObject,
00058         public CacheAccessor, public StatsSource,
00059         public boost::enable_shared_from_this<Cache>
00060 {
00061     friend class CachePage;
00062 
00063 protected:
00064     uint cbPage;
00065 
00066 public:
00074     static const DeviceId NULL_DEVICE_ID;
00075 
00088     static SharedCache newCache(
00089         CacheParams const &cacheParams,
00090         CacheAllocator *bufferAllocator = NULL);
00091 
00096     virtual ~Cache();
00097 
00107     virtual void setAllocatedPageCount(uint nMemPages) = 0;
00108 
00113     virtual uint getMaxAllocatedPageCount() = 0;
00114 
00120     virtual uint getAllocatedPageCount() = 0;
00121 
00128     virtual void collectStats(CacheStats &stats) = 0;
00129 
00130 // ----------------------------------------------------------------------
00131 // Accessor Methods
00132 // ----------------------------------------------------------------------
00133 
00137     uint getPageSize() const
00138     {
00139         return cbPage;
00140     }
00141 
00142     virtual CacheAllocator &getAllocator() const = 0;
00143 
00144 // ----------------------------------------------------------------------
00145 // Device Registration and Operations
00146 // ----------------------------------------------------------------------
00147 
00157     virtual void registerDevice(
00158         DeviceId deviceId,SharedRandomAccessDevice pDevice) = 0;
00159 
00166     virtual void unregisterDevice(
00167         DeviceId deviceId) = 0;
00168 
00176     virtual SharedRandomAccessDevice &getDevice(DeviceId deviceId) = 0;
00177 
00178 // ----------------------------------------------------------------------
00179 // Global Operations on Pages; also see CacheAccessor methods
00180 // ----------------------------------------------------------------------
00181 
00195     virtual uint checkpointPages(
00196         PagePredicate &pagePredicate,
00197         CheckpointType checkpointType = CHECKPOINT_FLUSH_ALL) = 0;
00198 
00206     virtual bool isPageMapped(BlockId blockId) = 0;
00207 
00224     virtual CachePage &lockScratchPage(BlockNum blockNum = 0) = 0;
00225 
00230     virtual DeviceAccessScheduler &getDeviceAccessScheduler(
00231         RandomAccessDevice &) = 0;
00232 
00233     // partial implementation of CacheAccessor
00234     virtual SharedCache getCache();
00235     virtual uint getMaxLockedPages();
00236     virtual void setMaxLockedPages(uint nPages);
00237     virtual void setTxnId(TxnId txnId); // ignored
00238     virtual TxnId getTxnId() const;
00239 
00240     // implementation of StatsSource
00241     virtual void writeStats(StatsTarget &target);
00242 
00243 private:
00244     // notification methods called from friend Page
00245     virtual void notifyTransferCompletion(CachePage &,bool bSuccess) = 0;
00246     virtual void markPageDirty(CachePage &) = 0;
00247 };
00248 
00249 FENNEL_END_NAMESPACE
00250 
00251 #endif
00252 
00253 // End Cache.h

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