Subject | Re: [Firebird-Java] Deadlock question |
---|---|
Author | Roman Rokytskyy |
Post date | 2005-09-30T16:16:12Z |
> b) You use READ COMMITTED isolation with NO_REC_VERSION and NOWAITHere's an example to reproduce the issue (though a message is a bit
> transaction parameters. Then, if there is an uncommitted version for the
> record being currently fetched, an error is returned.
different)
public void testLockConflictOnNoWaitTransaction() throws Exception {
FirebirdConnection connection1 = (FirebirdConnection)
getConnectionViaDriverManager();
try {
PreparedStatement ps =
connection1.prepareStatement(INSERT_DATA);
try {
ps.setInt(1, 1);
ps.execute();
} finally {
ps.close();
}
connection1.setAutoCommit(false);
FirebirdConnection connection2 = (FirebirdConnection)
getConnectionViaDriverManager();
connection2.setAutoCommit(false);
try {
TransactionParameterBuffer tpb =
connection2.createTransactionParameterBuffer();
tpb.addArgument(TransactionParameterBuffer.READ_COMMITTED);
tpb.addArgument(TransactionParameterBuffer.NO_REC_VERSION);
tpb.addArgument(TransactionParameterBuffer.WRITE);
tpb.addArgument(TransactionParameterBuffer.WAIT);
connection2.setTransactionParameters(tpb);
// start Tx2, but do not touch the table
Statement stmt2 = connection2.createStatement();
try {
ResultSet rs2 = stmt2.executeQuery(
"SELECT * FROM rdb$database");
rs2.close();
// start Tx1 and update the table
Statement stmt1 = connection1.createStatement();
try {
stmt1.execute("UPDATE test SET col1 = col1 + 1");
} finally {
stmt1.close();
}
rs2 = stmt2.executeQuery("SELECT * FROM test");
while(rs2.next())
System.out.println(rs2.getInt(1));
} finally {
stmt2.close();
}
} finally {
connection2.close();
}
} finally {
connection1.close();
}
}
It produces error:
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544345. lock conflict
on no wait transaction
deadlock
at
org.firebirdsql.jdbc.FBStatementFetcher.fetch(FBStatementFetcher.java:206)
at
org.firebirdsql.jdbc.FBStatementFetcher.next(FBStatementFetcher.java:119)
at org.firebirdsql.jdbc.FBResultSet.next(FBResultSet.java:250)
at
org.firebirdsql.jdbc.TestFBConnection.testLockConflictOnNoWaitTransaction(TestFBConnection.java:391)
Roman