Search in sources :

Example 11 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class UpdateBaseProc method validateCIDData.

public static void validateCIDData(VoltTable data, VoltTable view, String callerId) {
    // empty tables are lamely valid
    if (data.getRowCount() == 0)
        return;
    byte cid = (byte) data.fetchRow(0).getLong("cid");
    data.resetRowPosition();
    long prevCnt = 0;
    long entries = 0;
    long max = 0;
    long min = Long.MAX_VALUE;
    long sum = 0;
    while (data.advanceRow()) {
        // check that the inner join of partitioned and replicated tables
        // produce the expected result
        byte desc = (byte) data.getLong("desc");
        if (desc != cid) {
            throw new VoltAbortException(callerId + " desc value " + desc + " not equal to cid value " + cid);
        }
        // make sure all cnt values are consecutive
        long cntValue = data.getLong("cnt");
        if ((prevCnt > 0) && ((prevCnt - 1) != cntValue)) {
            throw new VoltAbortException(callerId + " cnt values are not consecutive" + " for cid " + cid + ". Got " + cntValue + ", prev was: " + prevCnt);
        }
        if (view != null) {
            entries += 1;
            max = Math.max(max, cntValue);
            min = Math.min(min, cntValue);
            sum += cntValue;
        }
        prevCnt = cntValue;
    }
    if (view != null) {
        if (view.getRowCount() != 1)
            throw new VoltAbortException("View has multiple entries of the same cid, that should not happen.");
        VoltTableRow row0 = view.fetchRow(0);
        long v_entries = row0.getLong("entries");
        long v_max = row0.getLong("maximum");
        long v_min = row0.getLong("minimum");
        long v_sum = row0.getLong("summation");
        if (v_entries != entries)
            throw new VoltAbortException("The count(*):" + v_entries + " materialized view aggregation does not match the number of cnt entries:" + entries + " for cid:" + cid);
        if (v_max != max)
            throw new VoltAbortException("The max(cnt):" + v_max + " materialized view aggregation does not match the max:" + max + " for cid:" + cid);
        if (v_min != min)
            throw new VoltAbortException("The min(cnt):" + v_min + " materialized view aggregation does not match the min:" + min + " for cid:" + cid);
        if (v_sum != sum)
            throw new VoltAbortException("The sum(cnt):" + v_sum + " materialized view aggregation does not match the sum:" + sum + " for cid:" + cid);
    }
}
Also used : VoltTableRow(org.voltdb.VoltTableRow)

Example 12 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class UpdateBaseProc method validateStreamData.

private void validateStreamData(String type, VoltTable exview, VoltTable shadowview, byte cid, long cnt) {
    if (type == "delete") {
        if (exview.getRowCount() == 0) {
            // success
            return;
        } else {
            throw new VoltAbortException("Export view has " + exview.getRowCount() + " rows for this id. Zero expected after delete");
        }
    }
    if (exview.getRowCount() != 1)
        throw new VoltAbortException("Export view has " + exview.getRowCount() + " entries of the same cid, that should not happen.");
    VoltTableRow row0 = exview.fetchRow(0);
    long v_entries = row0.getLong("entries");
    long v_max = row0.getLong("maximum");
    long v_min = row0.getLong("minimum");
    long v_sum = row0.getLong("summation");
    if (shadowview.getRowCount() == 1) {
        row0 = shadowview.fetchRow(0);
        long shadow_entries = row0.getLong("entries");
        long shadow_max = row0.getLong("maximum");
        long shadow_min = row0.getLong("minimum");
        long shadow_sum = row0.getLong("summation");
        // adjust the shadow values for updated cnt, not done for "update"
        if (type == "insert") {
            shadow_entries++;
            shadow_max = Math.max(shadow_max, v_max);
            shadow_min = Math.min(shadow_min, v_min);
            shadow_sum += cnt;
        }
        if (v_entries != shadow_entries)
            throw new VoltAbortException("View entries:" + v_entries + " materialized view aggregation does not match the number of shadow entries:" + shadow_entries + " for cid:" + cid);
        if (v_max != shadow_max)
            throw new VoltAbortException("View v_max:" + v_max + " materialized view aggregation does not match the shadow max:" + shadow_max + " for cid:" + cid);
        if (v_min != shadow_min)
            throw new VoltAbortException("View v_min:" + v_min + " materialized view aggregation does not match the shadow min:" + shadow_min + " for cid:" + cid);
        if (v_sum != shadow_sum)
            throw new VoltAbortException("View v_sum:" + v_sum + " materialized view aggregation does not match the shadow sum:" + shadow_sum + " for cid:" + cid);
        voltQueueSQL(p_upsertExViewShadowData, cid, shadow_entries, shadow_max, shadow_min, shadow_sum);
    } else {
        // first time through, get initial values into the shadow table
        voltQueueSQL(p_upsertExViewShadowData, cid, v_entries, v_max, v_min, v_sum);
    }
    // update the shadow table with the new matching values and return
    voltExecuteSQL();
    return;
}
Also used : VoltTableRow(org.voltdb.VoltTableRow)

