Please see below for a standalone testcase. However after playing with
it I no longer claim that the issue is related to the two-phase
commit...





import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Savepoint;
import java.sql.Statement;
import java.util.Random;
import org.h2.jdbcx.JdbcDataSource;


public class H2_TwoPhaseCommit_issue
{
    private static final String DATA_TABLE_NAME = "MATDB_DATA";

    private static final String DATA_STAMP_SEQUENCE_NAME =
"DATA_STAMP";

    private static final int DATA_STAMP_SEQUENCE_CACHE_SIZE = 1024;

    private static final String PREPARED_TXN_NAME = "BULK_ENSURED";


    public static void main(String[] args) throws Exception
    {
        // create/open the DB
        System.setProperty("h2.lobInDatabase", "true");
        String dbUrl = "jdbc:h2:split:" +
System.getProperty("java.io.tmpdir") + "txn_log_issue";

        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL(dbUrl);
        Connection dbConn = ds.getConnection();

        // create data table and a relevant precompiled insertion
statement
        Statement st = null;
        st = dbConn.createStatement();
        st.executeUpdate("CREATE SEQUENCE IF NOT EXISTS " +
DATA_STAMP_SEQUENCE_NAME + " CACHE " +
DATA_STAMP_SEQUENCE_CACHE_SIZE);
        st.executeUpdate("CREATE TABLE IF NOT EXISTS " +
DATA_TABLE_NAME + "("
                + "GLOBAL_STAMP BIGINT NOT NULL DEFAULT NEXT VALUE FOR
" + DATA_STAMP_SEQUENCE_NAME + " PRIMARY KEY, "
                + "DATA BLOB, "
                + "DESC BLOB)");
        PreparedStatement tableDataInsertSt =
dbConn.prepareStatement("INSERT INTO " + DATA_TABLE_NAME + " VALUES("
                + "DEFAULT, "
                + "?, "
                + "?)", Statement.RETURN_GENERATED_KEYS);

        Random random = new Random(0xBAD); // ensure full
repeatability
        for (int i = 0; i < 2048; ++i) {
            // start a transaction
            dbConn.setAutoCommit(false);
            String dbSpName = "a savepoint";
            Savepoint dbSp = dbConn.setSavepoint(dbSpName);

            // generate some data
            byte[] data = new byte[(int)(random.nextDouble() *
10240)];
            byte[] desc = new byte[(int)(random.nextDouble() *
10240)];
            random.nextBytes(data);
            random.nextBytes(desc);

            // save the data in the DB
            tableDataInsertSt.setBytes(1, data);
            tableDataInsertSt.setBytes(2, desc);
            tableDataInsertSt.executeUpdate();

            // commit the transaction (using two-phase commit)
            st.executeUpdate("PREPARE COMMIT " + PREPARED_TXN_NAME);
            dbConn.commit();
            dbConn.setAutoCommit(true);
            //st.executeUpdate("CHECKPOINT"); // if uncommented this
prevents the transaction log from growing
        }

        // done
        dbConn.close();
    }
}

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to