Search in sources :

Example 6 with ExecutionEngineJNI

use of org.voltdb.jni.ExecutionEngineJNI 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) {
    }
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) ExecutionEngine(org.voltdb.jni.ExecutionEngine) ExecutionEngineJNI(org.voltdb.jni.ExecutionEngineJNI) IOException(java.io.IOException) JSONException(org.json_voltpatches.JSONException) Test(org.junit.Test)

Example 7 with ExecutionEngineJNI

use of org.voltdb.jni.ExecutionEngineJNI 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) {
    }
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) ExecutionEngine(org.voltdb.jni.ExecutionEngine) ExecutionEngineJNI(org.voltdb.jni.ExecutionEngineJNI) IOException(java.io.IOException) JSONException(org.json_voltpatches.JSONException) Test(org.junit.Test)

Example 8 with ExecutionEngineJNI

use of org.voltdb.jni.ExecutionEngineJNI in project voltdb by VoltDB.

the class TestTwoSitePlans method setUp.

@SuppressWarnings("deprecation")
@Override
public void setUp() throws IOException, InterruptedException {
    VoltDB.instance().readBuildInfo("Test");
    // compile a catalog
    String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
    String catalogJar = testDir + File.separator + JAR;
    TPCCProjectBuilder pb = new TPCCProjectBuilder();
    pb.addDefaultSchema();
    pb.addDefaultPartitioning();
    pb.addProcedures(MultiSiteSelect.class, InsertNewOrder.class);
    pb.compile(catalogJar, 2, 0);
    // load a catalog
    byte[] bytes = MiscUtils.fileToBytes(new File(catalogJar));
    String serializedCatalog = CatalogUtil.getSerializedCatalogStringFromJar(CatalogUtil.loadAndUpgradeCatalogFromJar(bytes, false).getFirst());
    // create the catalog (that will be passed to the ClientInterface
    catalog = new Catalog();
    catalog.execute(serializedCatalog);
    // update the catalog with the data from the deployment file
    String pathToDeployment = pb.getPathToDeployment();
    assertTrue(CatalogUtil.compileDeployment(catalog, pathToDeployment, false) == null);
    cluster = catalog.getClusters().get("cluster");
    CatalogMap<Procedure> procedures = cluster.getDatabases().get("database").getProcedures();
    Procedure insertProc = procedures.get("InsertNewOrder");
    assert (insertProc != null);
    selectProc = procedures.get("MultiSiteSelect");
    assert (selectProc != null);
    // Each EE needs its own thread for correct initialization.
    final AtomicReference<ExecutionEngine> site1Reference = new AtomicReference<ExecutionEngine>();
    final byte[] configBytes = LegacyHashinator.getConfigureBytes(2);
    Thread site1Thread = new Thread() {

        @Override
        public void run() {
            site1Reference.set(new ExecutionEngineJNI(cluster.getRelativeIndex(), 1, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, configBytes, 0, 0), false));
        }
    };
    site1Thread.start();
    site1Thread.join();
    final AtomicReference<ExecutionEngine> site2Reference = new AtomicReference<ExecutionEngine>();
    Thread site2Thread = new Thread() {

        @Override
        public void run() {
            site2Reference.set(new ExecutionEngineJNI(cluster.getRelativeIndex(), 2, 1, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, configBytes, 0, 0), false));
        }
    };
    site2Thread.start();
    site2Thread.join();
    // create two EEs
    ee1 = site1Reference.get();
    ee1.loadCatalog(0, catalog.serialize());
    ee2 = site2Reference.get();
    ee2.loadCatalog(0, catalog.serialize());
    // cache some plan fragments
    selectStmt = selectProc.getStatements().get("selectAll");
    assert (selectStmt != null);
    int i = 0;
    // this kinda assumes the right order
    for (PlanFragment f : selectStmt.getFragments()) {
        if (i == 0)
            selectTopFrag = f;
        else
            selectBottomFrag = f;
        i++;
    }
    assert (selectTopFrag != null);
    assert (selectBottomFrag != null);
    if (selectTopFrag.getHasdependencies() == false) {
        PlanFragment temp = selectTopFrag;
        selectTopFrag = selectBottomFrag;
        selectBottomFrag = temp;
    }
    // get the insert frag
    Statement insertStmt = insertProc.getStatements().get("insert");
    assert (insertStmt != null);
    for (PlanFragment f : insertStmt.getFragments()) insertFrag = f;
    // populate plan cache
    ActivePlanRepository.clear();
    ActivePlanRepository.addFragmentForTest(CatalogUtil.getUniqueIdForFragment(selectBottomFrag), Encoder.decodeBase64AndDecompressToBytes(selectBottomFrag.getPlannodetree()), selectStmt.getSqltext());
    ActivePlanRepository.addFragmentForTest(CatalogUtil.getUniqueIdForFragment(selectTopFrag), Encoder.decodeBase64AndDecompressToBytes(selectTopFrag.getPlannodetree()), selectStmt.getSqltext());
    ActivePlanRepository.addFragmentForTest(CatalogUtil.getUniqueIdForFragment(insertFrag), Encoder.decodeBase64AndDecompressToBytes(insertFrag.getPlannodetree()), insertStmt.getSqltext());
    // insert some data
    ParameterSet params = ParameterSet.fromArrayNoCopy(1L, 1L, 1L);
    FastDeserializer fragResult2 = ee2.executePlanFragments(1, new long[] { CatalogUtil.getUniqueIdForFragment(insertFrag) }, null, new ParameterSet[] { params }, null, new String[] { selectStmt.getSqltext() }, null, null, 1, 1, 0, 42, Long.MAX_VALUE, false);
    // ignore totalsize field in message
    fragResult2.readInt();
    VoltTable[] results = TableHelper.convertBackedBufferToTables(fragResult2.buffer(), 1);
    assert (results[0].asScalarLong() == 1L);
    params = ParameterSet.fromArrayNoCopy(2L, 2L, 2L);
    FastDeserializer fragResult1 = ee1.executePlanFragments(1, new long[] { CatalogUtil.getUniqueIdForFragment(insertFrag) }, null, new ParameterSet[] { params }, null, new String[] { selectStmt.getSqltext() }, null, null, 2, 2, 1, 42, Long.MAX_VALUE, false);
    // ignore totalsize field in message
    fragResult1.readInt();
    results = TableHelper.convertBackedBufferToTables(fragResult1.buffer(), 1);
    assert (fragResult1.buffer() != fragResult2.buffer());
    assert (results[0].asScalarLong() == 1L);
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) ExecutionEngineJNI(org.voltdb.jni.ExecutionEngineJNI) FastDeserializer(org.voltdb.messaging.FastDeserializer) Statement(org.voltdb.catalog.Statement) AtomicReference(java.util.concurrent.atomic.AtomicReference) Catalog(org.voltdb.catalog.Catalog) PlanFragment(org.voltdb.catalog.PlanFragment) ExecutionEngine(org.voltdb.jni.ExecutionEngine) Procedure(org.voltdb.catalog.Procedure) TPCCProjectBuilder(org.voltdb.benchmark.tpcc.TPCCProjectBuilder) File(java.io.File)

