Commit a2597ef1 authored by Tom Lane's avatar Tom Lane

Modify sequence state storage to eliminate dangling-pointer problem

exemplified by bug #671.  Moving the storage to relcache turned out to
be a bad idea because relcache might decide to discard the info.  Instead,
open and close the relcache entry on each sequence operation, and use
a record of the current XID to discover whether we already hold
AccessShareLock on the sequence.
parent b8ffc996
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.123 2002/05/21 22:05:53 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.124 2002/05/22 21:40:55 tgl Exp $
* *
* NOTES * NOTES
* Transaction aborts can now occur two ways: * Transaction aborts can now occur two ways:
...@@ -166,7 +166,6 @@ ...@@ -166,7 +166,6 @@
#include "catalog/index.h" #include "catalog/index.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "commands/async.h" #include "commands/async.h"
#include "commands/sequence.h"
#include "commands/trigger.h" #include "commands/trigger.h"
#include "executor/spi.h" #include "executor/spi.h"
#include "libpq/be-fsstubs.h" #include "libpq/be-fsstubs.h"
...@@ -947,7 +946,6 @@ CommitTransaction(void) ...@@ -947,7 +946,6 @@ CommitTransaction(void)
/* NOTIFY commit must also come before lower-level cleanup */ /* NOTIFY commit must also come before lower-level cleanup */
AtCommit_Notify(); AtCommit_Notify();
CloseSequences();
AtEOXact_portals(); AtEOXact_portals();
/* Here is where we really truly commit. */ /* Here is where we really truly commit. */
...@@ -1063,7 +1061,6 @@ AbortTransaction(void) ...@@ -1063,7 +1061,6 @@ AbortTransaction(void)
DeferredTriggerAbortXact(); DeferredTriggerAbortXact();
lo_commit(false); /* 'false' means it's abort */ lo_commit(false); /* 'false' means it's abort */
AtAbort_Notify(); AtAbort_Notify();
CloseSequences();
AtEOXact_portals(); AtEOXact_portals();
/* Advertise the fact that we aborted in pg_clog. */ /* Advertise the fact that we aborted in pg_clog. */
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.76 2002/04/15 05:22:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.77 2002/05/22 21:40:55 tgl Exp $
* *
* DESCRIPTION * DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the * The "DefineFoo" routines take the parse tree and pick out the
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "commands/defrem.h" #include "commands/defrem.h"
#include "parser/parse_type.h" #include "parser/parse_type.h"
#include "utils/int8.h"
/* /*
...@@ -114,6 +115,34 @@ defGetNumeric(DefElem *def) ...@@ -114,6 +115,34 @@ defGetNumeric(DefElem *def)
return 0; /* keep compiler quiet */ return 0; /* keep compiler quiet */
} }
/*
* Extract an int64 value from a DefElem.
*/
int64
defGetInt64(DefElem *def)
{
if (def->arg == NULL)
elog(ERROR, "Define: \"%s\" requires a numeric value",
def->defname);
switch (nodeTag(def->arg))
{
case T_Integer:
return (int64) intVal(def->arg);
case T_Float:
/*
* Values too large for int4 will be represented as Float
* constants by the lexer. Accept these if they are valid int8
* strings.
*/
return DatumGetInt64(DirectFunctionCall1(int8in,
CStringGetDatum(strVal(def->arg))));
default:
elog(ERROR, "Define: \"%s\" requires a numeric value",
def->defname);
}
return 0; /* keep compiler quiet */
}
/* /*
* Extract a possibly-qualified name (as a List of Strings) from a DefElem. * Extract a possibly-qualified name (as a List of Strings) from a DefElem.
*/ */
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: defrem.h,v 1.37 2002/05/17 18:32:52 petere Exp $ * $Id: defrem.h,v 1.38 2002/05/22 21:40:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -54,12 +54,13 @@ extern void DefineDomain(CreateDomainStmt *stmt); ...@@ -54,12 +54,13 @@ extern void DefineDomain(CreateDomainStmt *stmt);
extern void RemoveDomain(List *names, int behavior); extern void RemoveDomain(List *names, int behavior);
/* support routines in define.c */ /* support routines in commands/define.c */
extern void case_translate_language_name(const char *input, char *output); extern void case_translate_language_name(const char *input, char *output);
extern char *defGetString(DefElem *def); extern char *defGetString(DefElem *def);
extern double defGetNumeric(DefElem *def); extern double defGetNumeric(DefElem *def);
extern int64 defGetInt64(DefElem *def);
extern List *defGetQualifiedName(DefElem *def); extern List *defGetQualifiedName(DefElem *def);
extern TypeName *defGetTypeName(DefElem *def); extern TypeName *defGetTypeName(DefElem *def);
extern int defGetTypeLength(DefElem *def); extern int defGetTypeLength(DefElem *def);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: sequence.h,v 1.19 2001/11/05 17:46:33 momjian Exp $ * $Id: sequence.h,v 1.20 2002/05/22 21:40:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -84,7 +84,6 @@ extern Datum setval(PG_FUNCTION_ARGS); ...@@ -84,7 +84,6 @@ extern Datum setval(PG_FUNCTION_ARGS);
extern Datum setval_and_iscalled(PG_FUNCTION_ARGS); extern Datum setval_and_iscalled(PG_FUNCTION_ARGS);
extern void DefineSequence(CreateSeqStmt *stmt); extern void DefineSequence(CreateSeqStmt *stmt);
extern void CloseSequences(void);
extern void seq_redo(XLogRecPtr lsn, XLogRecord *rptr); extern void seq_redo(XLogRecPtr lsn, XLogRecord *rptr);
extern void seq_undo(XLogRecPtr lsn, XLogRecord *rptr); extern void seq_undo(XLogRecPtr lsn, XLogRecord *rptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment