use of org.voltdb.TheHashinator.HashinatorConfig in project voltdb by VoltDB.
the class TestTheHashinator method testSameLongHash.
@Test
public void testSameLongHash() throws Exception {
byte[] configBytes = TheHashinator.getConfigureBytes(1);
ExecutionEngine ee = new ExecutionEngineJNI(1, 1, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(hashinatorType, configBytes, 0, 0), false);
/**
* Run with 10k of random values and make sure C++ and Java hash to
* the same value.
*/
for (int i = 0; i < 1500; i++) {
final int partitionCount = r.nextInt(1000) + 1;
configBytes = TheHashinator.getConfigureBytes(partitionCount);
TheHashinator.initialize(TheHashinator.getConfiguredHashinatorClass(), configBytes);
// this will produce negative values, which is desired here.
final long valueToHash = r.nextLong();
final int javahash = TheHashinator.getPartitionForParameter(VoltType.typeFromObject(valueToHash).getValue(), valueToHash);
final int eehash = ee.hashinate(valueToHash, TheHashinator.getCurrentConfig());
if (eehash != javahash) {
System.out.printf("Mismatched hash of (%s) %d with %d partitions => EE: %d, Java: %d\n", VoltType.typeFromObject(valueToHash).toSQLString(), valueToHash, partitionCount, eehash, javahash);
}
assertEquals(eehash, javahash);
assertTrue(eehash < partitionCount);
assertTrue(eehash > -1);
}
try {
ee.release();
} catch (Exception e) {
}
}
use of org.voltdb.TheHashinator.HashinatorConfig in project voltdb by VoltDB.
the class TestTheHashinator method testSameBytesHash.
@Test
public void testSameBytesHash() throws Exception {
ExecutionEngine ee = new ExecutionEngineJNI(1, 1, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(hashinatorType, TheHashinator.getConfigureBytes(6), 0, 0), false);
for (int i = 0; i < 2500; i++) {
int partitionCount = r.nextInt(1000) + 1;
byte[] valueToHash = new byte[r.nextInt(1000)];
r.nextBytes(valueToHash);
final byte[] configBytes = TheHashinator.getConfigureBytes(partitionCount);
TheHashinator.initialize(TheHashinator.getConfiguredHashinatorClass(), configBytes);
int eehash = ee.hashinate(valueToHash, TheHashinator.getCurrentConfig());
int javahash = TheHashinator.getPartitionForParameter(VoltType.typeFromClass(byte[].class).getValue(), valueToHash);
if (eehash != javahash) {
System.out.printf("Mismatched hash of (%s) %d bytes %d partitions => EE: %d Java: %d\n", VoltType.typeFromObject(valueToHash).toSQLString(), valueToHash.length, partitionCount, eehash, javahash);
partitionCount++;
}
assertTrue(eehash < partitionCount);
assertTrue(eehash >= 0);
assertEquals(eehash, javahash);
}
try {
ee.release();
} catch (Exception e) {
}
}
use of org.voltdb.TheHashinator.HashinatorConfig in project voltdb by VoltDB.
the class TestExecutionEngine method testStreamTables.
public void testStreamTables() throws Exception {
sourceEngine.loadCatalog(0, m_catalog.serialize());
// Each EE needs its own thread for correct initialization.
final AtomicReference<ExecutionEngine> destinationEngine = new AtomicReference<ExecutionEngine>();
final byte[] configBytes = LegacyHashinator.getConfigureBytes(1);
Thread destEEThread = new Thread() {
@Override
public void run() {
destinationEngine.set(new ExecutionEngineJNI(CLUSTER_ID, NODE_ID, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, configBytes, 0, 0), false));
}
};
destEEThread.start();
destEEThread.join();
destinationEngine.get().loadCatalog(0, m_catalog.serialize());
int WAREHOUSE_TABLEID = warehouseTableId(m_catalog);
int STOCK_TABLEID = stockTableId(m_catalog);
loadTestTables(sourceEngine, m_catalog);
sourceEngine.activateTableStream(WAREHOUSE_TABLEID, TableStreamType.RECOVERY, Long.MAX_VALUE, new SnapshotPredicates(-1).toBytes());
sourceEngine.activateTableStream(STOCK_TABLEID, TableStreamType.RECOVERY, Long.MAX_VALUE, new SnapshotPredicates(-1).toBytes());
final BBContainer origin = DBBPool.allocateDirect(1024 * 1024 * 2);
origin.b().clear();
final BBContainer container = new BBContainer(origin.b()) {
@Override
public void discard() {
checkDoubleFree();
origin.discard();
}
};
try {
List<BBContainer> output = new ArrayList<BBContainer>();
output.add(container);
int serialized = sourceEngine.tableStreamSerializeMore(WAREHOUSE_TABLEID, TableStreamType.RECOVERY, output).getSecond()[0];
assertTrue(serialized > 0);
container.b().limit(serialized);
destinationEngine.get().processRecoveryMessage(container.b(), container.address());
serialized = sourceEngine.tableStreamSerializeMore(WAREHOUSE_TABLEID, TableStreamType.RECOVERY, output).getSecond()[0];
assertEquals(5, serialized);
assertEquals(RecoveryMessageType.Complete.ordinal(), container.b().get());
assertEquals(sourceEngine.tableHashCode(WAREHOUSE_TABLEID), destinationEngine.get().tableHashCode(WAREHOUSE_TABLEID));
container.b().clear();
serialized = sourceEngine.tableStreamSerializeMore(STOCK_TABLEID, TableStreamType.RECOVERY, output).getSecond()[0];
assertTrue(serialized > 0);
container.b().limit(serialized);
destinationEngine.get().processRecoveryMessage(container.b(), container.address());
serialized = sourceEngine.tableStreamSerializeMore(STOCK_TABLEID, TableStreamType.RECOVERY, output).getSecond()[0];
assertEquals(5, serialized);
assertEquals(RecoveryMessageType.Complete.ordinal(), container.b().get());
assertEquals(STOCK_TABLEID, container.b().getInt());
assertEquals(sourceEngine.tableHashCode(STOCK_TABLEID), destinationEngine.get().tableHashCode(STOCK_TABLEID));
} finally {
container.discard();
}
}
use of org.voltdb.TheHashinator.HashinatorConfig in project voltdb by VoltDB.
the class TestExecutionEngine method testStreamIndex.
public void testStreamIndex() throws Exception {
sourceEngine.loadCatalog(0, m_catalog.serialize());
// Each EE needs its own thread for correct initialization.
final AtomicReference<ExecutionEngine> destinationEngine = new AtomicReference<ExecutionEngine>();
final byte[] configBytes = LegacyHashinator.getConfigureBytes(1);
Thread destEEThread = new Thread() {
@Override
public void run() {
destinationEngine.set(new ExecutionEngineJNI(CLUSTER_ID, NODE_ID, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, configBytes, 0, 0), false));
}
};
destEEThread.start();
destEEThread.join();
destinationEngine.get().loadCatalog(0, m_catalog.serialize());
int STOCK_TABLEID = stockTableId(m_catalog);
loadTestTables(sourceEngine, m_catalog);
SnapshotPredicates predicates = new SnapshotPredicates(-1);
predicates.addPredicate(new HashRangeExpressionBuilder().put(0x00000000, 0x7fffffff).build(0), true);
// Build the index
sourceEngine.activateTableStream(STOCK_TABLEID, TableStreamType.ELASTIC_INDEX, Long.MAX_VALUE, predicates.toBytes());
// Humor serializeMore() by providing a buffer, even though it's not used.
final BBContainer origin = DBBPool.allocateDirect(1024 * 1024 * 2);
origin.b().clear();
BBContainer container = new BBContainer(origin.b()) {
@Override
public void discard() {
checkDoubleFree();
origin.discard();
}
};
try {
List<BBContainer> output = new ArrayList<BBContainer>();
output.add(container);
assertEquals(0, sourceEngine.tableStreamSerializeMore(STOCK_TABLEID, TableStreamType.ELASTIC_INDEX, output).getSecond()[0]);
} finally {
container.discard();
}
}
use of org.voltdb.TheHashinator.HashinatorConfig in project voltdb by VoltDB.
the class TestTheHashinator method testExpectNonZeroHash.
/*
* This test validates that not all values hash to 0. Most of the other
* tests will pass even if everything hashes to a single partition.
*/
@Test
public void testExpectNonZeroHash() throws Exception {
int partitionCount = 3;
final byte[] configBytes = TheHashinator.getConfigureBytes(partitionCount);
TheHashinator.initialize(TheHashinator.getConfiguredHashinatorClass(), configBytes);
HashinatorConfig config = TheHashinator.getCurrentConfig();
ExecutionEngine ee = new ExecutionEngineJNI(1, 1, 0, 0, "", 0, 64 * 1024, 100, config, false);
long valueToHash = hashinatorType == HashinatorType.ELASTIC ? 39 : 2;
int eehash = ee.hashinate(valueToHash, config);
int javahash = TheHashinator.getPartitionForParameter(VoltType.typeFromObject(valueToHash).getValue(), valueToHash);
if (eehash != javahash) {
System.out.printf("Mismatched hash of (%s) %d with %d partitions => EE: %d, Java: %d\n", VoltType.typeFromObject(valueToHash).toSQLString(), valueToHash, partitionCount, eehash, javahash);
}
assertEquals(eehash, javahash);
assertNotSame(0, eehash);
assertTrue(eehash < partitionCount);
assertTrue(eehash >= 0);
try {
ee.release();
} catch (Exception e) {
}
}
Aggregations