Skip to content

Commit

Permalink
Apply the count-min-sketch.
Browse files Browse the repository at this point in the history
  • Loading branch information
linmagit committed Jan 5, 2016
1 parent 6a73d4f commit b654e8b
Show file tree
Hide file tree
Showing 6 changed files with 625 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@
json_spirit_reader.cpp
json_spirit_value.cpp
"""
CTX.THIRD_PARTY_INPUT['mmh3'] = """
MurmurHash3.cpp
"""

###############################################################################
# SPECIFY THE TESTS
Expand Down
33 changes: 33 additions & 0 deletions src/ee/anticache/AntiCacheEvictionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()];
Expand Down
14 changes: 13 additions & 1 deletion src/ee/anticache/AntiCacheEvictionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion src/ee/execution/VoltDBEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit b654e8b

Please sign in to comment.