Example 9 with ExecutionEngineJNI

use of org.voltdb.jni.ExecutionEngineJNI in project voltdb by VoltDB.

the class TestTheHashinator method testNulls.

@Test
public void testNulls() throws Exception {
    ExecutionEngine ee = new ExecutionEngineJNI(1, 1, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(hashinatorType, TheHashinator.getConfigureBytes(2), 0, 0), false);
    final byte[] configBytes = TheHashinator.getConfigureBytes(2);
    TheHashinator.initialize(TheHashinator.getConfiguredHashinatorClass(), configBytes);
    int jHash = TheHashinator.getPartitionForParameter(VoltType.TINYINT.getValue(), new Byte(VoltType.NULL_TINYINT));
    int cHash = ee.hashinate(VoltType.NULL_TINYINT, TheHashinator.getCurrentConfig());
    assertEquals(0, jHash);
    assertEquals(jHash, cHash);
    System.out.println("jhash " + jHash + " chash " + cHash);
    jHash = TheHashinator.getPartitionForParameter(VoltType.SMALLINT.getValue(), new Short(VoltType.NULL_SMALLINT));
    cHash = ee.hashinate(VoltType.NULL_SMALLINT, TheHashinator.getCurrentConfig());
    assertEquals(0, jHash);
    assertEquals(jHash, cHash);
    System.out.println("jhash " + jHash + " chash " + cHash);
    jHash = TheHashinator.getPartitionForParameter(VoltType.INTEGER.getValue(), new Integer(VoltType.NULL_INTEGER));
    cHash = ee.hashinate(VoltType.NULL_INTEGER, TheHashinator.getCurrentConfig());
    assertEquals(0, jHash);
    assertEquals(jHash, cHash);
    System.out.println("jhash " + jHash + " chash " + cHash);
    jHash = TheHashinator.getPartitionForParameter(VoltType.BIGINT.getValue(), new Long(VoltType.NULL_BIGINT));
    cHash = ee.hashinate(VoltType.NULL_BIGINT, TheHashinator.getCurrentConfig());
    assertEquals(0, jHash);
    assertEquals(jHash, cHash);
    System.out.println("jhash " + jHash + " chash " + cHash);
    jHash = TheHashinator.getPartitionForParameter(VoltType.STRING.getValue(), VoltType.NULL_STRING_OR_VARBINARY);
    cHash = ee.hashinate(VoltType.NULL_STRING_OR_VARBINARY, TheHashinator.getCurrentConfig());
    assertEquals(0, jHash);
    assertEquals(jHash, cHash);
    System.out.println("jhash " + jHash + " chash " + cHash);
    jHash = TheHashinator.getPartitionForParameter(VoltType.VARBINARY.getValue(), null);
    cHash = ee.hashinate(null, TheHashinator.getCurrentConfig());
    assertEquals(0, jHash);
    assertEquals(jHash, cHash);
    System.out.println("jhash " + jHash + " chash " + cHash);
    try {
        ee.release();
    } catch (Exception e) {
    }
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) ExecutionEngine(org.voltdb.jni.ExecutionEngine) ExecutionEngineJNI(org.voltdb.jni.ExecutionEngineJNI) IOException(java.io.IOException) JSONException(org.json_voltpatches.JSONException) Test(org.junit.Test)

