Apologies for over-quoting on the previous message.

My approach to a regression test was this single-threaded test ( actual code at 
bottom ) 

        Connection 1 - implicitly autocommiting every statement
                create a test table and populate it with a single row. 
                        CREATE TABLE FOO ( a int not null );
                        INSERT INTO FOO VALUES (1);
                set the connection autocommit to false ( implied transaction 
begin on next statement )
                read 
                        SELECT * FROM FOO;
                modify
                        UPDATE FOO SET a=a+1;
                ( transaction is still open )
        Connection 2
                set the connection autocommit to false
                read
                        SELECT * FROM FOO;
        Connection 1
                commit;
        Connection 2
                modify
                        UPDATE FOO SET a=a+1
                throws concurrent serialization error
        Connection 3
                do a bunch of catalog updates
                        for f in 1..??? ( i tried 1, 10, 100, and 4096 )
                                CREATE TEMP TABLE BAR$f (a int not null );
        Connection 2
                rollback <- I am expecting a server crash here. It does not 
crash.



My guess is that I am not provoking a 'SI queue overrun' 
( I am assuming this is a reference to the queue implemented in sinvaladt.c. My 
C skills are rusty at best. )

Am I completely off base about how this should be reproducing?


Bug5269Test.java

import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/* Regression test for PostgreSQL Bug # 5269 
 * http://archives.postgresql.org/pgsql-bugs/2010-01/msg00080.php 
 * */

public class Bug5269Test {

        private Connection newConnection(Driver driver) {
                Properties info = new Properties();
                info.put("user", "postgres");
                try {
                        return 
driver.connect("jdbc:postgresql://localhost:5433", info);
                } catch (SQLException e) {
                        e.printStackTrace();
                }
                return null;
        }

        public void test() throws SQLException, InterruptedException {
                Driver driver = new org.postgresql.Driver();
                Connection a = newConnection(driver);
                setupTable(a);

                Connection b = newConnection(driver);
                a.setAutoCommit(false);
                a.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
                b.setAutoCommit(false);
                b.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);

                String select = "select * from foo";
                String update = "update foo set a = a + 1";

                a.prepareStatement(select).execute();
                System.out.println("select a");

                a.prepareStatement(update).execute();
                System.out.println("update a");

                b.prepareStatement(select).execute();
                System.out.println("select b");

                a.commit();
                System.out.println("commit a");
                try {
                        b.prepareStatement(update).execute();
                        b.commit();
                        throw new RuntimeException("Expected a serialization 
failure.");
                } catch (SQLException sqle) {
                        System.out.println(sqle.getMessage());
                        flogCatalogs(driver);
                        System.out.println("flog catalogs");

                        // The hope is that an unpatched system would crash 
here.
                        b.rollback();
                        System.out.println("rollback.");
                }
                a.close();
                b.close();
        }

        private void setupTable(Connection a) throws SQLException {
                try {
                        a.prepareStatement("drop table foo").execute();
                } catch (Exception e) {
                        e.printStackTrace();
                }
                a.prepareStatement("create table foo(a int not 
null)").executeUpdate();
                a.prepareStatement("insert into foo values 
(1);").executeUpdate();
        }

        private void flogCatalogs(final Driver driver) throws SQLException {
                final Connection conn = newConnection(driver);
                try {
                        conn.setAutoCommit(false);
                        Statement ps = conn.createStatement();
                        String a = "create temp table bar";
                        String b = " (a int not null); ";
                        for (int f = 0; f < 128; f++) {
                                StringBuilder sb = new StringBuilder();
                                sb.append(a).append(f).append(b);
                                ps.execute(sb.toString());
                        }
                        conn.commit();
                } catch (SQLException e) {
                        e.printStackTrace();
                } finally {
                        try {
                                conn.close();
                        } catch (SQLException e) {
                                e.printStackTrace();
                        }
                }
        }

        public static void main(String... args) throws SQLException,
                        InterruptedException {
                Bug5269Test test = new Bug5269Test();
                test.test();
        }

}



On Jan 13, 2010, at 10:22 PM, Justin Pitts wrote:

> Sorry for the delay.
> 
> I am attempting to construct a JDBC test case that reproduces the problem. 
> 
> I have installed the patch and have not seen the crash since.
> 
> On Jan 13, 2010, at 11:58 AM, Tom Lane wrote:
> 


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to