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

Commit e1bca3b

Browse files
committed
Checkpoint for EE part's AntiCache stats.
1 parent ca25aa2 commit e1bca3b

File tree

10 files changed

+108
-20
lines changed

10 files changed

+108
-20
lines changed

build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@
420420
EvictedTupleAccessException.cpp
421421
UnknownBlockAccessException.cpp
422422
FullBackingStoreException.cpp
423+
AntiCacheStats.cpp
423424
AntiCacheDB.cpp
424425
BerkeleyAntiCacheDB.cpp
425426
NVMAntiCacheDB.cpp

src/ee/anticache/AntiCacheDB.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "anticache/AntiCacheDB.h"
2727
#include "anticache/UnknownBlockAccessException.h"
28+
#include "anticache/AntiCacheStats.h"
2829
#include "common/debuglog.h"
2930
#include "common/FatalException.hpp"
3031
#include "common/executorcontext.hpp"
@@ -65,10 +66,13 @@ AntiCacheDB::AntiCacheDB(ExecutorContext *ctx, std::string db_dir, long blockSiz
6566
m_blocksEvicted = 0;
6667
m_bytesUnevicted = 0;
6768
m_blocksUnevicted = 0;
69+
70+
m_stats = new AntiCacheStats(NULL, this);
6871

6972
}
7073

7174
AntiCacheDB::~AntiCacheDB() {
75+
delete m_stats;
7276
}
7377

7478
AntiCacheBlock* AntiCacheDB::getLRUBlock() {
@@ -120,6 +124,9 @@ uint16_t AntiCacheDB::popBlockLRU() {
120124
return blockId;
121125
}
122126

127+
void AntiCacheDB::setStatsSource() {
128+
//m_stats = new AntiCacheStats(NULL, this);
129+
}
123130

124131
}
125132

