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

Commit ee2301b

Browse files
committed
Two more fixes for anticache:
1. Need to check whether a tuple has already been unevicted. 2. BerkeleyDB does not check the validation of blockID. This will lead to duplicated read an incorrect stats.
1 parent c842629 commit ee2301b

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

src/ee/anticache/AntiCacheDB.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ void AntiCacheDB::setStatsSource() {
139139
//m_stats = new AntiCacheStats(NULL, this);
140140
}
141141

142-
void AntiCacheDB::removeSingleTupleStats(uint16_t blockId) {
143-
m_bytesUnevicted += static_cast<int32_t>( blockSize[blockId] / tupleInBlock[blockId]);
144-
evictedTupleInBlock[blockId]--;
142+
void AntiCacheDB::removeSingleTupleStats(uint16_t blockId, int32_t sign) {
143+
m_bytesUnevicted += static_cast<int32_t>( blockSize[blockId] / tupleInBlock[blockId]) * sign;
144+
evictedTupleInBlock[blockId] -= sign;
145145
}
146146

147147
}

src/ee/anticache/AntiCacheDB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class AntiCacheDB {
213213
* Because of the structure of AnticacheDB we have to have this another
214214
* function.
215215
*/
216-
void removeSingleTupleStats(uint16_t blockId);
216+
void removeSingleTupleStats(uint16_t blockId, int32_t sign);
217217

218218
/**
219219
* Return the AntiCacheID number.

src/ee/anticache/AntiCacheEvictionManager.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,9 @@ bool AntiCacheEvictionManager::readEvictedBlock(PersistentTable *table, int32_t
12101210

12111211
table->insertUnevictedBlock(table->getUnevictedBlocks(already_unevicted - 1));
12121212
table->insertTupleOffset(tuple_offset);
1213+
table->insertBlockID(block_id);
12131214

1214-
antiCacheDB->removeSingleTupleStats(_block_id);
1215+
antiCacheDB->removeSingleTupleStats(_block_id, 1);
12151216

12161217
VOLT_DEBUG("BLOCK %u TUPLE %d - unevicted blocks size is %d",
12171218
block_id, tuple_offset, (int)table->unevictedBlocksSize());
@@ -1271,6 +1272,7 @@ bool AntiCacheEvictionManager::readEvictedBlock(PersistentTable *table, int32_t
12711272

12721273
table->insertUnevictedBlock(unevicted_tuples);
12731274
table->insertTupleOffset(tuple_offset);
1275+
table->insertBlockID(block_id);
12741276

12751277

12761278
table->insertUnevictedBlockID(std::pair<int32_t,int32_t>(block_id, table->unevictedBlocksSize()));
@@ -1613,6 +1615,13 @@ bool AntiCacheEvictionManager::mergeUnevictedTuples(PersistentTable *table) {
16131615
VOLT_TRACE("%s", tableNames[j].c_str());
16141616
}
16151617

1618+
// Get ACDB for this tuple. That is used for correct stats tuple-merge strategy
1619+
int32_t block_id = table->getBlockID(i);
1620+
uint16_t _block_id = (int16_t)(block_id & 0x0000FFFF);
1621+
int16_t ACID = (int16_t)((block_id & 0x00070000) >> 16);
1622+
VOLT_DEBUG("block_id: %8x ACID: %d _block_id: %d blocking: %d\n", block_id, ACID, _block_id, (int)blocking);
1623+
AntiCacheDB* antiCacheDB = m_db_lookup[ACID];
1624+
16161625
int count = 0;
16171626
for (std::vector<std::string>::iterator it = tableNames.begin() ; it != tableNames.end(); ++it){
16181627
PersistentTable *tableInBlock = dynamic_cast<PersistentTable*>(m_engine->getTable(*it));
@@ -1623,7 +1632,12 @@ bool AntiCacheEvictionManager::mergeUnevictedTuples(PersistentTable *table) {
16231632
int64_t bytes_unevicted = 0;
16241633
int tuplesRead = 0;
16251634
if(!table->mergeStrategy()) {
1626-
bytes_unevicted += tableInBlock->unevictTuple(&in, merge_tuple_offset, merge_tuple_offset, (bool)table->mergeStrategy());
1635+
int64_t current_unevicted = tableInBlock->unevictTuple(&in, merge_tuple_offset, merge_tuple_offset, (bool)table->mergeStrategy());
1636+
bytes_unevicted += current_unevicted;
1637+
if (current_unevicted == 0) {
1638+
antiCacheDB->removeSingleTupleStats(_block_id, -1);
1639+
//printf("Add back: %u %u\n", ACID, _block_id);
1640+
}
16271641
} else {
16281642
for (int j = 0; j < num_tuples_in_block; j++)
16291643
{
@@ -1707,6 +1721,7 @@ bool AntiCacheEvictionManager::mergeUnevictedTuples(PersistentTable *table) {
17071721
}
17081722
table->clearUnevictedBlocks();
17091723
table->clearMergeTupleOffsets();
1724+
table->clearBlockIDs();
17101725
VOLT_DEBUG("unevicted blockIDs size %d", static_cast<int>(table->getUnevictedBlockIDs().size()));
17111726
VOLT_DEBUG("unevicted blocks size %d", static_cast<int>(table->unevictedBlocksSize()));
17121727

src/ee/anticache/BerkeleyAntiCacheDB.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ void BerkeleyAntiCacheDB::writeBlock(const std::string tableName,
179179

180180

181181
pushBlockLRU(blockId);
182+
m_blockSet.insert(blockId);
182183

183184
delete [] databuf_;
184185
}
185186

186187
bool BerkeleyAntiCacheDB::validateBlock(uint16_t blockId) {
187-
return true;
188+
189+
//if (m_blockSet.find(blockId) == m_blockSet.end())
190+
// printf("Berkeley block already unevicted!\n");
191+
return m_blockSet.find(blockId) != m_blockSet.end();
188192
}
189193

190194
AntiCacheBlock* BerkeleyAntiCacheDB::readBlock(uint16_t blockId, bool isMigrate) {
@@ -228,9 +232,11 @@ AntiCacheBlock* BerkeleyAntiCacheDB::readBlock(uint16_t blockId, bool isMigrate)
228232
}
229233

230234
removeBlockLRU(blockId);
235+
m_blockSet.erase(blockId);
231236

232-
if (!(this->isBlockMerge())) { //i.e. tuple merge
237+
if (!(this->isBlockMerge()) && !isMigrate) { //i.e. tuple merge
233238
pushBlockLRU(blockId); // update block LRU
239+
m_blockSet.insert(blockId);
234240
}
235241

236242
/*uint16_t rm_block = removeBlockLRU(blockId);

src/ee/anticache/BerkeleyAntiCacheDB.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <map>
1010
#include <vector>
11+
#include <set>
1112

1213
using namespace std;
1314

@@ -106,6 +107,7 @@ class BerkeleyAntiCacheDB : public AntiCacheDB {
106107
DbEnv* m_dbEnv;
107108
Db* m_db;
108109
Dbt m_value;
110+
std::set <uint16_t> m_blockSet;
109111
};
110112

111113
}

src/ee/storage/persistenttable.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ int32_t PersistentTable::getMergeTupleOffset(int i)
363363
{
364364
return m_mergeTupleOffset[i];
365365
}
366+
367+
int32_t PersistentTable::getBlockID(int i)
368+
{
369+
return m_blockIDs[i];
370+
}
371+
366372
char* PersistentTable::getUnevictedBlocks(int i)
367373
{
368374
return m_unevictedBlocks[i];
@@ -377,6 +383,11 @@ void PersistentTable::insertTupleOffset(int32_t tuple_offset)
377383
m_mergeTupleOffset.push_back(tuple_offset);
378384
}
379385

386+
void PersistentTable::insertBlockID(int32_t ACID)
387+
{
388+
m_blockIDs.push_back(ACID);
389+
}
390+
380391
int32_t PersistentTable::getTuplesRead()
381392
{
382393
return m_tuplesRead;
@@ -414,6 +425,11 @@ void PersistentTable::clearMergeTupleOffsets()
414425
m_mergeTupleOffset.clear();
415426
}
416427

428+
void PersistentTable::clearBlockIDs()
429+
{
430+
m_blockIDs.clear();
431+
}
432+
417433
int64_t PersistentTable::unevictTuple(ReferenceSerializeInput * in, int j, int merge_tuple_offset, bool blockMerge){
418434
TableTuple evicted_tuple = m_evictedTable->tempTuple();
419435
// get a free tuple and increment the count of tuples current used
@@ -435,6 +451,11 @@ int64_t PersistentTable::unevictTuple(ReferenceSerializeInput * in, int j, int m
435451
// Note, this goal of the section below is to get a tuple that points to the tuple in the EvictedTable and has the
436452
// schema of the evicted tuple. However, the lookup has to be done using the schema of the original (unevicted) version
437453
m_tmpTarget2 = lookupTuple(m_tmpTarget1); // lookup the tuple in the table
454+
//printf("%d\n", m_tmpTarget2.isEvicted());
455+
if (!m_tmpTarget2.isEvicted()) {
456+
deleteTupleStorage(m_tmpTarget1);
457+
return 0;
458+
}
438459
evicted_tuple.move(m_tmpTarget2.address());
439460
static_cast<EvictedTable*>(m_evictedTable)->deleteEvictedTuple(evicted_tuple); // delete the EvictedTable tuple
440461

src/ee/storage/persistenttable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class PersistentTable : public Table {
282282
std::map<int32_t, int32_t> getUnevictedBlockIDs();
283283
std::vector<char*> getUnevictedBlocks();
284284
int32_t getMergeTupleOffset(int);
285+
int32_t getBlockID(int);
285286
bool mergeStrategy();
286287
int32_t getTuplesEvicted();
287288
void setTuplesEvicted(int32_t tuplesEvicted);
@@ -300,6 +301,7 @@ class PersistentTable : public Table {
300301
bool removeUnevictedBlockID(int32_t blockId);
301302
void insertUnevictedBlock(char* unevicted_tuples);
302303
void insertTupleOffset(int32_t tuple_offset);
304+
void insertBlockID(int32_t);
303305
int isAlreadyUnEvicted(int32_t blockId);
304306
int32_t getTuplesRead();
305307
void setTuplesRead(int32_t tuplesRead);
@@ -310,6 +312,7 @@ class PersistentTable : public Table {
310312
int64_t unevictTuple(ReferenceSerializeInput * in, int j, int merge_tuple_offset, bool blockMerge);
311313
void clearUnevictedBlocks(int i);
312314
void clearUnevictedBlockIDs();
315+
void clearBlockIDs();
313316
char* getUnevictedBlocks(int i);
314317
int unevictedBlocksSize();
315318
std::vector<AntiCacheDB*> allACDBs() const;
@@ -384,6 +387,7 @@ class PersistentTable : public Table {
384387
// std::vector<int16_t> m_unevictedBlockIDs;
385388
std::vector<char*> m_unevictedBlocks;
386389
std::vector<int32_t> m_mergeTupleOffset;
390+
std::vector<int32_t> m_blockIDs;
387391

388392
std::map<int, int> m_unevictedTuplesPerBlocks;
389393

0 commit comments

Comments
 (0)