Permalink
Browse files

Array for multiple AntiCacheDB instances and support methods

  • Loading branch information...
1 parent d9da0fe commit 8d19ab1b5b429a8a44867da2d71705a6939fdd7d @mjgiardino mjgiardino committed Aug 28, 2014
@@ -131,6 +131,10 @@ class AntiCacheDB {
inline AntiCacheDBType getDBType() {
return m_dbType;
}
+
+ inline int getMaxBlockSize() {
+ return m_maxBlockSize;
+ }
protected:
ExecutorContext *m_executorContext;
string m_dbDir;
@@ -141,7 +145,7 @@ class AntiCacheDB {
int m_totalBlocks;
AntiCacheDBType m_dbType;
-
+ int m_maxBlockSize;
/*
* DB specific method of shutting down the database on destructor call
*/
@@ -541,7 +541,7 @@ bool AntiCacheEvictionManager::evictBlockToDisk(PersistentTable *table, const lo
// For now use the single AntiCacheDB from PersistentTable but in the future, this
// method to get the AntiCacheDB will have to choose which AntiCacheDB from to
// evict to
- AntiCacheDB* antiCacheDB = table->getAntiCacheDB();
+ AntiCacheDB* antiCacheDB = table->getAntiCacheDB(chooseDB());
int tuple_length = -1;
bool needs_flush = false;
@@ -741,7 +741,7 @@ bool AntiCacheEvictionManager::evictBlockToDiskInBatch(PersistentTable *table, P
// evictedTable->name().c_str(), evictedTable->schema()->debug().c_str());
// get the AntiCacheDB instance from the executorContext
- AntiCacheDB* antiCacheDB = table->getAntiCacheDB();
+ AntiCacheDB* antiCacheDB = table->getAntiCacheDB(chooseDB());
int tuple_length = -1;
bool needs_flush = false;
@@ -1187,6 +1187,14 @@ bool AntiCacheEvictionManager::readEvictedBlock(PersistentTable *table, int16_t
return true;
}
+
+// stub method that may either be implemented by plug in policies
+// or via class inheritance.
+
+int AntiCacheEvictionManager::chooseDB() {
+ return 0;
+}
+
/*
* Merges the unevicted block into the regular data table
*/
@@ -63,7 +63,9 @@ class AntiCacheEvictionManager {
bool mergeUnevictedTuples(PersistentTable *table);
bool readEvictedBlock(PersistentTable *table, int16_t block_id, int32_t tuple_offset);
//int numTuplesInEvictionList();
-
+
+ int chooseDB();
+
// -----------------------------------------
// Evicted Access Tracking Methods
// -----------------------------------------
@@ -28,6 +28,8 @@
#include "anticache/NVMAntiCacheDB.h"
#include "anticache/AntiCacheEvictionManager.h"
#include "execution/VoltDBEngine.h"
+#define MAX_LEVELS 5
+
#endif
namespace voltdb {
@@ -193,8 +195,8 @@ namespace voltdb {
* Return the handle to disk-based storage object that we
* can use to read and write tuples to
*/
- AntiCacheDB* getAntiCacheDB() const {
- return m_antiCacheDB;
+ AntiCacheDB* getAntiCacheDB(int level) const {
+ return m_antiCacheDB[level];
}
/**
@@ -204,6 +206,14 @@ namespace voltdb {
AntiCacheEvictionManager* getAntiCacheEvictionManager() const {
return m_antiCacheEvictionManager;
}
+
+ /**
+ * Return the AntiCacheDBType associated with the given AntiCacheDB
+ */
+
+ AntiCacheDBType getAntiCacheDBType(int level) {
+ return m_dbType[level];
+ }
/**
* Enable the anti-caching feature in the EE.
@@ -213,17 +223,24 @@ namespace voltdb {
void enableAntiCache(const VoltDBEngine *engine, std::string &dbDir, long blockSize, AntiCacheDBType dbType) {
assert(m_antiCacheEnabled == false);
m_antiCacheEnabled = true;
- m_dbType = dbType;
+ m_levels = 0;
+ addAntiCacheDB(dbDir, blockSize, dbType);
+ m_antiCacheEvictionManager = new AntiCacheEvictionManager(engine);
+ }
+
+ void addAntiCacheDB(std::string &dbDir, long blockSize, AntiCacheDBType dbType) {
+ assert(m_antiCacheEnabled == true);
+ m_dbType[m_levels] = dbType;
// MJG: need a better error return (throw exception?)
if (dbType == ANTICACHEDB_BERKELEY) {
- m_antiCacheDB = new BerkeleyAntiCacheDB(this, dbDir, blockSize);
+ m_antiCacheDB[m_levels] = new BerkeleyAntiCacheDB(this, dbDir, blockSize);
} else if (dbType == ANTICACHEDB_NVM) {
- m_antiCacheDB = new NVMAntiCacheDB(this, dbDir, blockSize);
+ m_antiCacheDB[m_levels] = new NVMAntiCacheDB(this, dbDir, blockSize);
} else {
VOLT_ERROR("Invalid AntiCacheDBType: %d! Aborting...", (int)dbType);
assert(m_antiCacheEnabled == false);
- }
- m_antiCacheEvictionManager = new AntiCacheEvictionManager(engine);
+ }
+ m_levels++;
}
#endif
@@ -299,9 +316,10 @@ namespace voltdb {
int64_t m_txnId;
#ifdef ANTICACHE
- AntiCacheDB *m_antiCacheDB;
+ AntiCacheDB *m_antiCacheDB[MAX_LEVELS];
AntiCacheEvictionManager *m_antiCacheEvictionManager;
- AntiCacheDBType m_dbType;
+ AntiCacheDBType m_dbType[MAX_LEVELS];
+ int m_levels;
#endif
#ifdef STORAGE_MMAP
@@ -247,9 +247,9 @@ uint32_t PersistentTable::getOldestTupleID()
return m_oldestTupleID;
}
-AntiCacheDB* PersistentTable::getAntiCacheDB()
+AntiCacheDB* PersistentTable::getAntiCacheDB(int level)
{
- return m_executorContext->getAntiCacheDB();
+ return m_executorContext->getAntiCacheDB(level);
}
int32_t PersistentTable::getTuplesEvicted()
@@ -278,7 +278,7 @@ class PersistentTable : public Table {
uint32_t getOldestTupleID();
void setNumTuplesInEvictionChain(int num_tuples);
int getNumTuplesInEvictionChain();
- AntiCacheDB* getAntiCacheDB();
+ AntiCacheDB* getAntiCacheDB(int level);
std::map<int16_t, int16_t> getUnevictedBlockIDs();
std::vector<char*> getUnevictedBlocks();
int32_t getMergeTupleOffset(int);

0 comments on commit 8d19ab1

Please sign in to comment.