Example 10 with ExecutionEngineJNI

use of org.voltdb.jni.ExecutionEngineJNI in project voltdb by VoltDB.

the class TestTheHashinator method testSameStringHash.

@Test
public void testSameStringHash() 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);
    for (int i = 0; i < 1500; i++) {
        int partitionCount = r.nextInt(1000) + 1;
        configBytes = TheHashinator.getConfigureBytes(partitionCount);
        String valueToHash = Long.toString(r.nextLong());
        TheHashinator.initialize(TheHashinator.getConfiguredHashinatorClass(), configBytes);
        int eehash = ee.hashinate(valueToHash, TheHashinator.getCurrentConfig());
        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);
            partitionCount++;
        }
        assertEquals(eehash, javahash);
        assertTrue(eehash < partitionCount);
        assertTrue(eehash >= 0);
    }
    try {
        ee.release();
    } catch (Exception e) {
    }
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) ExecutionEngine(org.voltdb.jni.ExecutionEngine) ExecutionEngineJNI(org.voltdb.jni.ExecutionEngineJNI) IOException(java.io.IOException) JSONException(org.json_voltpatches.JSONException) Test(org.junit.Test)

Aggregations

HashinatorConfig (org.voltdb.TheHashinator.HashinatorConfig)10 ExecutionEngine (org.voltdb.jni.ExecutionEngine)10 ExecutionEngineJNI (org.voltdb.jni.ExecutionEngineJNI)10 IOException (java.io.IOException)9 JSONException (org.json_voltpatches.JSONException)8 Test (org.junit.Test)8 File (java.io.File)1 Method (java.lang.reflect.Method)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 VoltAbortException (org.voltdb.VoltProcedure.VoltAbortException)1 TPCCProjectBuilder (org.voltdb.benchmark.tpcc.TPCCProjectBuilder)1 Catalog (org.voltdb.catalog.Catalog)1 Deployment (org.voltdb.catalog.Deployment)1 PlanFragment (org.voltdb.catalog.PlanFragment)1 Procedure (org.voltdb.catalog.Procedure)1 Statement (org.voltdb.catalog.Statement)1 EEException (org.voltdb.exceptions.EEException)1 ExecutionEngineIPC (org.voltdb.jni.ExecutionEngineIPC)1 MockExecutionEngine (org.voltdb.jni.MockExecutionEngine)1 FastDeserializer (org.voltdb.messaging.FastDeserializer)1