/* This file is part of VoltDB.
 * Copyright (C) 2008-2012 VoltDB Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

package voter.procedures;

import org.voltdb.ProcInfo;
import org.voltdb.SQLStmt;
import org.voltdb.VoltProcedure;
import org.voltdb.VoltTable;

@ProcInfo (
    partitionInfo = "transactions.pid:0",
    singlePartition = true
)
public class doTxn extends VoltProcedure {

    public final SQLStmt getLastTxnId = new SQLStmt(
            "SELECT txnid, rid FROM transactions WHERE txnid < ? ORDER BY txnid DESC LIMIT 1;");

    public final SQLStmt getReplicated = new SQLStmt(
            "SELECT * FROM replicated ORDER BY id LIMIT 10;");

    public final SQLStmt insertTxnid = new SQLStmt(
            "INSERT INTO transactions VALUES (?, ?, ?, ?);");

    public final SQLStmt deleteOldTxns = new SQLStmt(
            "DELETE FROM transactions WHERE rid < ? AND rid >= 0;");

    public VoltTable[] run(byte partition, long rid, long oldestRid, byte[] value) {
        voltQueueSQL(getLastTxnId, getTransactionId());
        voltQueueSQL(getReplicated);
        voltQueueSQL(insertTxnid, getTransactionId(), partition, rid, value);
        voltQueueSQL(deleteOldTxns, oldestRid);
        return voltExecuteSQL(true);
    }
}

@@ -1503,24 +1503,8 @@
 ions
- WHERE txnid %3C ?
  ORD
@@ -1987,92 +1987,841 @@
     
-voltQueueSQL(getLastTxnId, getTransactionId());%0A        voltQueueSQL(getReplicated);
+final long txnId = getTransactionId();%0A        voltQueueSQL(getLastTxnId);%0A        voltQueueSQL(getReplicated);%0A        VoltTable%5B%5D results = voltExecuteSQL();%0A%0A        if (results%5B0%5D.advanceRow()) %7B%0A            long previousTxnId = results%5B0%5D.getLong(%22txnid%22);%0A            long previousRid = results%5B0%5D.getLong(%22rid%22);%0A            if (previousTxnId %3E= txnId %7C%7C previousRid %3E= rid) %7B%0A                throw new VoltAbortException(%22doTxn executed out of order%22);%0A            %7D%0A            results%5B0%5D.resetRowPosition();%0A        %7D%0A        if (results%5B1%5D.advanceRow()) %7B%0A            long previousTxnId = results%5B1%5D.getLong(%22id%22);%0A            if (previousTxnId %3E= txnId) %7B%0A                throw new VoltAbortException(%22doTxn and updateReplicated executed out of order%22);%0A            %7D%0A            results%5B1%5D.resetRowPosition();%0A        %7D%0A
 %0A   
@@ -2851,34 +2851,21 @@
 tTxnid, 
-getTransactio
+tx
 nId
-()
 , partit
@@ -2942,15 +2942,8 @@
     
-return 
 volt
@@ -2955,21 +2955,46 @@
 teSQL(true);
+%0A%0A        return results;
 %0A    %7D%0A%7D%0A

Add some checks in the single partition procedure.