@@ -820,11 +820,23 @@ bool VoltDBEngine::rebuildTableCollections() {
820
820
821
821
// add all of the indexes to the stats source
822
822
std::vector<TableIndex*> tindexes = tcd->getTable ()->allIndexes ();
823
+ CatalogId tableId = static_cast <CatalogId>(catTable->relativeIndex ());
823
824
for (int i = 0 ; i < tindexes.size (); i++) {
824
825
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);
825
837
getStatsManager ().registerStatsSource (
826
838
STATISTICS_SELECTOR_TYPE_INDEX,
827
- catTable-> relativeIndex () , index->getIndexStats ());
839
+ indexId , index->getIndexStats ());
828
840
}
829
841
}
830
842
cdIt++;
@@ -1194,16 +1206,18 @@ int VoltDBEngine::getStats(int selector, int locators[], int numLocators,
1194
1206
bool interval, int64_t now) {
1195
1207
Table *resultTable = NULL ;
1196
1208
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
- }
1202
1209
size_t lengthPosition = m_resultOutput.reserveBytes (sizeof (int32_t ));
1203
1210
1204
1211
try {
1205
1212
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
+ }
1207
1221
for (int ii = 0 ; ii < numLocators; ii++) {
1208
1222
CatalogId locator = static_cast <CatalogId>(locators[ii]);
1209
1223
if (m_tables.find (locator) == m_tables.end ()) {
@@ -1221,24 +1235,47 @@ int VoltDBEngine::getStats(int selector, int locators[], int numLocators,
1221
1235
(StatisticsSelectorType) selector, locatorIds, interval,
1222
1236
now);
1223
1237
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
1225
1248
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 ()) {
1228
1251
char message[256 ];
1229
1252
snprintf (message, 256 ,
1230
1253
" getStats() called with selector %d, and"
1231
1254
" an invalid locator %d that does not correspond to"
1232
- " a table" , selector, locator );
1255
+ " a table" , selector, tableId );
1233
1256
throw SerializableEEException (
1234
1257
VOLT_EE_EXCEPTION_TYPE_EEEXCEPTION, message);
1235
1258
}
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
1237
1273
1238
1274
resultTable = m_statsManager.getStats (
1239
1275
(StatisticsSelectorType) selector, locatorIds, interval,
1240
1276
now);
1241
1277
break ;
1278
+ }
1242
1279
default :
1243
1280
char message[256 ];
1244
1281
snprintf (message, 256 ,
0 commit comments