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

Commit b654e8b

Browse files
committed
Apply the count-min-sketch.
1 parent 6a73d4f commit b654e8b

6 files changed

Lines changed: 625 additions & 2 deletions

File tree

build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@
312312
json_spirit_reader.cpp
313313
json_spirit_value.cpp
314314
"""
315+
CTX.THIRD_PARTY_INPUT['mmh3'] = """
316+
MurmurHash3.cpp
317+
"""
315318

316319
###############################################################################
317320
# SPECIFY THE TESTS

src/ee/anticache/AntiCacheEvictionManager.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,10 @@ bool AntiCacheEvictionManager::mergeUnevictedTuples(PersistentTable *table) {
18111811
// Evicted Access Tracking Methods
18121812
// -----------------------------------------
18131813

1814+
#ifdef ANTICACHE_COUNTER
1815+
const uint32_t AntiCacheEvictionManager::m_hash_seed[3] = {41, 239785, 878124560};
1816+
#endif
1817+
18141818
void AntiCacheEvictionManager::recordEvictedAccess(catalog::Table* catalogTable, TableTuple *tuple) {
18151819
// FIXME: HACK HACK HACK
18161820
if (m_evicted_block_ids.size() > 100000) {
@@ -1838,6 +1842,35 @@ void AntiCacheEvictionManager::recordEvictedAccess(catalog::Table* catalogTable,
18381842
if (!m_update_access && (block_id & 0x10000000)) {
18391843
uint32_t _block_id = (uint32_t)(block_id & 0x0FFFFFFF);
18401844
int16_t ACID = (int16_t)((block_id & 0xE0000000) >> 29);
1845+
1846+
1847+
1848+
uint64_t key = ((uint64_t)_block_id << 32) + tuple_id;
1849+
uint64_t hash[2];
1850+
1851+
unsigned char min_sketch = 255;
1852+
for (int i = 0; i < SKETCH_HEIGHT; ++i) {
1853+
MurmurHash3_x64_128(&key, 8, m_hash_seed[i], hash);
1854+
//hash = MurmurHash64A(&key, 8, m_hash_seed[i]);
1855+
int j = hash[0] & SKETCH_MASK;
1856+
if (m_sketch[i][j] < 254) {
1857+
m_sketch[i][j]++;
1858+
}
1859+
if (m_sketch[i][j] < min_sketch)
1860+
min_sketch = m_sketch[i][j];
1861+
}
1862+
1863+
if (min_sketch > 10) {
1864+
m_evicted_tables_sync.push_back(catalogTable);
1865+
m_evicted_block_ids_sync.push_back(block_id);
1866+
m_evicted_offsets_sync.push_back(tuple_id);
1867+
m_update_access = true;
1868+
return;
1869+
//printf("greater than: %u %d %d\n", min_sketch, _block_id, tuple_id);
1870+
}
1871+
1872+
1873+
18411874
AntiCacheDB* antiCacheDB = m_db_lookup[ACID];
18421875
AntiCacheBlock* value = antiCacheDB->readBlock(_block_id, 0);
18431876
//char* unevicted_tuples = new char[value->getSize()];

src/ee/anticache/AntiCacheEvictionManager.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,24 @@
3535
#include "common/NValue.hpp"
3636
#include "common/ValuePeeker.hpp"
3737
#include "anticache/AntiCacheDB.h"
38+
#include "mmh3/MurmurHash3.h"
3839

3940
#include <vector>
4041
#include <map>
4142
#include <pthread.h>
4243

4344
#define MAX_DBS 8
4445

46+
#ifdef ANTICACHE_COUNTER
47+
//#define SKETCH_WIDTH 32768
48+
//#define SKETCH_MASK 32767
49+
#define SKETCH_WIDTH 16384
50+
#define SKETCH_MASK 16383
51+
//#define SKETCH_WIDTH 1048576
52+
//#define SKETCH_MASK 1048575
53+
#define SKETCH_HEIGHT 3
54+
#endif
55+
4556
namespace voltdb {
4657

4758
class Table;
@@ -108,7 +119,8 @@ class AntiCacheEvictionManager {
108119

109120
#ifdef ANTICACHE_COUNTER
110121
bool m_update_access;
111-
unsigned char m_sketch[3][150000];
122+
unsigned char m_sketch[SKETCH_HEIGHT][SKETCH_WIDTH];
123+
static const uint32_t m_hash_seed[3];
112124
#endif
113125

114126
protected:

src/ee/execution/VoltDBEngine.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,20 @@ int VoltDBEngine::getStats(int selector, int locators[], int numLocators,
13441344
VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, message);
13451345
}
13461346
}*/
1347-
1347+
#ifdef ANTICACHE_COUNTER
1348+
AntiCacheEvictionManager* eviction_manager = m_executorContext->getAntiCacheEvictionManager();
1349+
if (eviction_manager != NULL) {
1350+
VOLT_ERROR("We have reset the sketch counter of size %ld :)", sizeof(eviction_manager->m_sketch));
1351+
/*
1352+
int sum = 0;
1353+
for (int i = 0; i < SKETCH_WIDTH; ++i)
1354+
sum += eviction_manager->m_sketch[0][i];
1355+
printf("cardinality: %d\n", sum);
1356+
*/
1357+
1358+
memset(eviction_manager->m_sketch, 0, sizeof(eviction_manager->m_sketch));
1359+
}
1360+
#endif
13481361
resultTable = m_statsManager.getStats(
13491362
(StatisticsSelectorType) selector, locatorIds, interval,
13501363
now);

0 commit comments

Comments
 (0)