Skip to content

Commit 29527be

Browse files
committed
Two fixes:
(1) The Array index type now properly keeps track of the number of entries that it has. (2) Updated the TestStatsSuite to now check that INDEX stats returns the proper count per index per partition
1 parent 78aff6f commit 29527be

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

src/ee/indexes/arrayuniqueindex.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
namespace voltdb {
2929

3030

31-
ArrayUniqueIndex::ArrayUniqueIndex(const TableIndexScheme &scheme) : TableIndex(scheme) {
31+
ArrayUniqueIndex::ArrayUniqueIndex(const TableIndexScheme &scheme) : TableIndex(scheme), num_entries_(0) {
3232
assert(colCount_ == 1);
3333
assert((column_types_[0] == VALUE_TYPE_TINYINT) || (column_types_[0] == VALUE_TYPE_SMALLINT) ||
3434
(column_types_[0] == VALUE_TYPE_INTEGER) || (column_types_[0] == VALUE_TYPE_BIGINT));
@@ -51,6 +51,7 @@ bool ArrayUniqueIndex::addEntry(const TableTuple *tuple) {
5151
return false;
5252
entries_[key] = static_cast<void*>(const_cast<TableTuple*>(tuple)->address());
5353
++m_inserts;
54+
++num_entries_;
5455
return true;
5556
}
5657

@@ -59,6 +60,10 @@ bool ArrayUniqueIndex::deleteEntry(const TableTuple *tuple) {
5960
assert((key < ARRAY_INDEX_INITIAL_SIZE) && (key >= 0));
6061

6162
//VOLT_DEBUG("Deleting entry %lld", key);
63+
if (entries_[key] != NULL) {
64+
--num_entries_;
65+
assert(num_entries_ >= 0);
66+
}
6267
entries_[key] = NULL;
6368
++m_deletes;
6469
return true; //deleted

src/ee/indexes/arrayuniqueindex.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ArrayUniqueIndex : public TableIndex {
5656

5757
bool checkForIndexChange(const TableTuple *lhs, const TableTuple *rhs);
5858

59-
size_t getSize() const { return 0; }
59+
size_t getSize() const { return (num_entries_); }
6060
int64_t getMemoryEstimate() const {
6161
return sizeof(void*) * ARRAY_INDEX_INITIAL_SIZE;
6262
}
@@ -68,6 +68,7 @@ class ArrayUniqueIndex : public TableIndex {
6868
void **entries_;
6969
int32_t allocated_entries_;
7070
int32_t match_i_;
71+
int32_t num_entries_;
7172
};
7273

7374
}

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

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.voltdb.regressionsuites;
22

33
import java.io.IOException;
4+
import java.util.HashMap;
5+
import java.util.Map;
46
import java.util.Random;
57

68
import org.voltdb.CatalogContext;
@@ -86,6 +88,25 @@ public static long getRowCount(Client client, Table tbl) throws Exception {
8688
return (count);
8789
}
8890

91+
public static Map<String, Map<Integer, Long>> getRowCountPerPartition(Client client) throws Exception {
92+
ClientResponse statsResponse = RegressionSuiteUtil.getStats(client, SysProcSelector.TABLE);
93+
assert(Status.OK == statsResponse.getStatus());
94+
VoltTable statsResult = statsResponse.getResults()[0];
95+
Map<String, Map<Integer, Long>> rowCounts = new HashMap<String, Map<Integer,Long>>();
96+
while (statsResult.advanceRow()) {
97+
String tableName = statsResult.getString("TABLE_NAME");
98+
int partition = (int)statsResult.getLong("PARTITION_ID");
99+
long tupleCount = statsResult.getLong("TUPLE_COUNT");
100+
Map<Integer, Long> cnts = rowCounts.get(tableName);
101+
if (cnts == null) {
102+
cnts = new HashMap<Integer, Long>();
103+
rowCounts.put(tableName, cnts);
104+
}
105+
cnts.put(partition, tupleCount);
106+
} // WHILE
107+
return (rowCounts);
108+
}
109+
89110
/**
90111
* Populate the given table with a bunch of random tuples
91112
* @param client

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

+21-9
Original file line numberDiff line numberDiff line change
@@ -163,42 +163,54 @@ public void testIndexStats() throws Exception {
163163
Client client = this.getClient();
164164
RegressionSuiteUtil.initializeTPCCDatabase(catalogContext, client);
165165

166+
// Get the row count per table per partition
167+
// We need this so we can check that the indexes have the proper number of entries
168+
Map<String, Map<Integer, Long>> rowCounts = RegressionSuiteUtil.getRowCountPerPartition(client);
169+
assertEquals(rowCounts.toString(), catalogContext.getDataTables().size(), rowCounts.size());
170+
// System.err.println(StringUtil.formatMaps(rowCounts));
171+
172+
// Loop through each table and make sure that each index reports back at least
173+
// some amount of data.
166174
ClientResponse cresponse = RegressionSuiteUtil.getStats(client, SysProcSelector.INDEX);
167175
assertNotNull(cresponse);
168176
assertEquals(Status.OK, cresponse.getStatus());
169-
170-
// Loop through each table and make sure that each index reports back at least
171-
// some amount of data.
172177
VoltTable result = cresponse.getResults()[0];
173178
for (Table tbl : catalogContext.getDataTables()) {
174179
if (tbl.getIndexes().isEmpty()) continue;
175180

181+
Map<Integer, Long> expected = rowCounts.get(tbl.getName());
182+
assertNotNull(tbl.toString(), expected);
183+
176184
for (Index idx : tbl.getIndexes()) {
177185
result.resetRowPosition();
178186
boolean found = false;
179187
while (result.advanceRow()) {
180188
String idxName = result.getString("INDEX_NAME");
181189
String tblName = result.getString("TABLE_NAME");
182190
String idxType = result.getString("INDEX_TYPE");
191+
int partitionId = (int)result.getLong("PARTITION_ID");
183192
long entryCount= result.getLong("ENTRY_COUNT");
184193
if (tbl.getName().equalsIgnoreCase(tblName) && idx.getName().equalsIgnoreCase(idxName)) {
185194
long memoryEstimate = result.getLong("MEMORY_ESTIMATE");
186195
//System.err.println(tblName + "------" + entryCount + "-------" + idxName + "------" + idxType + "---------" + memoryEstimate);
187196
assert(memoryEstimate > 0) :
188197
String.format("Unexpected zero memory estimate for index %s.%s", tblName, idxName);
189198
found = true;
199+
200+
// Check whether the entry count is correct if it's a unique index
201+
if (idx.getUnique()) {
202+
Long expectedCnt = expected.get(partitionId);
203+
assertNotNull(String.format("TABLE:%s PARTITION:%d", tbl.getName(), partitionId), expectedCnt);
204+
assertEquals(idx.fullName(), expectedCnt.longValue(), entryCount);
205+
}
190206
}
191207
} // WHILE
192208
// 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());
209+
assert(found) : "Did not get index stats for " + idx.fullName();
196210
} // FOR
197-
198211
} // FOR
199212
}
200-
201-
213+
202214
public static Test suite() {
203215
// the suite made here will all be using the tests from this class
204216
MultiConfigSuiteBuilder builder = new MultiConfigSuiteBuilder(TestStatsSuite.class);

0 commit comments

Comments
 (0)