Example 13 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class UpdateBaseProc method doWork.

protected VoltTable[] doWork(SQLStmt getCIDData, SQLStmt cleanUp, SQLStmt insert, SQLStmt export, SQLStmt getAdHocData, SQLStmt getViewData, byte cid, long rid, byte[] value, byte shouldRollback, boolean usestreamviews) {
    voltQueueSQL(getCIDData, cid);
    voltQueueSQL(getAdHocData);
    voltQueueSQL(d_getCount, cid);
    voltQueueSQL(getViewData, cid);
    VoltTable[] results = voltExecuteSQL();
    VoltTable data = results[0];
    VoltTable adhoc = results[1];
    VoltTable dim = results[2];
    VoltTable view = results[3];
    final long txnid = getUniqueId();
    final long ts = getTransactionTime().getTime();
    long prevtxnid = 0;
    long prevrid = 0;
    long cnt = 0;
    // read data modified by AdHocMayhemThread for later insertion
    final long adhocInc = adhoc.getRowCount() > 0 ? adhoc.fetchRow(0).getLong("inc") : 0;
    final long adhocJmp = adhoc.getRowCount() > 0 ? adhoc.fetchRow(0).getLong("jmp") : 0;
    // compute the cheesy checksum of all of the table's contents based on
    // this cid to subsequently store in the new row
    final long cidallhash = MiscUtils.cheesyBufferCheckSum(data.getBuffer());
    // get the most recent row's data
    int rowCount = data.getRowCount();
    if (rowCount != 0) {
        VoltTableRow row = data.fetchRow(0);
        cnt = row.getLong("cnt") + 1;
        prevtxnid = row.getLong("txnid");
        prevrid = row.getLong("rid");
    }
    validateCIDData(data, view, getClass().getName());
    // check the rids monotonically increase
    if (prevrid >= rid) {
        throw new VoltAbortException(getClass().getName() + " previous rid " + prevrid + " >= than current rid " + rid + " for cid " + cid);
    }
    voltQueueSQL(insert, txnid, prevtxnid, ts, cid, cidallhash, rid, cnt, adhocInc, adhocJmp, value);
    voltQueueSQL(export, txnid, prevtxnid, ts, cid, cidallhash, rid, cnt, adhocInc, adhocJmp, value);
    voltQueueSQL(cleanUp, cid, cnt - 10);
    voltQueueSQL(getCIDData, cid);
    voltQueueSQL(getViewData, cid);
    assert dim.getRowCount() == 1;
    VoltTable[] retval = voltExecuteSQL();
    // Is this comment below now obsolete and can be removed?
    // Verify that our update happened.  The client is reporting data errors on this validation
    // not seen by the server, hopefully this will bisect where they're occurring.
    data = retval[3];
    view = retval[4];
    VoltTableRow row = data.fetchRow(0);
    if (row.getVarbinary("value").length == 0)
        throw new VoltAbortException("Value column contained no data in UpdateBaseProc");
    validateCIDData(data, view, getClass().getName());
    if (usestreamviews) {
        // insert to export table done, check corresponding materialized view
        validateView(cid, cnt, "insert");
        // update export materialized view & validate
        // arbitrary. could use random but really doesn't matter
        int someData = 5;
        voltQueueSQL(p_updateExViewData, someData, someData + 1, someData + 2, someData + 3, cid);
        voltQueueSQL(p_updateExViewShadowData, someData, someData + 1, someData + 2, someData + 3, cid);
        voltExecuteSQL();
        validateView(cid, cnt, "update");
        // delete from export materialized view & validate
        voltQueueSQL(p_deleteExViewData, cid);
        voltQueueSQL(p_deleteExViewShadowData, cid);
        voltExecuteSQL();
        validateView(cid, cnt, "delete");
    }
    if (shouldRollback != 0) {
        throw new VoltAbortException("EXPECTED ROLLBACK");
    }
    return retval;
}
Also used : VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 14 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class SwapTablesBase method run.

