Re: Error on failed COMMIT

From: Dave Cramer <davecramer(at)postgres(dot)rocks>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Shay Rojansky <roji(at)roji(dot)org>, "Haumacher, Bernhard" <haui(at)haumacher(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Error on failed COMMIT
Date: 2020-02-24 13:21:48
Message-ID: CADK3HHLa1NXEFosiSe=-Kg4aMdnJ-wLgkZdXA2zEP=pw8Njcgw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

If we did change the server behavior, it seems unlikely that
> every driver would adjust their behavior to the new server behavior
> all at once and that they would all get it right while also all
> preserving backward compatibility with current releases in case a
> newer driver is used with an older server. I don't think that's
> likely. What would probably happen is that many drivers would ignore
> the change, leaving applications to cope with the differences between
> server versions, and some would change the driver behavior
> categorically, breaking compatibility with older server versions, and
> some would make mistakes in implementing support for the new behavior.
> And maybe we would also find that the new behavior isn't ideal for
> everybody any more than the current behavior is ideal for everybody.
>

To test how the driver would currently react if the server did respond with
an error I made a small change

diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 0a6f80963b..9405b0cfd9 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -2666,8 +2666,7 @@ IsTransactionExitStmt(Node *parsetree)
{
TransactionStmt *stmt = (TransactionStmt *) parsetree;

- if (stmt->kind == TRANS_STMT_COMMIT ||
- stmt->kind == TRANS_STMT_PREPARE ||
+ if (stmt->kind == TRANS_STMT_PREPARE ||
stmt->kind == TRANS_STMT_ROLLBACK ||
stmt->kind == TRANS_STMT_ROLLBACK_TO)
return true;

I have no idea how badly this breaks other things but it does throw an
error on commit if the transaction is in error.
With absolutely no changes to the driver this code does what I would expect
and executes the conn.rollback()

try {
conn.setAutoCommit(false);
try {
conn.createStatement().execute("insert into notnullable values (NULL)");
} catch (SQLException ex ) {
ex.printStackTrace();
//ignore this exception
}
conn.commit();
} catch ( SQLException ex ) {
ex.printStackTrace();
conn.rollback();
}
conn.close();

Dave Cramer

http://www.postgres.rocks

>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Shay Rojansky 2020-02-24 13:24:19 Re: Error on failed COMMIT
Previous Message Dave Cramer 2020-02-24 13:16:11 Re: Error on failed COMMIT