Continuation 
of https://groups.google.com/forum/#!topic/h2-database/oHpaE_LMLz4

I'm getting following error with nioMemLZF (url= jdbc:h2:nioMemLZF:db):

org.h2.jdbc.JdbcSQLException: General error: 
"java.lang.IllegalStateException: File corrupted in chunk 28, expected page 
length 4..32, got -1621686845 [1.4.193/6]"; SQL statement:
update account set balance = ? where id = ? [50000-193]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.message.DbException.convert(DbException.java:295)
at org.h2.command.Command.executeUpdate(Command.java:266)
at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:201)
at Bug_H2_4$Arte.call(Bug_H2_4.java:99)
at Bug_H2_4$Arte.call(Bug_H2_4.java:82)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: File corrupted in chunk 28, 
expected page length 4..32, got -1621686845 [1.4.193/6]
at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:766)
at org.h2.mvstore.Page.read(Page.java:649)
at org.h2.mvstore.Page.read(Page.java:195)
at org.h2.mvstore.MVStore.readPage(MVStore.java:1952)
at org.h2.mvstore.MVMap.readPage(MVMap.java:738)
at org.h2.mvstore.Page.getChildPage(Page.java:217)
at org.h2.mvstore.MVMap.binarySearch(MVMap.java:470)
at org.h2.mvstore.MVMap.binarySearch(MVMap.java:471)
at org.h2.mvstore.MVMap.binarySearch(MVMap.java:471)
at org.h2.mvstore.MVMap.get(MVMap.java:452)
at 
org.h2.mvstore.db.TransactionStore$TransactionMap.getValue(TransactionStore.java:1203)
at 
org.h2.mvstore.db.TransactionStore$TransactionMap.get(TransactionStore.java:1180)
at 
org.h2.mvstore.db.TransactionStore$TransactionMap.get(TransactionStore.java:1148)
at org.h2.mvstore.db.MVPrimaryIndex.getRow(MVPrimaryIndex.java:215)
at org.h2.mvstore.db.MVTable.getRow(MVTable.java:463)
at 
org.h2.mvstore.db.MVSecondaryIndex$MVStoreCursor.get(MVSecondaryIndex.java:489)
at org.h2.index.IndexCursor.get(IndexCursor.java:288)
at org.h2.table.TableFilter.get(TableFilter.java:594)
at org.h2.command.dml.Update.update(Update.java:109)
at org.h2.command.CommandContainer.update(CommandContainer.java:98)


Please try attached test. It fails after 10-60 seconds run

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To post to this group, send email to h2-database@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class Bug_H2_4 {

    static String dbUrl = "jdbc:h2:nioMemLZF:db;DB_CLOSE_DELAY=-1;MULTI_THREADED=1;LOCK_TIMEOUT=10000;WRITE_DELAY=500";
    static String user = "sa", pwd = "";
    static int threadCount = 200;

    public static void main(String args[]) throws InterruptedException, SQLException {
        Arte[] artes = new Arte[threadCount];
        Connection dbConnect;
        try {
            Class.forName("org.h2.Driver");
            dbConnect = DriverManager.getConnection(dbUrl, user, pwd);
            DbPreparator.prepareScheme(dbConnect);
            System.out.println("DB scheme prepared");

            DbPreparator.populate(dbConnect);
            System.out.println("DB populated");

            for (int i = 0; i < threadCount; i++) {
                artes[i] = new Arte(DriverManager.getConnection(dbUrl, user, pwd));
            }
            System.out.println("ARTEs created");
        } catch (ClassNotFoundException | SQLException e) {
            System.out.println("DB Connection Failed: " + dbUrl);
            e.printStackTrace();
            return;
        }

        ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
        for (int i = 0; i < threadCount; i++) {
            threadPool.submit(artes[i]);
        }

        while (true) {
            Thread.sleep(100);
        }
    }

    static class DbPreparator {

        public static final int OBJ_CNT = 10000;
        private static final String[] SQLs = new String[]{
            "CREATE TABLE IF NOT EXISTS "
            + "ACCOUNT (\n"
            + "	ID NUMBER(18,0) not null PRIMARY KEY,\n"
            + "	BALANCE NUMBER null,\n"
            + "	CONTRACTID NUMBER(18,0) null,\n"
            + "	NOTES VARCHAR2(4000 char) null)",
            "create index IF NOT EXISTS IDX_ACCOUNT_CONTRACT on ACCOUNT (CONTRACTID asc)",
        };

        public static void prepareScheme(Connection db) throws SQLException {
            for (String sql : SQLs) {
                db.createStatement().execute(sql);
                db.commit();
            }
        }

        public static void populate(Connection db) throws SQLException {
            PreparedStatement mergeAcctStmt = db.prepareStatement("MERGE INTO Account(id, balance) key (id) VALUES (?, ?)");
            for (int i = 0; i < OBJ_CNT; i++) {
                mergeAcctStmt.setLong(1, i);
                mergeAcctStmt.setBigDecimal(2, BigDecimal.ZERO);
                mergeAcctStmt.addBatch();
            }
            mergeAcctStmt.executeBatch();
            db.commit();
        }
    }

    static class Arte implements Callable<Integer> {

        Connection db;
        PreparedStatement updateAcctStmt;

        public Arte(Connection db_) throws SQLException {
            db = db_;
            db.setAutoCommit(false);
            updateAcctStmt = db.prepareStatement("update account set balance = ? where id = ?");
        }

        @Override
        public Integer call() {
            try {
                while (true) {
                    updateAcctStmt.setDouble(1, Math.random());
                    updateAcctStmt.setLong(2, (int) (Math.random() * DbPreparator.OBJ_CNT));
                    updateAcctStmt.execute();
                    Thread.sleep(100);
                    db.commit();
                }
            } catch (SQLException e) {
                System.out.println("DB write error: ");
                e.printStackTrace();
                System.exit(0);
            } catch (InterruptedException ex) {
                System.exit(0);
            }
            return null;
        }
    }

}

Reply via email to