public VoltTable[] run(long p, byte shouldRollback, String storedProcName) {
    // and used before the SWAP TABLES (as ad hoc DML) feature is complete
    if (USE_FAKE_SWAP) {
        return runFakeSwap(p, shouldRollback, storedProcName);
    }
    // Execute the SWAP TABLES query, with SELECT COUNT(*) queries before and after
    voltQueueSQL(count_tru);
    voltQueueSQL(count_swap);
    voltQueueSQL(scancount_tru);
    voltQueueSQL(scancount_swap);
    //        voltQueueSQL(swap);
    voltQueueSQL(count_tru);
    voltQueueSQL(count_swap);
    voltQueueSQL(scancount_tru);
    voltQueueSQL(scancount_swap);
    VoltTable[] results = voltExecuteSQL(true);
    // Check that the total (opt) counts of the two tables have been swapped
    VoltTable data = results[0];
    VoltTableRow row = data.fetchRow(0);
    long truCountBefore = row.getLong(0);
    data = results[1];
    row = data.fetchRow(0);
    long swapCountBefore = row.getLong(0);
    data = results[5];
    row = data.fetchRow(0);
    long truCountAfter = row.getLong(0);
    data = results[6];
    row = data.fetchRow(0);
    long swapCountAfter = row.getLong(0);
    if (truCountBefore != swapCountAfter || swapCountBefore != truCountAfter) {
        throw new VoltAbortException("after swap (opt) counts (" + truCountAfter + "," + swapCountAfter + ") do not match reverse of those before (" + truCountBefore + "," + swapCountBefore + ")");
    }
    // Check that the partial (scan) counts of the two tables have been swapped
    data = results[2];
    row = data.fetchRow(0);
    long truScanCountBefore = row.getLong(0);
    data = results[3];
    row = data.fetchRow(0);
    long swapScanCountBefore = row.getLong(0);
    data = results[7];
    row = data.fetchRow(0);
    long truScanCountAfter = row.getLong(0);
    data = results[8];
    row = data.fetchRow(0);
    long swapScanCountAfter = row.getLong(0);
    if (truScanCountBefore != swapScanCountAfter || swapScanCountBefore != truScanCountAfter) {
        throw new VoltAbortException("after swap (scan) counts (" + truScanCountAfter + "," + swapScanCountAfter + ") do not match reverse of those before (" + truScanCountBefore + "," + swapScanCountBefore + ")");
    }
    if (shouldRollback != 0) {
        throw new VoltAbortException("EXPECTED SWAP ROLLBACK");
    }
    return results;
}
Also used : VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) VoltAbortException(org.voltdb.VoltProcedure.VoltAbortException)

Example 15 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class SwapTablesBase method runFakeSwap.

