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

Commit 3498d87

Browse files
committed
SET TRANSACTION ISOLATION LEVEL ...
LOCK TABLE IN ... MODE ...implemented
1 parent c7da80b commit 3498d87

File tree

19 files changed

+6453
-6016
lines changed

19 files changed

+6453
-6016
lines changed

src/backend/access/transam/varsup.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.17 1998/09/01 04:27:18 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.18 1998/12/18 09:10:17 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -311,6 +311,42 @@ GetNewTransactionId(TransactionId *xid)
311311
SpinRelease(OidGenLockId);
312312
}
313313

314+
/*
315+
* Like GetNewTransactionId reads nextXid but don't fetch it.
316+
*/
317+
void
318+
ReadNewTransactionId(TransactionId *xid)
319+
{
320+
321+
/* ----------------
322+
* during bootstrap initialization, we return the special
323+
* bootstrap transaction id.
324+
* ----------------
325+
*/
326+
if (AMI_OVERRIDE)
327+
{
328+
TransactionIdStore(AmiTransactionId, xid);
329+
return;
330+
}
331+
332+
SpinAcquire(OidGenLockId); /* not good for concurrency... */
333+
334+
if (ShmemVariableCache->xid_count == 0)
335+
{
336+
TransactionId nextid;
337+
338+
VariableRelationGetNextXid(&nextid);
339+
TransactionIdStore(nextid, &(ShmemVariableCache->nextXid));
340+
ShmemVariableCache->xid_count = VAR_XID_PREFETCH;
341+
TransactionIdAdd(&nextid, VAR_XID_PREFETCH);
342+
VariableRelationPutNextXid(nextid);
343+
}
344+
345+
TransactionIdStore(ShmemVariableCache->nextXid, xid);
346+
347+
SpinRelease(OidGenLockId);
348+
}
349+
314350
/* ----------------------------------------------------------------
315351
* object id generation support
316352
* ----------------------------------------------------------------

src/backend/access/transam/xact.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.27 1998/12/16 11:53:44 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.28 1998/12/18 09:10:18 vadim Exp $
1111
*
1212
* NOTES
1313
* Transaction aborts can now occur two ways:
@@ -194,7 +194,8 @@ TransactionStateData CurrentTransactionStateData = {
194194
TransactionState CurrentTransactionState =
195195
&CurrentTransactionStateData;
196196

197-
int XactIsoLevel = XACT_SERIALIZED;
197+
int DefaultXactIsoLevel = XACT_SERIALIZABLE;
198+
int XactIsoLevel;
198199

199200
/* ----------------
200201
* info returned when the system is disabled
@@ -798,6 +799,7 @@ StartTransaction()
798799

799800
TransactionIdFlushCache();
800801
FreeXactSnapshot();
802+
XactIsoLevel = DefaultXactIsoLevel;
801803

802804
/* ----------------
803805
* Check the current transaction state. If the transaction system

src/backend/commands/command.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.34 1998/12/15 12:45:52 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.35 1998/12/18 09:10:18 vadim Exp $
1111
*
1212
* NOTES
1313
* The PortalExecutorHeapMemory crap needs to be eliminated
@@ -39,6 +39,7 @@
3939
#include "utils/mcxt.h"
4040
#include "utils/portal.h"
4141
#include "utils/syscache.h"
42+
#include "miscadmin.h"
4243

4344
/* ----------------
4445
* PortalExecutorHeapMemory stuff
@@ -492,3 +493,25 @@ PerformAddAttribute(char *relationName,
492493
pfree(reltup);
493494
heap_close(rel);
494495
}
496+
497+
void
498+
LockTableCommand(LockStmt *lockstmt)
499+
{
500+
Relation rel;
501+
int aclresult;
502+
503+
rel = heap_openr(lockstmt->relname);
504+
if (rel == NULL)
505+
elog(ERROR, "LOCK TABLE: relation %s can't be openned", lockstmt->relname);
506+
507+
if (lockstmt->mode == AccessShareLock)
508+
aclresult = pg_aclcheck(lockstmt->relname, GetPgUserName(), ACL_RD);
509+
else
510+
aclresult = pg_aclcheck(lockstmt->relname, GetPgUserName(), ACL_WR);
511+
512+
if (aclresult != ACLCHECK_OK)
513+
elog(ERROR, "LOCK TABLE: permission denied");
514+
515+
LockRelation(rel, lockstmt->mode);
516+
517+
}

src/backend/commands/trigger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@ GetTupleForTrigger(EState *estate, ItemPointer tid, bool before)
818818

819819
case HeapTupleUpdated:
820820
ReleaseBuffer(buffer);
821-
if (XactIsoLevel == XACT_SERIALIZED)
822-
elog(ERROR, "Serialize access failed due to concurrent update");
821+
if (XactIsoLevel == XACT_SERIALIZABLE)
822+
elog(ERROR, "Can't serialize access due to concurrent update");
823823
else
824824
elog(ERROR, "Isolation level %u is not supported", XactIsoLevel);
825825
return(NULL);

src/backend/commands/variable.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Routines for handling of 'SET var TO',
33
* 'SHOW var' and 'RESET var' statements.
44
*
5-
* $Id: variable.c,v 1.17 1998/10/26 00:59:22 tgl Exp $
5+
* $Id: variable.c,v 1.18 1998/12/18 09:10:20 vadim Exp $
66
*
77
*/
88

