Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 90b2202

Browse files
committed
Fix bad interaction between NOTIFY processing and V3 extended query
protocol, per report from Igor Shevchenko. NOTIFY thought it could do its thing if transaction blockState is TBLOCK_DEFAULT, but in reality it had better check the low-level transaction state is TRANS_DEFAULT as well. Formerly it was not possible to wait for the client in a state where the first is true and the second is not ... but now we can have such a state. Minor cleanup in StartTransaction() as well.
1 parent 839cea8 commit 90b2202

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

src/backend/access/transam/xact.c

+30-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.155 2003/09/28 23:26:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.156 2003/10/16 16:50:41 tgl Exp $
1212
*
1313
* NOTES
1414
* Transaction aborts can now occur two ways:
@@ -202,7 +202,7 @@ static TransactionStateData CurrentTransactionStateData = {
202202
* perspective */
203203
};
204204

205-
TransactionState CurrentTransactionState = &CurrentTransactionStateData;
205+
static TransactionState CurrentTransactionState = &CurrentTransactionStateData;
206206

207207
/*
208208
* User-tweakable parameters
@@ -826,27 +826,25 @@ StartTransaction(void)
826826
{
827827
TransactionState s = CurrentTransactionState;
828828

829-
FreeXactSnapshot();
830-
XactIsoLevel = DefaultXactIsoLevel;
831-
XactReadOnly = DefaultXactReadOnly;
832-
833829
/*
834-
* Check the current transaction state. If the transaction system is
835-
* switched off, or if we're already in a transaction, do nothing.
836-
* We're already in a transaction when the monitor sends a null
837-
* command to the backend to flush the comm channel. This is a hacky
838-
* fix to a communications problem, and we keep having to deal with it
839-
* here. We should fix the comm channel code. mao 080891
830+
* check the current transaction state
840831
*/
841-
if (s->state == TRANS_INPROGRESS)
842-
return;
832+
if (s->state != TRANS_DEFAULT)
833+
elog(WARNING, "StartTransaction and not in default state");
843834

844835
/*
845836
* set the current transaction state information appropriately during
846837
* start processing
847838
*/
848839
s->state = TRANS_START;
849840

841+
/*
842+
* Make sure we've freed any old snapshot, and reset xact state variables
843+
*/
844+
FreeXactSnapshot();
845+
XactIsoLevel = DefaultXactIsoLevel;
846+
XactReadOnly = DefaultXactReadOnly;
847+
850848
/*
851849
* generate a new transaction id
852850
*/
@@ -1725,6 +1723,24 @@ IsTransactionBlock(void)
17251723
return true;
17261724
}
17271725

1726+
/*
1727+
* IsTransactionOrTransactionBlock --- are we within either a transaction
1728+
* or a transaction block? (The backend is only really "idle" when this
1729+
* returns false.)
1730+
*
1731+
* This should match up with IsTransactionBlock and IsTransactionState.
1732+
*/
1733+
bool
1734+
IsTransactionOrTransactionBlock(void)
1735+
{
1736+
TransactionState s = CurrentTransactionState;
1737+
1738+
if (s->blockState == TBLOCK_DEFAULT && s->state == TRANS_DEFAULT)
1739+
return false;
1740+
1741+
return true;
1742+
}
1743+
17281744
/*
17291745
* TransactionBlockStatusCode - return status code to send in ReadyForQuery
17301746
*/

src/backend/commands/async.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.101 2003/10/01 21:30:52 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.102 2003/10/16 16:50:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -91,10 +91,6 @@
9191
#include "utils/syscache.h"
9292

9393

94-
/* stuff that we really ought not be touching directly :-( */
95-
extern TransactionState CurrentTransactionState;
96-
97-
9894
/*
9995
* State for outbound notifies consists of a list of all relnames NOTIFYed
10096
* in the current transaction. We do not actually perform a NOTIFY until
@@ -717,7 +713,7 @@ Async_NotifyHandler(SIGNAL_ARGS)
717713
void
718714
EnableNotifyInterrupt(void)
719715
{
720-
if (CurrentTransactionState->blockState != TRANS_DEFAULT)
716+
if (IsTransactionOrTransactionBlock())
721717
return; /* not really idle */
722718

723719
/*

src/backend/tcop/postgres.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.372 2003/10/09 02:40:18 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.373 2003/10/16 16:50:41 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -2660,7 +2660,7 @@ PostgresMain(int argc, char *argv[], const char *username)
26602660
if (!IsUnderPostmaster)
26612661
{
26622662
puts("\nPOSTGRES backend interactive interface ");
2663-
puts("$Revision: 1.372 $ $Date: 2003/10/09 02:40:18 $\n");
2663+
puts("$Revision: 1.373 $ $Date: 2003/10/16 16:50:41 $\n");
26642664
}
26652665

26662666
/*
@@ -2796,7 +2796,7 @@ PostgresMain(int argc, char *argv[], const char *username)
27962796
{
27972797
pgstat_report_tabstat();
27982798

2799-
if (IsTransactionBlock())
2799+
if (IsTransactionOrTransactionBlock())
28002800
{
28012801
set_ps_display("idle in transaction");
28022802
pgstat_report_activity("<IDLE> in transaction");

src/include/access/xact.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: xact.h,v 1.56 2003/09/28 23:26:20 tgl Exp $
10+
* $Id: xact.h,v 1.57 2003/10/16 16:50:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -129,6 +129,7 @@ extern void AbortCurrentTransaction(void);
129129
extern void BeginTransactionBlock(void);
130130
extern void EndTransactionBlock(void);
131131
extern bool IsTransactionBlock(void);
132+
extern bool IsTransactionOrTransactionBlock(void);
132133
extern char TransactionBlockStatusCode(void);
133134
extern void UserAbortTransactionBlock(void);
134135
extern void AbortOutOfAnyTransaction(void);

0 commit comments

Comments
 (0)