src/ee/anticache/AntiCacheDB.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace voltdb {
4747

4848
class ExecutorContext;
4949
class AntiCacheDB;
50+
class AntiCacheStats;
5051

5152
/**
5253
* Wrapper class for an evicted block that has been read back in
@@ -121,6 +122,8 @@ class AntiCacheDB {
121122
* Flush the buffered blocks to disk.
122123
*/
123124
virtual void flushBlocks() = 0;
125+
126+
virtual void setStatsSource();
124127

125128
/**
126129
* Return the next BlockId to use in the anti-cache database
@@ -198,6 +201,10 @@ class AntiCacheDB {
198201
inline void setACID(int16_t ACID) {
199202
m_ACID = ACID;
200203
}
204+
205+
virtual inline AntiCacheStats* getACDBStats() {
206+
return m_stats;
207+
}
201208

202209
/**
203210
* Return the AntiCacheID number.
@@ -318,7 +325,7 @@ class AntiCacheDB {
318325
int64_t m_bytesUnevicted;
319326
int32_t m_blocksUnevicted;
320327

321-
328+
voltdb::AntiCacheStats* m_stats;
322329

323330
/* we need to test whether a deque or list is better. If we push/pop more than we
324331
* remove, this is better. otherwise, let's use a list

src/ee/anticache/AntiCacheStats.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ vector<string> AntiCacheStats::generateAntiCacheStatsColumnNames() {
3333

3434
columnNames.push_back("ANTICACHE_ID");
3535
columnNames.push_back("TABLE_ID");
36+
columnNames.push_back("ANTICACHEDB_TYPE");
3637

3738
columnNames.push_back("ANTICACHE_LAST_BLOCKS_EVICTED");
3839
columnNames.push_back("ANTICACHE_LAST_BYTES_EVICTED");
@@ -68,6 +69,11 @@ void AntiCacheStats::populateAntiCacheStatsSchema(
6869
columnLengths.push_back(NValue::getTupleStorageSize(VALUE_TYPE_INTEGER));
6970
allowNull.push_back(false);
7071

72+
// AntiCacheDB_TYPE
73+
types.push_back(VALUE_TYPE_INTEGER);
74+
columnLengths.push_back(NValue::getTupleStorageSize(VALUE_TYPE_INTEGER));
75+
allowNull.push_back(false);
76+
7177
//ANTICACHE_LAST_BLOCKS_EVICTED
7278
types.push_back(VALUE_TYPE_INTEGER);
7379
columnLengths.push_back(NValue::getTupleStorageSize(VALUE_TYPE_INTEGER));
@@ -171,10 +177,12 @@ AntiCacheStats::AntiCacheStats(Table* table, AntiCacheDB* acdb)
171177
m_lastBlocksUnevicted = 0;
172178
m_lastBytesUnevicted = 0;
173179

180+
/*
174181
m_currentBlocksEvicted = 0;
175182
m_currentBytesEvicted = 0;
176183
m_currentBlocksUnevicted = 0;
177184
m_currentBytesUnevicted = 0;
185+
*/
178186

179187

180188
m_currentEvictedBlocks = 0;
@@ -201,7 +209,7 @@ void AntiCacheStats::configure(
201209
CatalogId partitionId,
202210
CatalogId databaseId) {
203211
StatsSource::configure(name, hostId, hostname, siteId, partitionId, databaseId);
204-
m_acid = acdb->getACID();
212+
m_acid = m_acdb->getACID();
205213
}
206214

207215
/**
@@ -218,7 +226,7 @@ vector<string> AntiCacheStats::generateStatsColumnNames() {
218226
*/
219227
void AntiCacheStats::updateStatsTuple(TableTuple *tuple) {
220228

221-
AntiCacheDB acdb = m_acdb;
229+
AntiCacheDB* acdb = m_acdb;
222230

223231
int32_t totalBlocksEvicted = acdb->getBlocksEvicted();
224232
int64_t totalBytesEvicted = acdb->getBytesEvicted();
@@ -243,42 +251,45 @@ void AntiCacheStats::updateStatsTuple(TableTuple *tuple) {
243251
tuple->setNValue(
244252
StatsSource::m_columnName2Index["ANTICACHE_ID"],
245253
ValueFactory::getIntegerValue(m_acid));
254+
tuple->setNValue(
255+
StatsSource::m_columnName2Index["ANTICACHEDB_TYPE"],
256+
ValueFactory::getIntegerValue(acdb->getDBType()));
246257
tuple->setNValue(
247258
StatsSource::m_columnName2Index["ANTICACHE_LAST_BLOCKS_EVICTED"],
248-
ValueFactory::getIntegerValue());
259+
ValueFactory::getIntegerValue(m_lastBlocksEvicted));
249260
tuple->setNValue(
250261
StatsSource::m_columnName2Index["ANTICACHE_LAST_BYTES_EVICTED"],
251-
ValueFactory::getBigIntValue());
262+
ValueFactory::getBigIntValue(m_lastBytesEvicted));
252263
tuple->setNValue(
253264
StatsSource::m_columnName2Index["ANTICACHE_LAST_BLOCKS_UNEVICTED"],
254-
ValueFactory::getIntegerValue());
265+
ValueFactory::getIntegerValue(m_lastBlocksUnevicted));
255266
tuple->setNValue(
256267
StatsSource::m_columnName2Index["ANTICACHE_LAST_BYTES_UNEVICTED"],
257-
ValueFactory::getBigIntValue());
268+
ValueFactory::getBigIntValue(m_lastBytesUnevicted));
258269
tuple->setNValue(
259270
StatsSource::m_columnName2Index["ANTICACHE_TOTAL_BLOCKS_EVICTED"],
260-
ValueFactory::getIntegerValue());
271+
ValueFactory::getIntegerValue(m_totalBlocksEvicted));
261272
tuple->setNValue(
262273
StatsSource::m_columnName2Index["ANTICACHE_TOTAL_BYTES_EVICTED"],
263-
ValueFactory::getBigIntValue());
274+
ValueFactory::getBigIntValue(m_totalBytesEvicted));
264275
tuple->setNValue(
265276
StatsSource::m_columnName2Index["ANTICACHE_TOTAL_BLOCKS_UNEVICTED"],
266-
ValueFactory::getIntegerValue());
277+
ValueFactory::getIntegerValue(m_totalBlocksUnevicted));
267278
tuple->setNValue(
268279
StatsSource::m_columnName2Index["ANTICACHE_TOTAL_BYTES_UNEVICTED"],
269-
ValueFactory::getBigIntValue());
280+
ValueFactory::getBigIntValue(m_totalBytesUnevicted));
270281
tuple->setNValue(
271282
StatsSource::m_columnName2Index["ANTICACHE_BLOCKS_STORED"],
272-
ValueFactory::getIntegerValue());
283+
ValueFactory::getIntegerValue(m_totalBlocksEvicted - m_totalBlocksUnevicted));
273284
tuple->setNValue(
274285
StatsSource::m_columnName2Index["ANTICACHE_BYTES_STORED"],
275-
ValueFactory::getBigIntValue());
286+
ValueFactory::getBigIntValue(m_totalBytesEvicted - m_totalBytesUnevicted));
276287
tuple->setNValue(
277288
StatsSource::m_columnName2Index["ANTICACHE_BLOCKS_FREE"],
278-
ValueFactory::getIntegerValue());
289+
ValueFactory::getIntegerValue(m_currentFreeBlocks));
279290
tuple->setNValue(
280291
StatsSource::m_columnName2Index["ANTICACHE_BYTES_FREE"],
281-
ValueFactory::getBigIntValue());
292+
ValueFactory::getBigIntValue(m_currentFreeBytes));
282293

