Skip to content
Permalink
Browse files
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
  • Loading branch information
apavlo committed Nov 21, 2014
1 parent 78aff6f commit 29527be
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
@@ -28,7 +28,7 @@
namespace voltdb {


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

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

//VOLT_DEBUG("Deleting entry %lld", key);
if (entries_[key] != NULL) {
--num_entries_;
assert(num_entries_ >= 0);
}
entries_[key] = NULL;
++m_deletes;
return true; //deleted
@@ -56,7 +56,7 @@ class ArrayUniqueIndex : public TableIndex {

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

size_t getSize() const { return 0; }
size_t getSize() const { return (num_entries_); }
int64_t getMemoryEstimate() const {
return sizeof(void*) * ARRAY_INDEX_INITIAL_SIZE;
}
@@ -68,6 +68,7 @@ class ArrayUniqueIndex : public TableIndex {
void **entries_;
int32_t allocated_entries_;
int32_t match_i_;
int32_t num_entries_;
};

}
@@ -1,6 +1,8 @@
package org.voltdb.regressionsuites;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

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

public static Map<String, Map<Integer, Long>> getRowCountPerPartition(Client client) throws Exception {
ClientResponse statsResponse = RegressionSuiteUtil.getStats(client, SysProcSelector.TABLE);
assert(Status.OK == statsResponse.getStatus());
VoltTable statsResult = statsResponse.getResults()[0];
Map<String, Map<Integer, Long>> rowCounts = new HashMap<String, Map<Integer,Long>>();
while (statsResult.advanceRow()) {
String tableName = statsResult.getString("TABLE_NAME");
int partition = (int)statsResult.getLong("PARTITION_ID");
long tupleCount = statsResult.getLong("TUPLE_COUNT");
Map<Integer, Long> cnts = rowCounts.get(tableName);
if (cnts == null) {
cnts = new HashMap<Integer, Long>();
rowCounts.put(tableName, cnts);
}
cnts.put(partition, tupleCount);
} // WHILE
return (rowCounts);
}

/**
* Populate the given table with a bunch of random tuples
* @param client
@@ -163,42 +163,54 @@ public void testIndexStats() throws Exception {
Client client = this.getClient();
RegressionSuiteUtil.initializeTPCCDatabase(catalogContext, client);

// Get the row count per table per partition
// We need this so we can check that the indexes have the proper number of entries
Map<String, Map<Integer, Long>> rowCounts = RegressionSuiteUtil.getRowCountPerPartition(client);
assertEquals(rowCounts.toString(), catalogContext.getDataTables().size(), rowCounts.size());
// System.err.println(StringUtil.formatMaps(rowCounts));

// Loop through each table and make sure that each index reports back at least
// some amount of data.
ClientResponse cresponse = RegressionSuiteUtil.getStats(client, SysProcSelector.INDEX);
assertNotNull(cresponse);
assertEquals(Status.OK, cresponse.getStatus());

// Loop through each table and make sure that each index reports back at least
// some amount of data.
VoltTable result = cresponse.getResults()[0];
for (Table tbl : catalogContext.getDataTables()) {
if (tbl.getIndexes().isEmpty()) continue;

Map<Integer, Long> expected = rowCounts.get(tbl.getName());
assertNotNull(tbl.toString(), expected);

for (Index idx : tbl.getIndexes()) {
result.resetRowPosition();
boolean found = false;
while (result.advanceRow()) {
String idxName = result.getString("INDEX_NAME");
String tblName = result.getString("TABLE_NAME");
String idxType = result.getString("INDEX_TYPE");
int partitionId = (int)result.getLong("PARTITION_ID");
long entryCount= result.getLong("ENTRY_COUNT");
if (tbl.getName().equalsIgnoreCase(tblName) && idx.getName().equalsIgnoreCase(idxName)) {
long memoryEstimate = result.getLong("MEMORY_ESTIMATE");
//System.err.println(tblName + "------" + entryCount + "-------" + idxName + "------" + idxType + "---------" + memoryEstimate);
assert(memoryEstimate > 0) :
String.format("Unexpected zero memory estimate for index %s.%s", tblName, idxName);
found = true;

// Check whether the entry count is correct if it's a unique index
if (idx.getUnique()) {
Long expectedCnt = expected.get(partitionId);
assertNotNull(String.format("TABLE:%s PARTITION:%d", tbl.getName(), partitionId), expectedCnt);
assertEquals(idx.fullName(), expectedCnt.longValue(), entryCount);
}
}
} // WHILE
// Make sure that we got all the indexes for the table.
assert(found) :
String.format("Did not get index stats for %s.%s",
tbl.getName(), idx.getName());
assert(found) : "Did not get index stats for " + idx.fullName();
} // FOR

} // FOR
}



public static Test suite() {
// the suite made here will all be using the tests from this class
MultiConfigSuiteBuilder builder = new MultiConfigSuiteBuilder(TestStatsSuite.class);

0 comments on commit 29527be

Please sign in to comment.