@@ -15,6 +15,7 @@
1515
#include "commands/variable.h"
1616
#include "utils/builtins.h"
1717
#include "optimizer/internal.h"
18+
#include "access/xact.h"
1819
#ifdef MULTIBYTE
1920
#include "mb/pg_wchar.h"
2021
#endif
@@ -44,6 +45,9 @@ static bool parse_geqo(const char *);
4445
static bool show_ksqo(void);
4546
static bool reset_ksqo(void);
4647
static bool parse_ksqo(const char *);
48+
static bool show_XactIsoLevel(void);
49+
static bool reset_XactIsoLevel(void);
50+
static bool parse_XactIsoLevel(const char *);
4751
#ifdef QUERY_LIMIT
4852
static bool show_query_limit(void);
4953
static bool reset_query_limit(void);
@@ -669,6 +673,9 @@ struct VariableParsers
669673
{
670674
"ksqo", parse_ksqo, show_ksqo, reset_ksqo
671675
},
676+
{
677+
"XactIsoLevel", parse_XactIsoLevel, show_XactIsoLevel, reset_XactIsoLevel
678+
},
672679
#ifdef QUERY_LIMIT
673680
{
674681
"query_limit", parse_query_limit, show_query_limit, reset_query_limit
@@ -773,3 +780,58 @@ reset_ksqo()
773780
_use_keyset_query_optimizer = false;
774781
return TRUE;
775782
}
783+
784+
/* SET TRANSACTION */
785+
786+
static bool
787+
parse_XactIsoLevel(const char *value)
788+
{
789+
790+
if (value == NULL)
791+
{
792+
reset_XactIsoLevel();
793+
return TRUE;
794+
}
795+
796+
if (SerializableSnapshot != NULL)
797+
{
798+
elog(ERROR, "SET TRANSACTION ISOLATION LEVEL must be called before any query");
799+
return TRUE;
800+
}
801+
802+
803+
if (strcasecmp(value, "SERIALIZABLE") == 0)
804+
XactIsoLevel = XACT_SERIALIZABLE;
805+
else if (strcasecmp(value, "COMMITTED") == 0)
806+
XactIsoLevel = XACT_READ_COMMITTED;
807+
else
808+
elog(ERROR, "Bad TRANSACTION ISOLATION LEVEL (%s)", value);
809+
810+
return TRUE;
811+
}
812+
813+
static bool
814+
show_XactIsoLevel()
815+
{
816+
817+
if (XactIsoLevel == XACT_SERIALIZABLE)
818+
elog(NOTICE, "TRANSACTION ISOLATION LEVEL is SERIALIZABLE");
819+
else
820+
elog(NOTICE, "TRANSACTION ISOLATION LEVEL is READ COMMITTED");
821+
return TRUE;
822+
}
823+
824+
static bool
825+
reset_XactIsoLevel()
826+
{
827+
828+
if (SerializableSnapshot != NULL)
829+
{
830+
elog(ERROR, "SET TRANSACTION ISOLATION LEVEL must be called before any query");
831+
return TRUE;
832+
}
833+
834+
XactIsoLevel = DefaultXactIsoLevel;
835+
836+
return TRUE;
837+
}

src/backend/executor/execMain.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.61 1998/12/16 11:53:45 vadim Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.62 1998/12/18 09:10:21 vadim Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -1037,8 +1037,8 @@ ExecDelete(TupleTableSlot *slot,
10371037
break;
10381038

10391039
case HeapTupleUpdated:
1040-
if (XactIsoLevel == XACT_SERIALIZED)
1041-
elog(ERROR, "Serialize access failed due to concurrent update");
1040+
if (XactIsoLevel == XACT_SERIALIZABLE)
1041+
elog(ERROR, "Can't serialize access due to concurrent update");
10421042
else
10431043
elog(ERROR, "Isolation level %u is not supported", XactIsoLevel);
10441044
return;
@@ -1167,8 +1167,8 @@ ExecReplace(TupleTableSlot *slot,
11671167
break;
11681168

11691169
case HeapTupleUpdated:
1170-
if (XactIsoLevel == XACT_SERIALIZED)
1171-
elog(ERROR, "Serialize access failed due to concurrent update");
1170+
if (XactIsoLevel == XACT_SERIALIZABLE)
1171+
elog(ERROR, "Can't serialize access due to concurrent update");
11721172
else
11731173
elog(ERROR, "Isolation level %u is not supported", XactIsoLevel);
11741174
return;

0 commit comments

Comments
 (0)