// TODO: this is a temporary method, so that the test code can be tested
// and used before the SWAP TABLES (as ad hoc DML) feature is complete.
private VoltTable[] runFakeSwap(long p, byte shouldRollback, String storedProcName) {
    // Execute the SWAP TABLES query, with SELECT COUNT(*) queries before and after
    voltQueueSQL(count_tru);
    voltQueueSQL(count_swap);
    voltQueueSQL(scancount_tru);
    voltQueueSQL(scancount_swap);
    // "Fake" swap, using a temp table:
    voltQueueSQL(swap6);
    voltQueueSQL(swap0);
    voltQueueSQL(swap6);
    voltQueueSQL(swap1);
    voltQueueSQL(swap2);
    voltQueueSQL(swap3);
    voltQueueSQL(swap4);
    voltQueueSQL(swap5);
    voltQueueSQL(swap6);
    voltQueueSQL(swap0);
    voltQueueSQL(swap6);
    voltQueueSQL(count_tru);
    voltQueueSQL(count_swap);
    voltQueueSQL(scancount_tru);
    voltQueueSQL(scancount_swap);
    VoltTable[] results = voltExecuteSQL(true);
    // Check that the total (opt) counts of the two tables have been swapped
    VoltTable data = results[0];
    VoltTableRow row = data.fetchRow(0);
    long truCountBefore = row.getLong(0);
    data = results[1];
    row = data.fetchRow(0);
    long swapCountBefore = row.getLong(0);
    data = results[15];
    row = data.fetchRow(0);
    long truCountAfter = row.getLong(0);
    data = results[16];
    row = data.fetchRow(0);
    long swapCountAfter = row.getLong(0);
    if (truCountBefore != swapCountAfter || swapCountBefore != truCountAfter) {
        throw new VoltAbortException("after swap (opt) counts (" + truCountAfter + "," + swapCountAfter + ") do not match reverse of those before (" + truCountBefore + "," + swapCountBefore + ")");
    }
    // Check that the partial (scan) counts of the two tables have been swapped
    data = results[2];
    row = data.fetchRow(0);
    long truScanCountBefore = row.getLong(0);
    data = results[3];
    row = data.fetchRow(0);
    long swapScanCountBefore = row.getLong(0);
    data = results[17];
    row = data.fetchRow(0);
    long truScanCountAfter = row.getLong(0);
    data = results[18];
    row = data.fetchRow(0);
    long swapScanCountAfter = row.getLong(0);
    if (truScanCountBefore != swapScanCountAfter || swapScanCountBefore != truScanCountAfter) {
        throw new VoltAbortException("after swap (scan) counts (" + truScanCountAfter + "," + swapScanCountAfter + ") do not match reverse of those before (" + truScanCountBefore + "," + swapScanCountBefore + ")");
    }
    // TODO: temporary debug print:
    data = results[4];
    row = data.fetchRow(0);
    long countTemp0 = row.getLong(0);
    data = results[6];
    row = data.fetchRow(0);
    long countTemp1 = row.getLong(0);
    data = results[12];
    row = data.fetchRow(0);
    long countTemp2 = row.getLong(0);
    data = results[14];
    row = data.fetchRow(0);
    long countTemp3 = row.getLong(0);
    System.out.println("In " + storedProcName + ": shouldRollback: " + shouldRollback + "\n  truCountBefore: " + truCountBefore + " swapCountBefore: " + swapCountBefore + "; truCountAfter: " + truCountAfter + " swapCountAfter: " + swapCountAfter + "\n  truScanCountBefore: " + truScanCountBefore + " swapScanCountBefore: " + swapScanCountBefore + "; truScanCountAfter: " + truScanCountAfter + " swapScanCountAfter: " + swapScanCountAfter + "\n  countTemp0: " + countTemp0 + " countTemp1: " + countTemp1 + "; countTemp2: " + countTemp2 + " countTemp3: " + countTemp3);
    if (shouldRollback != 0) {
        throw new VoltAbortException("EXPECTED SWAP ROLLBACK");
    }
    return results;
}
Also used : VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) VoltAbortException(org.voltdb.VoltProcedure.VoltAbortException)

Aggregations

VoltTableRow (org.voltdb.VoltTableRow)65 VoltTable (org.voltdb.VoltTable)57 Client (org.voltdb.client.Client)23 ProcCallException (org.voltdb.client.ProcCallException)11 TimestampType (org.voltdb.types.TimestampType)7 NoConnectionsException (org.voltdb.client.NoConnectionsException)6 IOException (java.io.IOException)5 VoltAbortException (org.voltdb.VoltProcedure.VoltAbortException)5 Date (java.util.Date)4 WorkWithBigString (org.voltdb_testprocs.regressionsuites.sqlfeatureprocs.WorkWithBigString)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 ClientResponse (org.voltdb.client.ClientResponse)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 ByteBuilder (org.voltdb.benchmark.tpcc.procedures.ByteBuilder)1