Skip to content
This repository was archived by the owner on Aug 10, 2025. It is now read-only.

Commit 8d19ab1

Browse files
committed
Array for multiple AntiCacheDB instances and support methods
1 parent d9da0fe commit 8d19ab1

6 files changed

Lines changed: 48 additions & 16 deletions

File tree

src/ee/anticache/AntiCacheDB.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ class AntiCacheDB {
131131
inline AntiCacheDBType getDBType() {
132132
return m_dbType;
133133
}
134+
135+
inline int getMaxBlockSize() {
136+
return m_maxBlockSize;
137+
}
134138
protected:
135139
ExecutorContext *m_executorContext;
136140
string m_dbDir;
@@ -141,7 +145,7 @@ class AntiCacheDB {
141145
int m_totalBlocks;
142146

143147
AntiCacheDBType m_dbType;
144-
148+
int m_maxBlockSize;
145149
/*
146150
* DB specific method of shutting down the database on destructor call
147151
*/

src/ee/anticache/AntiCacheEvictionManager.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ bool AntiCacheEvictionManager::evictBlockToDisk(PersistentTable *table, const lo
541541
// For now use the single AntiCacheDB from PersistentTable but in the future, this
542542
// method to get the AntiCacheDB will have to choose which AntiCacheDB from to
543543
// evict to
544-
AntiCacheDB* antiCacheDB = table->getAntiCacheDB();
544+
AntiCacheDB* antiCacheDB = table->getAntiCacheDB(chooseDB());
545545
int tuple_length = -1;
546546
bool needs_flush = false;
547547

@@ -741,7 +741,7 @@ bool AntiCacheEvictionManager::evictBlockToDiskInBatch(PersistentTable *table, P
741741
// evictedTable->name().c_str(), evictedTable->schema()->debug().c_str());
742742

743743
// get the AntiCacheDB instance from the executorContext
744-
AntiCacheDB* antiCacheDB = table->getAntiCacheDB();
744+
AntiCacheDB* antiCacheDB = table->getAntiCacheDB(chooseDB());
745745
int tuple_length = -1;
746746
bool needs_flush = false;
747747

@@ -1187,6 +1187,14 @@ bool AntiCacheEvictionManager::readEvictedBlock(PersistentTable *table, int16_t
11871187
return true;
11881188
}
11891189

1190+
1191+
// stub method that may either be implemented by plug in policies
1192+
// or via class inheritance.
1193+
1194+
int AntiCacheEvictionManager::chooseDB() {
1195+
return 0;
1196+
}
1197+
11901198
/*
11911199
* Merges the unevicted block into the regular data table
11921200
*/

src/ee/anticache/AntiCacheEvictionManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ class AntiCacheEvictionManager {
6363
bool mergeUnevictedTuples(PersistentTable *table);
6464
bool readEvictedBlock(PersistentTable *table, int16_t block_id, int32_t tuple_offset);
6565
//int numTuplesInEvictionList();
66-
66+
67+
int chooseDB();
68+
6769
// -----------------------------------------
6870
// Evicted Access Tracking Methods
6971
// -----------------------------------------

src/ee/common/executorcontext.hpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "anticache/NVMAntiCacheDB.h"
2929
#include "anticache/AntiCacheEvictionManager.h"
3030
#include "execution/VoltDBEngine.h"
31+
#define MAX_LEVELS 5
32+
3133
#endif
3234

3335
namespace voltdb {
@@ -193,8 +195,8 @@ namespace voltdb {
193195
* Return the handle to disk-based storage object that we
194196
* can use to read and write tuples to
195197
*/
196-
AntiCacheDB* getAntiCacheDB() const {
197-
return m_antiCacheDB;
198+
AntiCacheDB* getAntiCacheDB(int level) const {
199+
return m_antiCacheDB[level];
198200
}
199201

200202
/**
@@ -204,6 +206,14 @@ namespace voltdb {
204206
AntiCacheEvictionManager* getAntiCacheEvictionManager() const {
205207
return m_antiCacheEvictionManager;
206208
}
209+
210+
/**
211+
* Return the AntiCacheDBType associated with the given AntiCacheDB
212+
*/
213+
214+
AntiCacheDBType getAntiCacheDBType(int level) {
215+
return m_dbType[level];
216+
}
207217

208218
/**
209219
* Enable the anti-caching feature in the EE.
@@ -213,17 +223,24 @@ namespace voltdb {
213223
void enableAntiCache(const VoltDBEngine *engine, std::string &dbDir, long blockSize, AntiCacheDBType dbType) {
214224
assert(m_antiCacheEnabled == false);
215225
m_antiCacheEnabled = true;
216-
m_dbType = dbType;
226+
m_levels = 0;
227+
addAntiCacheDB(dbDir, blockSize, dbType);
228+
m_antiCacheEvictionManager = new AntiCacheEvictionManager(engine);
229+
}
230+
231+
void addAntiCacheDB(std::string &dbDir, long blockSize, AntiCacheDBType dbType) {
232+
assert(m_antiCacheEnabled == true);
233+
m_dbType[m_levels] = dbType;
217234
// MJG: need a better error return (throw exception?)
218235
if (dbType == ANTICACHEDB_BERKELEY) {
219-
m_antiCacheDB = new BerkeleyAntiCacheDB(this, dbDir, blockSize);
236+
m_antiCacheDB[m_levels] = new BerkeleyAntiCacheDB(this, dbDir, blockSize);
220237
} else if (dbType == ANTICACHEDB_NVM) {
221-
m_antiCacheDB = new NVMAntiCacheDB(this, dbDir, blockSize);
238+
m_antiCacheDB[m_levels] = new NVMAntiCacheDB(this, dbDir, blockSize);
222239
} else {
223240
VOLT_ERROR("Invalid AntiCacheDBType: %d! Aborting...", (int)dbType);
224241
assert(m_antiCacheEnabled == false);
225-
}
226-
m_antiCacheEvictionManager = new AntiCacheEvictionManager(engine);
242+
}
243+
m_levels++;
227244
}
228245
#endif
229246

@@ -299,9 +316,10 @@ namespace voltdb {
299316
int64_t m_txnId;
300317

301318
#ifdef ANTICACHE
302-
AntiCacheDB *m_antiCacheDB;
319+
AntiCacheDB *m_antiCacheDB[MAX_LEVELS];
303320
AntiCacheEvictionManager *m_antiCacheEvictionManager;
304-
AntiCacheDBType m_dbType;
321+
AntiCacheDBType m_dbType[MAX_LEVELS];
322+
int m_levels;
305323
#endif
306324

307325
#ifdef STORAGE_MMAP

src/ee/storage/persistenttable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ uint32_t PersistentTable::getOldestTupleID()
247247
return m_oldestTupleID;
248248
}
249249

250-
AntiCacheDB* PersistentTable::getAntiCacheDB()
250+
AntiCacheDB* PersistentTable::getAntiCacheDB(int level)
251251
{
252-
return m_executorContext->getAntiCacheDB();
252+
return m_executorContext->getAntiCacheDB(level);
253253
}
254254

255255
int32_t PersistentTable::getTuplesEvicted()

src/ee/storage/persistenttable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class PersistentTable : public Table {
278278
uint32_t getOldestTupleID();
279279
void setNumTuplesInEvictionChain(int num_tuples);
280280
int getNumTuplesInEvictionChain();
281-
AntiCacheDB* getAntiCacheDB();
281+
AntiCacheDB* getAntiCacheDB(int level);
282282
std::map<int16_t, int16_t> getUnevictedBlockIDs();
283283
std::vector<char*> getUnevictedBlocks();
284284
int32_t getMergeTupleOffset(int);

0 commit comments

Comments
 (0)