Cache.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/cache/Cache.cpp#14 $
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/cache/CacheImpl.h"
00026 #include "fennel/cache/LRUVictimPolicy.h"
00027 #include "fennel/cache/TwoQVictimPolicy.h"
00028 #include "fennel/common/StatsTarget.h"
00029 
00030 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/cache/Cache.cpp#14 $");
00031 
00032 const DeviceId Cache::NULL_DEVICE_ID = DeviceId(0);
00033 
00034 Cache::~Cache()
00035 {
00036 }
00037 
00038 CacheAccessor::~CacheAccessor()
00039 {
00040 }
00041 
00042 class TwoQPage : public CachePage, public TwoQVictim
00043 {
00044 public:
00045     TwoQPage(Cache &cache,PBuffer buffer)
00046         : CachePage(cache,buffer)
00047     {
00048     }
00049 };
00050 
00051 SharedCache Cache::newCache(
00052     CacheParams const &cacheParams,
00053     CacheAllocator *bufferAllocator)
00054 {
00055     typedef CacheImpl<
00056         TwoQPage,
00057         TwoQVictimPolicy<TwoQPage>
00058         > TwoQCache;
00059     return SharedCache(
00060         new TwoQCache(cacheParams,bufferAllocator),
00061         ClosableObjectDestructor());
00062 }
00063 
00064 SharedCache Cache::getCache()
00065 {
00066     return shared_from_this();
00067 }
00068 
00069 uint Cache::getMaxLockedPages()
00070 {
00071     return getAllocatedPageCount();
00072 }
00073 
00074 void Cache::setMaxLockedPages(uint)
00075 {
00076 }
00077 
00078 void Cache::setTxnId(TxnId)
00079 {
00080 }
00081 
00082 TxnId Cache::getTxnId() const
00083 {
00084     return IMPLICIT_TXN_ID;
00085 }
00086 
00087 void Cache::writeStats(StatsTarget &target)
00088 {
00089     CacheStats stats;
00090     collectStats(stats);
00091     target.writeCounter(
00092         "CacheHits", stats.nHits);
00093     target.writeCounter(
00094         "CacheHitsSinceInit", stats.nHitsSinceInit);
00095     target.writeCounter(
00096         "CacheRequests", stats.nRequests);
00097     target.writeCounter(
00098         "CacheRequestsSinceInit", stats.nRequestsSinceInit);
00099     target.writeCounter(
00100         "CacheVictimizations", stats.nVictimizations);
00101     target.writeCounter(
00102         "CacheVictimizationsSinceInit", stats.nVictimizationsSinceInit);
00103     target.writeCounter(
00104         "CacheDirtyPages", stats.nDirtyPages);
00105     target.writeCounter(
00106         "CachePagesRead", stats.nPageReads);
00107     target.writeCounter(
00108         "CachePagesReadSinceInit", stats.nPageReadsSinceInit);
00109     target.writeCounter(
00110         "CachePagesWritten", stats.nPageWrites);
00111     target.writeCounter(
00112         "CachePagesWrittenSinceInit", stats.nPageWritesSinceInit);
00113     target.writeCounter(
00114         "CachePagePrefetchesRejected", stats.nRejectedPrefetches);
00115     target.writeCounter(
00116         "CachePagePrefetchesRejectedSinceInit",
00117         stats.nRejectedPrefetchesSinceInit);
00118     target.writeCounter(
00119         "CachePageIoRetries", stats.nIoRetries);
00120     target.writeCounter(
00121         "CachePageIoRetriesSinceInit",
00122         stats.nIoRetriesSinceInit);
00123     target.writeCounter(
00124         "CachePagesPrefetched", stats.nSuccessfulPrefetches);
00125     target.writeCounter(
00126         "CachePagesPrefetchedSinceInit",
00127         stats.nSuccessfulPrefetchesSinceInit);
00128     target.writeCounter("CacheLazyWrites", stats.nLazyWrites);
00129     target.writeCounter("CacheLazyWritesSinceInit", stats.nLazyWritesSinceInit);
00130     target.writeCounter("CacheLazyWriteCalls", stats.nLazyWriteCalls);
00131     target.writeCounter(
00132         "CacheLazyWriteCallsSinceInit",
00133         stats.nLazyWriteCallsSinceInit);
00134     target.writeCounter("CacheVictimizationWrites", stats.nVictimizationWrites);
00135     target.writeCounter(
00136         "CacheVictimizationWritesSinceInit",
00137         stats.nVictimizationWritesSinceInit);
00138     target.writeCounter("CacheCheckpointWrites", stats.nCheckpointWrites);
00139     target.writeCounter(
00140         "CacheCheckpointWritesSinceInit",
00141         stats.nCheckpointWritesSinceInit);
00142     target.writeCounter(
00143         "CachePagesAllocated", stats.nMemPagesAllocated);
00144     target.writeCounter(
00145         "CachePagesUnused", stats.nMemPagesUnused);
00146     target.writeCounter(
00147         "CachePagesAllocationLimit", stats.nMemPagesMax);
00148 }
00149 
00150 // force references to some classes which aren't referenced elsewhere
00151 #ifdef __MSVC__
00152 class UnreferencedCacheStructs
00153 {
00154     LRUVictim lruVictim;
00155 };
00156 #endif
00157 
00158 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/cache/Cache.cpp#14 $");
00159 
00160 // End Cache.cpp

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