Search in sources :

Example 41 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class TestJSONInterface method testAdminMode.

public void testAdminMode() throws Exception {
    try {
        String simpleSchema = "create table blah (" + "ival bigint default 23 not null, " + "sval varchar(200) default 'foo', " + "dateval timestamp, " + "fval float, " + "decval decimal, " + "PRIMARY KEY(ival));";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltDB.Configuration config = new VoltDB.Configuration();
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("blah", "ival");
        builder.addStmtProcedure("Insert", "insert into blah values (?,?,?,?,?);");
        builder.addProcedures(CrazyBlahProc.class);
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"), 1, 1, 0, 0) != null;
        assertTrue(success);
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        config.m_adminPort = 21213;
        config.m_isPaused = true;
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        ParameterSet pset;
        String responseJSON;
        Response response;
        // Call insert on admin port
        pset = ParameterSet.fromArrayNoCopy(1, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // Call insert on closed client port and expect failure
        pset = ParameterSet.fromArrayNoCopy(2, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SERVER_UNAVAILABLE);
        // open client port
        pset = ParameterSet.emptyParameterSet();
        responseJSON = callProcOverJSON("@Resume", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // call insert on open client port
        pset = ParameterSet.fromArrayNoCopy(2, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // call insert on admin port again (now that both ports are open)
        pset = ParameterSet.fromArrayNoCopy(3, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // put the system in admin mode
        pset = ParameterSet.emptyParameterSet();
        responseJSON = callProcOverJSON("@Pause", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // Call insert on admin port
        pset = ParameterSet.fromArrayNoCopy(4, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // Call insert on closed client port and expect failure
        pset = ParameterSet.fromArrayNoCopy(5, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SERVER_UNAVAILABLE);
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) HttpResponse(org.apache.http.HttpResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) TimestampType(org.voltdb.types.TimestampType) File(java.io.File)

Example 42 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class paymentByCustomerName method processPayment.

public VoltTable[] processPayment(short w_id, byte d_id, short c_w_id, byte c_d_id, int c_id, double h_amount, VoltTableRow customer, TimestampType timestamp) {
    voltQueueSQL(getWarehouse, w_id);
    voltQueueSQL(getDistrict, w_id, d_id);
    final VoltTable[] results = voltExecuteSQL();
    final VoltTable warehouse = results[0];
    final VoltTable district = results[1];
    voltQueueSQL(updateWarehouseBalance, h_amount, w_id);
    voltQueueSQL(updateDistrictBalance, h_amount, w_id, d_id);
    voltExecuteSQL();
    //do stuff to extract district and warehouse info.
    //customer info
    final byte[] c_first = customer.getStringAsBytes(C_FIRST_IDX);
    final byte[] c_middle = customer.getStringAsBytes(C_MIDDLE_IDX);
    final byte[] c_last = customer.getStringAsBytes(C_LAST_IDX);
    final byte[] c_street_1 = customer.getStringAsBytes(C_STREET_1_IDX);
    final byte[] c_street_2 = customer.getStringAsBytes(C_STREET_2_IDX);
    final byte[] c_city = customer.getStringAsBytes(C_CITY_IDX);
    final byte[] c_state = customer.getStringAsBytes(C_STATE_IDX);
    final byte[] c_zip = customer.getStringAsBytes(C_ZIP_IDX);
    final byte[] c_phone = customer.getStringAsBytes(C_PHONE_IDX);
    final TimestampType c_since = customer.getTimestampAsTimestamp(C_SINCE_IDX);
    final byte[] c_credit = customer.getStringAsBytes(C_CREDIT_IDX);
    final double c_credit_lim = customer.getDouble(C_CREDIT_LIM_IDX);
    final double c_discount = customer.getDouble(C_DISCOUNT_IDX);
    final double c_balance = customer.getDouble(C_BALANCE_IDX) - h_amount;
    final double c_ytd_payment = customer.getDouble(C_YTD_PAYMENT_IDX) + h_amount;
    final int c_payment_cnt = (int) customer.getLong(C_PAYMENT_CNT_IDX) + 1;
    byte[] c_data;
    if (Arrays.equals(c_credit, Constants.BAD_CREDIT_BYTES)) {
        c_data = customer.getStringAsBytes(C_DATA_IDX);
        byte[] newData = (c_id + " " + c_d_id + " " + c_w_id + " " + d_id + " " + w_id + " " + h_amount + "|").getBytes();
        int newLength = newData.length + c_data.length;
        if (newLength > Constants.MAX_C_DATA) {
            newLength = Constants.MAX_C_DATA;
        }
        ByteBuilder builder = new ByteBuilder(newLength);
        int minLength = newLength;
        if (newData.length < minLength)
            minLength = newData.length;
        builder.append(newData, 0, minLength);
        int remaining = newLength - minLength;
        builder.append(c_data, 0, remaining);
        c_data = builder.array();
        voltQueueSQL(updateBCCustomer, c_balance, c_ytd_payment, c_payment_cnt, c_data, c_w_id, c_d_id, c_id);
    } else {
        c_data = new byte[0];
        voltQueueSQL(updateGCCustomer, c_balance, c_ytd_payment, c_payment_cnt, c_w_id, c_d_id, c_id);
    }
    // Concatenate w_name, four spaces, d_name
    byte[] w_name = warehouse.fetchRow(0).getStringAsBytes(W_NAME_IDX);
    final byte[] FOUR_SPACES = { ' ', ' ', ' ', ' ' };
    byte[] d_name = district.fetchRow(0).getStringAsBytes(D_NAME_IDX);
    ByteBuilder builder = new ByteBuilder(w_name.length + FOUR_SPACES.length + d_name.length);
    builder.append(w_name);
    builder.append(FOUR_SPACES);
    builder.append(d_name);
    byte[] h_data = builder.array();
    // Create the history record
    voltQueueSQL(insertHistory, c_id, c_d_id, c_w_id, d_id, w_id, timestamp, h_amount, h_data);
    voltExecuteSQL();
    // TPC-C 2.5.3.3: Must display the following fields:
    // W_ID, D_ID, C_ID, C_D_ID, C_W_ID, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP,
    // D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, C_FIRST, C_MIDDLE, C_LAST, C_STREET_1,
    // C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM,
    // C_DISCOUNT, C_BALANCE, the first 200 characters of C_DATA (only if C_CREDIT = "BC"),
    // H_AMOUNT, and H_DATE.
    // Return the entire warehouse and district tuples. The client provided:
    // w_id, d_id, c_d_id, c_w_id, h_amount, h_data.
    // Build a table for the rest
    final VoltTable misc = misc_template.clone(1024);
    misc.addRow(c_id, c_first, c_middle, c_last, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_since, c_credit, c_credit_lim, c_discount, c_balance, c_data);
    // Hand back all the warehouse, district, and customer data
    return new VoltTable[] { warehouse, district, misc };
}
Also used : TimestampType(org.voltdb.types.TimestampType) VoltTable(org.voltdb.VoltTable)

Example 43 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class TestCatalogUpdateSuite method testUpdate.

public void testUpdate() throws Exception {
    Client client = getClient();
    String newCatalogURL;
    String deploymentURL;
    VoltTable[] results;
    CatTestCallback callback;
    loadSomeData(client, 0, 25);
    assertCallbackSuccess(client);
    negativeTests(client);
    assertCallbackSuccess(client);
    // asynchronously call some random inserts
    loadSomeData(client, 25, 25);
    assertCallbackSuccess(client);
    // add a procedure "InsertOrderLineBatched"
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.xml");
    callback = new CatTestCallback(ClientResponse.SUCCESS);
    client.updateApplicationCatalog(callback, new File(newCatalogURL), new File(deploymentURL));
    // don't care if this succeeds or fails.
    // calling the new proc before the cat change returns is not guaranteed to work
    // we just hope it doesn't crash anything
    int x = 3;
    SyncCallback cb = new SyncCallback();
    client.callProcedure(cb, org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    cb.waitForResponse();
    // make sure the previous catalog change has completed
    assertCallbackSuccess(client);
    // now calling the new proc better work
    x = 2;
    client.callProcedure(org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    loadSomeData(client, 50, 5);
    assertCallbackSuccess(client);
    // this is a do nothing change... shouldn't affect anything
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.xml");
    results = client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL)).getResults();
    assertTrue(results.length == 1);
    assertCallbackSuccess(client);
    // now calling the new proc better work
    x = 4;
    client.callProcedure(org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    loadSomeData(client, 55, 5);
    // remove the procedure we just added async
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-base.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-base.xml");
    callback = new CatTestCallback(ClientResponse.SUCCESS);
    client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
    // don't care if this works now
    x = 4;
    cb = new SyncCallback();
    client.callProcedure(cb, org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    cb.waitForResponse();
    // make sure the previous catalog change has completed
    assertCallbackSuccess(client);
    // now calling the new proc better fail
    x = 5;
    cb = new SyncCallback();
    client.callProcedure(cb, org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    cb.waitForResponse();
    assertNotSame(cb.getResponse().getStatus(), ClientResponse.SUCCESS);
    loadSomeData(client, 60, 5);
    // change the insert new order procedure
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-conflict.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-conflict.xml");
    results = client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL)).getResults();
    assertTrue(results.length == 1);
    // call the new proc and make sure the one we want gets run
    results = client.callProcedure(InsertNewOrder.class.getSimpleName(), 100, 100, 100, 100, (short) 100, 100, 1.0, "a").getResults();
    assertEquals(1, results.length);
    assertEquals(1776, results[0].asScalarLong());
    // load a big catalog change just to make sure nothing fails horribly
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-many.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-many.xml");
    results = client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL)).getResults();
    assertTrue(results.length == 1);
    loadSomeData(client, 65, 5);
    //Check that if a catalog update blocker exists the catalog update fails
    ZooKeeper zk = ZKUtil.getClient(((LocalCluster) m_config).zkinterface(0), 10000, new HashSet<Long>());
    final String catalogUpdateBlockerPath = zk.create(VoltZK.elasticJoinActiveBlocker, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
    try {
        /*
             * Update the catalog and expect failure
             */
        newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-base.jar");
        deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-base.xml");
        boolean threw = false;
        try {
            client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
        } catch (ProcCallException e) {
            e.printStackTrace();
            threw = true;
        }
        assertTrue(threw);
    } finally {
        zk.delete(catalogUpdateBlockerPath, -1);
    }
    //Expect success
    client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
    assertCallbackSuccess(client);
    assertTrue(true);
}
Also used : VoltTable(org.voltdb.VoltTable) SyncCallback(org.voltdb.client.SyncCallback) ZooKeeper(org.apache.zookeeper_voltpatches.ZooKeeper) TimestampType(org.voltdb.types.TimestampType) Client(org.voltdb.client.Client) File(java.io.File) InsertNewOrder(org.voltdb.benchmark.tpcc.procedures.InsertNewOrder) ProcCallException(org.voltdb.client.ProcCallException)

Example 44 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class RegressionSuite method assertApproximateContentOfRow.

private static void assertApproximateContentOfRow(int row, Object[] expectedRow, VoltTable actualRow, double epsilon) {
    assertEquals("Actual row has wrong number of columns", expectedRow.length, actualRow.getColumnCount());
    for (int i = 0; i < expectedRow.length; ++i) {
        String msg = "Row " + row + ", col " + i + ": ";
        Object expectedObj = expectedRow[i];
        if (expectedObj == null) {
            VoltType vt = actualRow.getColumnType(i);
            actualRow.get(i, vt);
            assertTrue(msg, actualRow.wasNull());
        } else if (expectedObj instanceof GeographyPointValue) {
            assertApproximatelyEquals(msg, (GeographyPointValue) expectedObj, actualRow.getGeographyPointValue(i), epsilon);
        } else if (expectedObj instanceof GeographyValue) {
            assertApproximatelyEquals(msg, (GeographyValue) expectedObj, actualRow.getGeographyValue(i), epsilon);
        } else if (expectedObj instanceof Long) {
            long val = ((Long) expectedObj).longValue();
            assertEquals(msg, val, actualRow.getLong(i));
        } else if (expectedObj instanceof Integer) {
            long val = ((Integer) expectedObj).longValue();
            assertEquals(msg, val, actualRow.getLong(i));
        } else if (expectedObj instanceof Double) {
            double expectedValue = (Double) expectedObj;
            double actualValue = actualRow.getDouble(i);
            // for null values, convert value into double min
            if (actualRow.wasNull()) {
                actualValue = Double.MIN_VALUE;
            }
            if (epsilon <= 0) {
                String fullMsg = msg + String.format("Expected value %f != actual value %f", expectedValue, actualValue);
                assertEquals(fullMsg, expectedValue, actualValue);
            } else {
                String fullMsg = msg + String.format("abs(Expected Value - Actual Value) = %e >= %e", Math.abs(expectedValue - actualValue), epsilon);
                assertTrue(fullMsg, Math.abs(expectedValue - actualValue) < epsilon);
            }
        } else if (expectedObj instanceof BigDecimal) {
            BigDecimal exp = (BigDecimal) expectedObj;
            BigDecimal got = actualRow.getDecimalAsBigDecimal(i);
            // Either both are null or neither are null.
            assertEquals(exp == null, got == null);
            assertEquals(msg, exp.doubleValue(), got.doubleValue(), epsilon);
        } else if (expectedObj instanceof String) {
            String val = (String) expectedObj;
            assertEquals(msg, val, actualRow.getString(i));
        } else if (expectedObj instanceof TimestampType) {
            TimestampType val = (TimestampType) expectedObj;
            assertEquals(msg, val, actualRow.getTimestampAsTimestamp(i));
        } else {
            fail("Unexpected type in expected row: " + expectedObj.getClass().getSimpleName());
        }
    }
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) VoltType(org.voltdb.VoltType) TimestampType(org.voltdb.types.TimestampType) GeographyPointValue(org.voltdb.types.GeographyPointValue) BigDecimal(java.math.BigDecimal)

Example 45 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class TestApproxCountDistinctSuite method fillTable.

private void fillTable(Client client, String tbl) throws Exception {
    Random r = new Random(777);
    // Insert 1000 rows of data, and 84 (every 13th row) of nulls.
    int numRows = 1084;
    if (isValgrind()) {
        // This test takes 20 minutes if we use 1000 rows in valgrind,
        // so reduce the number of rows so it runs in a reasonable amount
        // of time.
        numRows = 109;
    }
    // Insert 1000 rows of data, and 84 (every 13th row) of nulls.
    for (int i = 0; i < numRows; ++i) {
        // it doesn't mess with the algorithm.
        if (i % 13 == 0) {
            client.callProcedure(tbl + ".Insert", i, null, null, null, null, null, null);
        } else {
            // Use a a Gaussian distribution (bell curve), to exercise the hyperloglog hash.
            // July 22, 2015 or so
            final long baseTs = 1437589323966000L;
            client.callProcedure(tbl + ".Insert", // primary key
            i, getNormalValue(r, 1000, Long.MIN_VALUE, Long.MAX_VALUE), getNormalValue(r, 1000, Integer.MIN_VALUE, Integer.MAX_VALUE), getNormalValue(r, 1000, Short.MIN_VALUE, Short.MAX_VALUE), getNormalValue(r, 100, Byte.MIN_VALUE, Byte.MAX_VALUE), // decimal
            getNormalDecimalValue(r, 1000000000), new TimestampType(baseTs + getNormalValue(r, 10000, Short.MIN_VALUE, Short.MAX_VALUE)));
        }
    }
}
Also used : Random(java.util.Random) TimestampType(org.voltdb.types.TimestampType)

Aggregations

TimestampType (org.voltdb.types.TimestampType)127 VoltTable (org.voltdb.VoltTable)37 BigDecimal (java.math.BigDecimal)30 Test (org.junit.Test)23 Client (org.voltdb.client.Client)19 ArrayList (java.util.ArrayList)16 IOException (java.io.IOException)11 GeographyValue (org.voltdb.types.GeographyValue)11 GeographyPointValue (org.voltdb.types.GeographyPointValue)10 Date (java.util.Date)9 File (java.io.File)7 VoltTableRow (org.voltdb.VoltTableRow)7 ProcCallException (org.voltdb.client.ProcCallException)7 ByteBuffer (java.nio.ByteBuffer)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)5 ClientResponse (org.voltdb.client.ClientResponse)5 Random (java.util.Random)4 VoltType (org.voltdb.VoltType)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2