db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kathey Marsden <kmarsdende...@sbcglobal.net>
Subject Should I get an IOException or truncated value if read is interupted by deletion of a row
Date Thu, 02 Aug 2007 23:31:59 GMT
I was trying to force a  IOException to test my fix for DERBY-2933.  To 
do this I am reading from a blobcolumn with getBinaryStream 
(READ_UNCOMMITTED isolation) and delete the row during the read, but 
instead of an IOException, with embedded, I get no error but read only 
32669  bytes of 40000.  With network server I am getting a lock timeout 
but that is apparently another issue.  I think I should get either the 
whole value or an IOException with this scenario. Is that correct?   
Below is my test program.  Just start network server and run.  It will 
run embedded, then network server.

Thanks for the help figuring out how this should behave.

Kathey

*10.1 results*
Embedded:
Read 40000 bytes (OK)
0 rows in BLOBCLOB

Client:
Read 40000 bytes (OK)
0 rows in BLOBCLOB

*10.2 results:*
[C:/kmarsden/repro/DERBY-2933] java TestIOException
Embedded:
Read 32669 bytes  (10.2 regression. Value truncated)
0 rows in BLOBCLOB

Client:
Read 40000 bytes (OK)
0 rows in BLOBCLOB


*10.3 results*

Embedded:
Read 32669 bytes (10.2 regression. value Truncated)
0 rows in BLOBCLOB

Client: (10.3 regression. Shouldn't get a lock timeout for READ_UNCOMMITTED)
Exception in thread "main" java.sql.SQLException: A lock could not be 
obtained within the time requested
        at 
org.apache.derby.client.am.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:46)
        at 
org.apache.derby.client.am.SqlException.getSQLException(SqlException.java:362)
        at 
org.apache.derby.client.am.Statement.executeUpdate(Statement.java:440)
        at 
TestIOException.testInteruptRead(TestIOException.java(Compiled Code))
        at TestIOException.main(TestIOException.java:22)


import java.sql.*;
import java.io.*;


public class TestIOException {

    public static void main(String[] args) throws Exception{

    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
    Connection conn = 
DriverManager.getConnection("jdbc:derby:wombat;create=true");
    Connection conn2 = DriverManager.getConnection("jdbc:derby:wombat");
    setupTable(conn);
    testInteruptRead(conn, conn2);
    conn.close();
    conn2.close();


    Class.forName("org.apache.derby.jdbc.ClientDriver");
    conn = 
DriverManager.getConnection("jdbc:derby://localhost:1527/wombatns;create=true");
     conn2 = 
DriverManager.getConnection("jdbc:derby://localhost:1527/wombatns");
    setupTable(conn);
    testInteruptRead(conn, conn2);
    conn.close();
    conn2.close();
    }

    public static void setupTable(Connection conn) throws SQLException
    {
    Statement s = conn.createStatement();
    try {
        s.executeUpdate("DROP TABLE BLOBTAB");
    } catch (SQLException se) {}

    s.executeUpdate("CREATE TABLE BLOBTAB (B BLOB(2M))");
    PreparedStatement ps = conn.prepareStatement("INSERT INTO BLOBTAB 
VALUES ?");
    byte[] bytes = new byte[40000];
    ps.setBytes(1,bytes);
    ps.executeUpdate();
    s.close();
    ps.close();
    }
    
    public static void testInteruptRead(Connection conn, Connection 
conn2) throws SQLException, IOException
    {
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    Statement s = conn.createStatement();
    Statement s2 = conn2.createStatement();
    ResultSet rs = s.executeQuery("SELECT B FROM BLOBTAB");
    rs.next();
    InputStream is = rs.getBinaryStream(1);
    int i = is.read();
    // now rudely interupt with connection 2 deleting the row;
    s2.executeUpdate("delete from blobtab");
    // now try to read from the input stream again
    try {
        int count = 1;
        while (i != -1) {
        count++;
        i = is.read();
        }
        System.out.println("Read " + count + " bytes");
    } catch (IOException ioe) {
        System.out.println("Caught IOException:" + ioe.getMessage());
    }
    // check connection make sure it is still ok.
    rs = s.executeQuery("SELECT COUNT(*) from BLOBTAB");
    rs.next();
    System.out.println(rs.getString(1) + " rows in BLOBCLOB");
    }
}



Mime
View raw message