Permalink
Browse files

Apply the count-min-sketch.

  • Loading branch information...
1 parent 6a73d4f commit b654e8b82c5e72b23d760207c0495c6ee6ae2e7a @malin1993ml malin1993ml committed Jan 5, 2016
View
@@ -312,6 +312,9 @@
json_spirit_reader.cpp
json_spirit_value.cpp
"""
+CTX.THIRD_PARTY_INPUT['mmh3'] = """
+ MurmurHash3.cpp
+"""
###############################################################################
# SPECIFY THE TESTS
@@ -1811,6 +1811,10 @@ bool AntiCacheEvictionManager::mergeUnevictedTuples(PersistentTable *table) {
// Evicted Access Tracking Methods
// -----------------------------------------
+#ifdef ANTICACHE_COUNTER
+const uint32_t AntiCacheEvictionManager::m_hash_seed[3] = {41, 239785, 878124560};
+#endif
+
void AntiCacheEvictionManager::recordEvictedAccess(catalog::Table* catalogTable, TableTuple *tuple) {
// FIXME: HACK HACK HACK
if (m_evicted_block_ids.size() > 100000) {
@@ -1838,6 +1842,35 @@ void AntiCacheEvictionManager::recordEvictedAccess(catalog::Table* catalogTable,
if (!m_update_access && (block_id & 0x10000000)) {
uint32_t _block_id = (uint32_t)(block_id & 0x0FFFFFFF);
int16_t ACID = (int16_t)((block_id & 0xE0000000) >> 29);
+
+
+
+ uint64_t key = ((uint64_t)_block_id << 32) + tuple_id;
+ uint64_t hash[2];
+
+ unsigned char min_sketch = 255;
+ for (int i = 0; i < SKETCH_HEIGHT; ++i) {
+ MurmurHash3_x64_128(&key, 8, m_hash_seed[i], hash);
+ //hash = MurmurHash64A(&key, 8, m_hash_seed[i]);
+ int j = hash[0] & SKETCH_MASK;
+ if (m_sketch[i][j] < 254) {
+ m_sketch[i][j]++;
+ }
+ if (m_sketch[i][j] < min_sketch)
+ min_sketch = m_sketch[i][j];
+ }
+
+ if (min_sketch > 10) {
+ m_evicted_tables_sync.push_back(catalogTable);
+ m_evicted_block_ids_sync.push_back(block_id);
+ m_evicted_offsets_sync.push_back(tuple_id);
+ m_update_access = true;
+ return;
+ //printf("greater than: %u %d %d\n", min_sketch, _block_id, tuple_id);
+ }
+
+
+
AntiCacheDB* antiCacheDB = m_db_lookup[ACID];
AntiCacheBlock* value = antiCacheDB->readBlock(_block_id, 0);
//char* unevicted_tuples = new char[value->getSize()];
@@ -35,13 +35,24 @@
#include "common/NValue.hpp"
#include "common/ValuePeeker.hpp"
#include "anticache/AntiCacheDB.h"
+#include "mmh3/MurmurHash3.h"
#include <vector>
#include <map>
#include <pthread.h>
#define MAX_DBS 8
+#ifdef ANTICACHE_COUNTER
+ //#define SKETCH_WIDTH 32768
+ //#define SKETCH_MASK 32767
+ #define SKETCH_WIDTH 16384
+ #define SKETCH_MASK 16383
+ //#define SKETCH_WIDTH 1048576
+ //#define SKETCH_MASK 1048575
+ #define SKETCH_HEIGHT 3
+#endif
+
namespace voltdb {
class Table;
@@ -108,7 +119,8 @@ class AntiCacheEvictionManager {
#ifdef ANTICACHE_COUNTER
bool m_update_access;
- unsigned char m_sketch[3][150000];
+ unsigned char m_sketch[SKETCH_HEIGHT][SKETCH_WIDTH];
+ static const uint32_t m_hash_seed[3];
#endif
protected:
@@ -1344,7 +1344,20 @@ int VoltDBEngine::getStats(int selector, int locators[], int numLocators,
VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, message);
}
}*/
-
+#ifdef ANTICACHE_COUNTER
+ AntiCacheEvictionManager* eviction_manager = m_executorContext->getAntiCacheEvictionManager();
+ if (eviction_manager != NULL) {
+ VOLT_ERROR("We have reset the sketch counter of size %ld :)", sizeof(eviction_manager->m_sketch));
+ /*
+ int sum = 0;
+ for (int i = 0; i < SKETCH_WIDTH; ++i)
+ sum += eviction_manager->m_sketch[0][i];
+ printf("cardinality: %d\n", sum);
+ */
+
+ memset(eviction_manager->m_sketch, 0, sizeof(eviction_manager->m_sketch));
+ }
+#endif
resultTable = m_statsManager.getStats(
(StatisticsSelectorType) selector, locatorIds, interval,
now);
Oops, something went wrong.

0 comments on commit b654e8b

Please sign in to comment.