283294
}
284295

@@ -294,6 +305,6 @@ void AntiCacheStats::populateSchema(
294305
}
295306

296307
AntiCacheStats::~AntiCacheStats() {
297-
m_tableName.free();
298-
m_tableType.free();
308+
//m_tableName.free();
309+
//m_tableType.free();
299310
}

src/ee/anticache/AntiCacheStats.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class AntiCacheStats : public voltdb::StatsSource {
7676
voltdb::CatalogId partitionId,
7777
voltdb::CatalogId databaseId);
7878

79+
virtual ~AntiCacheStats();
80+
7981
protected:
8082

8183
/**
@@ -96,14 +98,16 @@ class AntiCacheStats : public voltdb::StatsSource {
9698
*/
9799
virtual void populateSchema(std::vector<voltdb::ValueType> &types, std::vector<int32_t> &columnLengths, std::vector<bool> &allowNull);
98100

99-
~AntiCacheStats();
100101

101102
private:
102103
/**
103104
* AntiCacheDB whose stats are being collected.
104105
*/
105106
AntiCacheDB * m_acdb;
106107

108+
// actually we don't need this now
109+
Table* m_table;
110+
107111
// AntiCacheID
108112
int16_t m_acid;
109113

@@ -121,6 +125,12 @@ class AntiCacheStats : public voltdb::StatsSource {
121125
int32_t m_totalBlocksUnevicted;
122126
int64_t m_totalBytesUnevicted;
123127

128+
/*
129+
int32_t m_currentBlocksEvicted;
130+
int64_t m_currentBytesEvicted;
131+
int32_t m_currentBlocksUnevicted;
132+
int64_t m_currentBytesUnevicted;*/
133+
124134
// current number of blocks in storage
125135
int32_t m_currentEvictedBlocks;
126136
int64_t m_currentEvictedBytes;

src/ee/execution/VoltDBEngine.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include "storage/TableCatalogDelegate.hpp"
101101
#include "org_voltdb_jni_ExecutionEngine.h" // to use static values
102102
#include "stats/StatsAgent.h"
103+
#include "stats/StatsSource.h"
103104
#include "voltdbipc.h"
104105
#include "common/FailureInjection.h"
105106

@@ -838,6 +839,16 @@ bool VoltDBEngine::rebuildTableCollections() {
838839
STATISTICS_SELECTOR_TYPE_INDEX,
839840
indexId, index->getIndexStats());
840841
}
842+
843+
// Add all different levels of anticacheDB to the stats source.
844+
// This is duplicated, but that's fine for now (in case we need to get per-tire-table anticache stats).
845+
std::vector <AntiCacheDB*> tacdbs = tcd->getTable()->allACDBs();
846+
for (int i = 0; i < tacdbs.size(); i++) {
847+
VOLT_ERROR("CREATE ACDBStats: %d\n", i);
848+
getStatsManager().registerStatsSource(
849+
STATISTICS_SELECTOR_TYPE_MULTITIER_ANTICACHE,
850+
static_cast<CatalogId>(i), (StatsSource*)(tacdbs[i]->getACDBStats()));
851+
}
841852
}
842853
cdIt++;
843854
}
@@ -1279,8 +1290,30 @@ int VoltDBEngine::getStats(int selector, int locators[], int numLocators,
12791290
// -------------------------------------------------
12801291
// MULTITIER STATS
12811292
// -------------------------------------------------
1282-
case STATISTICS_SELECTOR_MULTITIER_ANTICACHE: {
1283-
1293+
case STATISTICS_SELECTOR_TYPE_MULTITIER_ANTICACHE: {
1294+
for (int ii = 0; ii < numLocators; ii++) {
1295+
CatalogId locator = static_cast<CatalogId>(locators[ii]);
1296+
locatorIds.push_back(locator);
1297+
}
1298+
/*
1299+
for (int ii = 0; ii < numLocators; ii++) {
1300+
CatalogId locator = static_cast<CatalogId>(locators[ii]);
1301+
if (m_tables.find(locator) == m_tables.end()) {
1302+
char message[256];
1303+
snprintf(message, 256,
1304+
"getStats() called with selector %d, and"
1305+
" an invalid locator %d that does not correspond to"
1306+
" a table", selector, locator);
1307+
throw SerializableEEException(
1308+
VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, message);
1309+
}
1310+
}*/
1311+
1312+
resultTable = m_statsManager.getStats(
1313+
(StatisticsSelectorType) selector, locatorIds, interval,
1314+
now);
1315+
break;
1316+
}
12841317

12851318
default:
12861319
char message[256];

src/ee/storage/persistenttable.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ AntiCacheDB* PersistentTable::getAntiCacheDB(int level)
252252
return m_executorContext->getAntiCacheDB(level);
253253
}
254254

255+
std::vector<AntiCacheDB*> PersistentTable::allACDBs() const {
256+
std::vector<AntiCacheDB*> retval;
257+
int numDBs = (int)m_executorContext->getAntiCacheEvictionManager()->getNumAntiCacheDBs();
258+
for (int i = 0; i < numDBs; ++i)
259+
retval.push_back(m_executorContext->getAntiCacheDB(i));
260+
261+
return retval;
262+
}
263+
255264
int32_t PersistentTable::getTuplesEvicted()
256265
{
257266
return m_tuplesEvicted;

src/ee/storage/persistenttable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ class PersistentTable : public Table {
312312
void clearUnevictedBlockIDs();
313313
char* getUnevictedBlocks(int i);
314314
int unevictedBlocksSize();
315+
std::vector<AntiCacheDB*> allACDBs() const;
315316

316317
#endif
317318

src/ee/storage/table.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,4 +618,10 @@ void Table::loadTuplesFrom(bool allowExport,
618618

619619
loadTuplesFromNoHeader( allowExport, serialize_io, stringPool);
620620
}
621+
622+
#ifdef ANTICACHE
623+
std::vector<AntiCacheDB*> Table::allACDBs() const{
624+
return std::vector<AntiCacheDB*>();
625+
}
626+
#endif
621627
}

src/ee/storage/table.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "common/Pool.hpp"
5858
#include "common/tabletuple.h"
5959
#include "common/MMAPMemoryManager.h"
60+
#include "anticache/AntiCacheDB.h"
6061

6162
namespace voltdb {
6263

@@ -221,6 +222,8 @@ class Table {
221222
inline int32_t getTuplesRead() const { return (m_tuplesRead); }
222223
inline int32_t getBlocksRead() const { return (m_blocksRead); }
223224
inline int64_t getBytesRead() const { return (m_bytesRead); }
225+
226+
virtual std::vector<AntiCacheDB*> allACDBs() const;
224227
#endif
225228

226229
int getTupleID(const char* tuple_address);

0 commit comments

Comments
 (0)