Skip to content

Commit 78aff6f

Browse files
committed
**Major bug fix for @huanchenz**
The EE was not keeping track of IndexStats properly because we were using the catalog object's relativeIndex parameter. Well, this parameter is not globally unique, so shit was getting overwritten. It was a real bummer. So now we compute a composite id in the EE for each unique table+index pair. That ensures that we can get set things properly. Ok, so I think I'm going to head back up to the Sex House for dinner with my ex-girlfriend. We're having lasagna.
1 parent 448985d commit 78aff6f

File tree

5 files changed

+67
-53
lines changed

5 files changed

+67
-53
lines changed

src/ee/execution/VoltDBEngine.cpp

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,23 @@ bool VoltDBEngine::rebuildTableCollections() {
820820

821821
// add all of the indexes to the stats source
822822
std::vector<TableIndex*> tindexes = tcd->getTable()->allIndexes();
823+
CatalogId tableId = static_cast<CatalogId>(catTable->relativeIndex());
823824
for (int i = 0; i < tindexes.size(); i++) {
824825
TableIndex *index = tindexes[i];
826+
// Pay attention here because this is important!
827+
// Because the relative indexes for the catalog objects are based on
828+
// their parent object, that means that we can't use the indexes' relativeIndex
829+
// field to uniquely identify them because they are overwritten for
830+
// each table. So this means that we have to generate a composite
831+
// key of the table's relativeIndex + index's relativeIndex so that can
832+
// uniquely identify them. The Java layer doesn't need to know
833+
// about this hot mess!
834+
CatalogId indexId = computeIndexStatsId(tableId, static_cast<CatalogId>(i+1));
835+
VOLT_DEBUG("CREATE IndexStats: %s.%s -> %d\n",
836+
tcd->getTable()->name().c_str(), index->getName().c_str(), indexId);
825837
getStatsManager().registerStatsSource(
826838
STATISTICS_SELECTOR_TYPE_INDEX,
827-
catTable->relativeIndex(), index->getIndexStats());
839+
indexId, index->getIndexStats());
828840
}
829841
}
830842
cdIt++;
@@ -1194,16 +1206,18 @@ int VoltDBEngine::getStats(int selector, int locators[], int numLocators,
11941206
bool interval, int64_t now) {
11951207
Table *resultTable = NULL;
11961208
vector<CatalogId> locatorIds;
1197-
1198-
for (int ii = 0; ii < numLocators; ii++) {
1199-
CatalogId locator = static_cast<CatalogId>(locators[ii]);
1200-
locatorIds.push_back(locator);
1201-
}
12021209
size_t lengthPosition = m_resultOutput.reserveBytes(sizeof(int32_t));
12031210

12041211
try {
12051212
switch (selector) {
1206-
case STATISTICS_SELECTOR_TYPE_TABLE:
1213+
// -------------------------------------------------
1214+
// TABLE STATS
1215+
// -------------------------------------------------
1216+
case STATISTICS_SELECTOR_TYPE_TABLE: {
1217+
for (int ii = 0; ii < numLocators; ii++) {
1218+
CatalogId locator = static_cast<CatalogId>(locators[ii]);
1219+
locatorIds.push_back(locator);
1220+
}
12071221
for (int ii = 0; ii < numLocators; ii++) {
12081222
CatalogId locator = static_cast<CatalogId>(locators[ii]);
12091223
if (m_tables.find(locator) == m_tables.end()) {
@@ -1221,24 +1235,47 @@ int VoltDBEngine::getStats(int selector, int locators[], int numLocators,
12211235
(StatisticsSelectorType) selector, locatorIds, interval,
12221236
now);
12231237
break;
1224-
case STATISTICS_SELECTOR_TYPE_INDEX:
1238+
}
1239+
// -------------------------------------------------
1240+
// INDEX STATS
1241+
// -------------------------------------------------
1242+
case STATISTICS_SELECTOR_TYPE_INDEX: {
1243+
// HACK: Pavlo 2014-11-20
1244+
// Ok here's what's going to happen in this mofo.
1245+
// We normally don't have globally unique index ids, since we're using the
1246+
// the relative indexes. So we'll create a composite key of the table's relativeIndex +
1247+
// the index's relativeIndex
12251248
for (int ii = 0; ii < numLocators; ii++) {
1226-
CatalogId locator = static_cast<CatalogId>(locators[ii]);
1227-
if (m_tables.find(locator) == m_tables.end()) {
1249+
CatalogId tableId = static_cast<CatalogId>(locators[ii]);
1250+
if (m_tables.find(tableId) == m_tables.end()) {
12281251
char message[256];
12291252
snprintf(message, 256,
12301253
"getStats() called with selector %d, and"
12311254
" an invalid locator %d that does not correspond to"
1232-
" a table", selector, locator);
1255+
" a table", selector, tableId);
12331256
throw SerializableEEException(
12341257
VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, message);
12351258
}
1236-
}
1259+
1260+
// Create the composite keys for this table
1261+
catalog::Table *catTable = m_database->tables().get(m_tables[tableId]->name());
1262+
1263+
map<string, catalog::Index*>::const_iterator idx_iterator;
1264+
for (idx_iterator = catTable->indexes().begin();
1265+
idx_iterator != catTable->indexes().end(); idx_iterator++) {
1266+
catalog::Index *catIndex = idx_iterator->second;
1267+
CatalogId indexId = computeIndexStatsId(catTable->relativeIndex(), catIndex->relativeIndex());
1268+
locatorIds.push_back(indexId);
1269+
VOLT_DEBUG("FETCH IndexStats: %s.%s -> %d\n",
1270+
catTable->name().c_str(), catIndex->name().c_str(), indexId);
1271+
} // FOR
1272+
} // FOR
12371273

12381274
resultTable = m_statsManager.getStats(
12391275
(StatisticsSelectorType) selector, locatorIds, interval,
12401276
now);
12411277
break;
1278+
}
12421279
default:
12431280
char message[256];
12441281
snprintf(message, 256,

src/ee/execution/VoltDBEngine.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,12 @@ class __attribute__((visibility("default"))) VoltDBEngine {
504504
bool updateCatalogDatabaseReference();
505505

506506
void printReport();
507+
508+
// HACK: PAVLO 2014-11-20
509+
// This is needed so that we can fix index stats collection
510+
inline CatalogId computeIndexStatsId(const CatalogId tableId, const CatalogId indexId) const {
511+
return static_cast<CatalogId>(indexId | tableId<<16);
512+
}
507513

508514

509515
/**

src/ee/stats/StatsAgent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Table* StatsAgent::getStats(voltdb::StatisticsSelectorType sst,
9393
voltdb::StatsSource *ss = (*statsSources)[catalogIds[ii]];
9494
assert (ss != NULL);
9595
if (ss == NULL) {
96+
VOLT_ERROR("Missing StatsSource for CatalogId #%d\n", catalogIds[ii]);
9697
continue;
9798
}
9899

src/frontend/org/voltdb/sysprocs/Statistics.java

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -259,50 +259,15 @@ public DependencySet executePlanFragment(Long txn_id,
259259
int ii = 0;
260260
for (Table table : tables) {
261261
tableGuids[ii++] = table.getRelativeIndex();
262-
System.err.println("TABLE ID: " + table.getRelativeIndex());
262+
// System.err.println("TABLE ID: " + table.getRelativeIndex());
263263
}
264264

265-
/* This part is a test version for add every index's m_relativeIndex to ids.
266-
// create an array of the tables for which statistics are required.
267-
// pass this to EE owned by the execution site running this plan fragment.
268-
CatalogMap<Table> tables = context.getDatabase().getTables();
269-
CatalogMap<Index> indexes;
270-
ArrayList<Integer> catalogIds = new ArrayList<Integer>();
271-
272-
//HashSet<Integer> tableIds = new HashSet<Integer>();
273-
//Integer tableId;
274-
275-
for (Table table : tables) {
276-
indexes = table.getIndexes();
277-
//tableId = table.getRelativeIndex();
278-
//if (tableIds.contains(tableId)) continue;
279-
//tableIds.add(tableId);
280-
for (Index index: indexes) {
281-
catalogIds.add(index.getRelativeIndex());
282-
//System.err.println("INDEX ID: " + index.getRelativeIndex());
283-
}
284-
}
285-
286-
int[] indexIds = new int[catalogIds.size()];
287-
int ii = 0;
288-
for (Integer n : catalogIds) {
289-
//indexIds[ii] = ii + 1;
290-
//ii++;
291-
//System.err.println("INDEX ID: " + ii);
292-
indexIds[ii++] = n;
293-
}
294-
VoltTable result = executor.getExecutionEngine().getStats(
295-
SysProcSelector.INDEX,
296-
indexIds,
297-
interval,
298-
now)[0];
299-
}*/
300-
301265
VoltTable result = executor.getExecutionEngine().getStats(
302266
SysProcSelector.INDEX,
303267
tableGuids,
304268
interval,
305269
now)[0];
270+
// System.err.println(VoltTableUtil.format(result));
306271
return new DependencySet(DEP_indexData, result);
307272
}
308273
case SysProcFragmentId.PF_indexAggregator: {

tests/frontend/org/voltdb/regressionsuites/TestStatsSuite.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.voltdb.regressionsuites;
22

3-
import java.util.HashMap;
43
import java.util.Map;
54
import java.util.TreeMap;
65

@@ -14,11 +13,10 @@
1413
import org.voltdb.benchmark.tpcc.TPCCConstants;
1514
import org.voltdb.benchmark.tpcc.TPCCProjectBuilder;
1615
import org.voltdb.benchmark.tpcc.procedures.neworder;
17-
import org.voltdb.client.Client;
18-
import org.voltdb.client.ClientResponse;
19-
import org.voltdb.utils.VoltTableUtil;
2016
import org.voltdb.catalog.Index;
2117
import org.voltdb.catalog.Table;
18+
import org.voltdb.client.Client;
19+
import org.voltdb.client.ClientResponse;
2220

2321
import edu.brown.hstore.Hstoreservice.Status;
2422
import edu.brown.utils.StringUtil;
@@ -177,6 +175,7 @@ public void testIndexStats() throws Exception {
177175

178176
for (Index idx : tbl.getIndexes()) {
179177
result.resetRowPosition();
178+
boolean found = false;
180179
while (result.advanceRow()) {
181180
String idxName = result.getString("INDEX_NAME");
182181
String tblName = result.getString("TABLE_NAME");
@@ -187,9 +186,15 @@ public void testIndexStats() throws Exception {
187186
//System.err.println(tblName + "------" + entryCount + "-------" + idxName + "------" + idxType + "---------" + memoryEstimate);
188187
assert(memoryEstimate > 0) :
189188
String.format("Unexpected zero memory estimate for index %s.%s", tblName, idxName);
189+
found = true;
190190
}
191191
} // WHILE
192+
// Make sure that we got all the indexes for the table.
193+
assert(found) :
194+
String.format("Did not get index stats for %s.%s",
195+
tbl.getName(), idx.getName());
192196
} // FOR
197+
193198
} // FOR
194199
}
195200

0 commit comments

Comments
 (0)