Search in sources :

Example 11 with HashinatorConfig

use of org.voltdb.TheHashinator.HashinatorConfig 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 12 with HashinatorConfig

use of org.voltdb.TheHashinator.HashinatorConfig 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 13 with HashinatorConfig

use of org.voltdb.TheHashinator.HashinatorConfig 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)

Example 14 with HashinatorConfig

use of org.voltdb.TheHashinator.HashinatorConfig in project voltdb by VoltDB.

the class TestFragmentProgressUpdate method setUp.

@Override
protected void setUp() throws Exception {
    final int CLUSTER_ID = 2;
    final long NODE_ID = 1;
    super.setUp();
    VoltDB.instance().readBuildInfo("Test");
    m_warehousedata = new VoltTable(new VoltTable.ColumnInfo("W_ID", VoltType.SMALLINT), new VoltTable.ColumnInfo("W_NAME", VoltType.STRING), new VoltTable.ColumnInfo("W_STREET_1", VoltType.STRING), new VoltTable.ColumnInfo("W_STREET_2", VoltType.STRING), new VoltTable.ColumnInfo("W_CITY", VoltType.STRING), new VoltTable.ColumnInfo("W_STATE", VoltType.STRING), new VoltTable.ColumnInfo("W_ZIP", VoltType.STRING), new VoltTable.ColumnInfo("W_TAX", VoltType.FLOAT), new VoltTable.ColumnInfo("W_YTD", VoltType.FLOAT));
    m_itemData = new VoltTable(new VoltTable.ColumnInfo("I_ID", VoltType.INTEGER), new VoltTable.ColumnInfo("I_IM_ID", VoltType.INTEGER), new VoltTable.ColumnInfo("I_NAME", VoltType.STRING), new VoltTable.ColumnInfo("I_PRICE", VoltType.FLOAT), new VoltTable.ColumnInfo("I_DATA", VoltType.STRING));
    TPCCProjectBuilder builder = new TPCCProjectBuilder();
    m_catalog = builder.createTPCCSchemaCatalog();
    Cluster cluster = m_catalog.getClusters().get("cluster");
    WAREHOUSE_TABLEID = m_catalog.getClusters().get("cluster").getDatabases().get("database").getTables().get("WAREHOUSE").getRelativeIndex();
    ITEM_TABLEID = m_catalog.getClusters().get("cluster").getDatabases().get("database").getTables().get("ITEM").getRelativeIndex();
    CatalogMap<Procedure> procedures = cluster.getDatabases().get("database").getProcedures();
    m_testProc = procedures.getIgnoreCase("FragmentUpdateTestProcedure");
    m_ee = new ExecutionEngineJNI(CLUSTER_ID, NODE_ID, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, LegacyHashinator.getConfigureBytes(1), 0, 0), false);
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) Cluster(org.voltdb.catalog.Cluster) Procedure(org.voltdb.catalog.Procedure) VoltTable(org.voltdb.VoltTable) TPCCProjectBuilder(org.voltdb.benchmark.tpcc.TPCCProjectBuilder)

Example 15 with HashinatorConfig

use of org.voltdb.TheHashinator.HashinatorConfig in project voltdb by VoltDB.

the class TestExecutionEngine method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    VoltDB.instance().readBuildInfo("Test");
    sourceEngine = new ExecutionEngineJNI(CLUSTER_ID, NODE_ID, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, LegacyHashinator.getConfigureBytes(1), 0, 0), false);
    m_project = new TPCCProjectBuilder();
    m_catalog = m_project.createTPCCSchemaCatalog();
}
Also used : HashinatorConfig(org.voltdb.TheHashinator.HashinatorConfig) TPCCProjectBuilder(org.voltdb.benchmark.tpcc.TPCCProjectBuilder)

Aggregations

HashinatorConfig (org.voltdb.TheHashinator.HashinatorConfig)15 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 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 TPCCProjectBuilder (org.voltdb.benchmark.tpcc.TPCCProjectBuilder)3 ArrayList (java.util.ArrayList)2 BBContainer (org.voltcore.utils.DBBPool.BBContainer)2 Procedure (org.voltdb.catalog.Procedure)2 SnapshotPredicates (org.voltdb.sysprocs.saverestore.SnapshotPredicates)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 VoltAbortException (org.voltdb.VoltProcedure.VoltAbortException)1 VoltTable (org.voltdb.VoltTable)1 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)1 Catalog (org.voltdb.catalog.Catalog)1 Cluster (org.voltdb.catalog.Cluster)1 Deployment (org.voltdb.catalog.Deployment)1