Hello Noel,

Unfortunately I could not reproduce this error on a test bench. It occured 
only once on a production machine under some specific circumstances.
Analysing thread dump I could identify operations that both threads were 
doing when they entered into deadlock:


"Thread-99":

------------


We're inserting 50k+ rows into a table. ConnectionPool is a standard 
org.h2.jdbcx.JdbcConnectionPool.


try(Connection connection = connectionPool.getConnection()) {

connection.setAutoCommit(false);


try(PreparedStatement st = conn.prepareStatement(
        "INSERT INTO mytable (fields...) VALUES (?,?,...)") {
    for (String[] row : data) {
        for (int i = 0; i < row.length; i++) {
            st.setString(i + 1, row[i]);
        }
        st.addBatch();
    }

    st.executeBatch();
}


// WE'VE ENTERED INTO THE DEADLOCK HERE

*connection.commit();*


} catch (SQLException ex ) {

    try {connection.rollback(); } catch (SQLException ex) { /*ignore*/ }

    throw ex;

}



"pool-thread-1":

----------------


We're reading a large resultset (60k+ records) from another table.



try(Connection connection = connectionPool.getConnection()) {

connection.setAutoCommit(false);


try(PreparedStatement st = conn.prepareStatement(
        "SELECT * FROM another_table WHERE conditions") {

    try(ResultSet rs = st.executeQuery()) {

        // WE'VE ENTERED INTO THE DEADLOCK HERE ON rs.next(), probably when 
reading the last row

        white (*rs.next()*) {

            // ... map row...

        }

    }
}

connection.commit();

} catch (SQLException ex ) {

    try {connection.rollback(); } catch (SQLException ex) { /*ignore*/ }

    throw ex;

}



P.S. As I understand with MULTI_THREADED=1 the deadlock probably will gone?


Salu2,
Antón

El miércoles, 13 de diciembre de 2017, 7:59:08 (UTC+1), Noel Grandin 
escribió:
>
> Do you possibly have a test case for this? I can fix it (I think), but I'd 
> really like to add a test case.​
>
> Note to self: the bug is probably in Command.executeUpdate where for 
> multithreaded=false, it needs to lock the session and then the database 
> object
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to