Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc13a64d

Browse files
committed
Serialized mode works!
1 parent54c3e65 commitc13a64d

File tree

9 files changed

+209
-47
lines changed

9 files changed

+209
-47
lines changed

‎src/backend/access/transam/transam.c

Lines changed: 9 additions & 19 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/transam.c,v 1.20 1998/12/15 12:45:30 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.21 1998/12/16 11:53:44 vadim Exp $
1111
*
1212
* NOTES
1313
* This file contains the high level access-method interface to the
@@ -172,12 +172,8 @@ TransactionLogTest(TransactionId transactionId, /* transaction id to test */
172172

173173
if (!fail)
174174
{
175-
/* must not cache status of running xaction !!! */
176-
if (xidstatus!=XID_INPROGRESS)
177-
{
178-
TransactionIdStore(transactionId,&cachedTestXid);
179-
cachedTestXidStatus=xidstatus;
180-
}
175+
TransactionIdStore(transactionId,&cachedTestXid);
176+
cachedTestXidStatus=xidstatus;
181177
return (bool)
182178
(status==xidstatus);
183179
}
@@ -230,11 +226,8 @@ TransactionLogUpdate(TransactionId transactionId,/* trans id to update */
230226
*
231227
* What's the hell ?! Why != XID_COMMIT ?!
232228
*/
233-
if (status!=XID_INPROGRESS)
234-
{
235-
TransactionIdStore(transactionId,&cachedTestXid);
236-
cachedTestXidStatus=status;
237-
}
229+
TransactionIdStore(transactionId,&cachedTestXid);
230+
cachedTestXidStatus=status;
238231

239232
}
240233

@@ -588,14 +581,11 @@ TransactionIdAbort(TransactionId transactionId)
588581
TransactionLogUpdate(transactionId,XID_ABORT);
589582
}
590583

591-
#ifdefNOT_USED
592584
void
593-
TransactionIdSetInProgress(TransactionIdtransactionId)
585+
TransactionIdFlushCache()
594586
{
595-
if (AMI_OVERRIDE)
596-
return;
597587

598-
TransactionLogUpdate(transactionId,XID_INPROGRESS);
599-
}
588+
TransactionIdStore(AmiTransactionId,&cachedTestXid);
589+
cachedTestXidStatus=XID_COMMIT;
600590

601-
#endif
591+
}

‎src/backend/access/transam/xact.c

Lines changed: 7 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/xact.c,v 1.26 1998/12/15 12:45:35 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.27 1998/12/16 11:53:44 vadim Exp $
1111
*
1212
* NOTES
1313
*Transaction aborts can now occur two ways:
@@ -516,6 +516,9 @@ CommandCounterIncrement()
516516
/* make cache changes visible to me */
517517
AtCommit_Cache();
518518
AtStart_Cache();
519+
520+
TransactionIdFlushCache();
521+
519522
}
520523

521524
void
@@ -793,6 +796,9 @@ StartTransaction()
793796
{
794797
TransactionStates=CurrentTransactionState;
795798

799+
TransactionIdFlushCache();
800+
FreeXactSnapshot();
801+
796802
/* ----------------
797803
*Check the current transaction state. If the transaction system
798804
*is switched off, or if we're already in a transaction, do nothing.

‎src/backend/executor/execMain.c

Lines changed: 2 additions & 2 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.60 1998/12/15 12:46:04 vadim Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.61 1998/12/16 11:53:45 vadim Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -124,7 +124,7 @@ ExecutorStart(QueryDesc *queryDesc, EState *estate)
124124
memset(estate->es_param_exec_vals,0,queryDesc->plantree->nParamExec*sizeof(ParamExecData));
125125
}
126126

127-
estate->es_snapshot=SnapshotNow;
127+
estate->es_snapshot=QuerySnapshot;
128128

129129
result=InitPlan(queryDesc->operation,
130130
queryDesc->parsetree,

‎src/backend/storage/ipc/shmem.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.32 1998/12/15 12:46:24 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.33 1998/12/16 11:53:46 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -633,27 +633,21 @@ TransactionIdIsInProgress(TransactionId xid)
633633
/*
634634
* GetSnapshotData -- returns information about running transactions.
635635
*
636-
* InvalidTransactionId is used as terminator in snapshot->xip array.
637-
* If serialized is true then XID >= current xact ID will not be
638-
* placed in array. Current xact ID are never placed there (just
639-
* to reduce its length, xmin/xmax may be equal to cid).
640-
* MyProc->xmin will be setted if equal to InvalidTransactionId.
641-
*
642636
* Yet another strange func for this place...- vadim 07/21/98
643637
*/
644638
Snapshot
645-
GetSnapshotData(boolserialized)
639+
GetSnapshotData(void)
646640
{
647641
Snapshotsnapshot= (Snapshot)malloc(sizeof(SnapshotData));
648642
ShmemIndexEnt*result;
649643
PROC*proc;
650644
TransactionIdcid=GetCurrentTransactionId();
651645
uint32count=0;
652-
uint32have=31;
646+
uint32have=32;
653647

654648
Assert(ShmemIndex);
655649

656-
snapshot->xip= (TransactionId*)malloc(32*sizeof(TransactionId));
650+
snapshot->xip= (TransactionId*)malloc(have*sizeof(TransactionId));
657651
snapshot->xmax=cid;
658652
snapshot->xmin=cid;
659653

@@ -667,15 +661,14 @@ GetSnapshotData(bool serialized)
667661
if (MyProc->xmin==InvalidTransactionId)
668662
MyProc->xmin=snapshot->xmin;
669663
SpinRelease(ShmemIndexLock);
670-
snapshot->xip[count]=InvalidTransactionId;
664+
snapshot->xcnt=count;
671665
returnsnapshot;
672666
}
673667
if (result->location==INVALID_OFFSET||
674668
strncmp(result->key,"PID ",4)!=0)
675669
continue;
676670
proc= (PROC*)MAKE_PTR(result->location);
677-
if (proc==MyProc||proc->xid<FirstTransactionId||
678-
(serialized&&proc->xid >=cid))
671+
if (proc==MyProc||proc->xid<FirstTransactionId)
679672
continue;
680673
if (proc->xid<snapshot->xmin)
681674
snapshot->xmin=proc->xid;
@@ -684,7 +677,7 @@ GetSnapshotData(bool serialized)
684677
if (have==0)
685678
{
686679
snapshot->xip= (TransactionId*)realloc(snapshot->xip,
687-
(count+33)*sizeof(TransactionId));
680+
(count+32)*sizeof(TransactionId));
688681
have=32;
689682
}
690683
snapshot->xip[count]=proc->xid;

‎src/backend/storage/lmgr/lmgr.c

Lines changed: 2 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/storage/lmgr/lmgr.c,v 1.20 1998/12/15 12:46:30 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.21 1998/12/16 11:53:48 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -325,6 +325,7 @@ XactLockTableWait(TransactionId xid)
325325

326326
LockAcquire(LockTableId,&tag,ShareLock);
327327

328+
TransactionIdFlushCache();
328329
/*
329330
* Transaction was committed/aborted/crashed -
330331
* we have to update pg_log if transaction is still

‎src/backend/tcop/postgres.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.94 1998/10/1606:05:13 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.95 1998/12/1611:53:52 vadim Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -786,9 +786,10 @@ pg_exec_query_dest(char *query_string,/* string to execute */
786786
}
787787
#endif
788788

789-
/* ----------------
789+
SetQuerySnapshot();
790+
791+
/*
790792
* execute the plan
791-
*
792793
*/
793794
if (ShowExecutorStats)
794795
ResetUsage();
@@ -1519,7 +1520,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
15191520
if (!IsUnderPostmaster)
15201521
{
15211522
puts("\nPOSTGRES backend interactive interface ");
1522-
puts("$Revision: 1.94 $ $Date: 1998/10/1606:05:13 $\n");
1523+
puts("$Revision: 1.95 $ $Date: 1998/12/1611:53:52 $\n");
15231524
}
15241525

15251526
/* ----------------

‎src/backend/utils/time/tqual.c

Lines changed: 160 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/utils/time/tqual.c,v 1.21 1998/12/15 12:46:40 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.22 1998/12/16 11:53:55 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -29,6 +29,9 @@ extern bool PostgresIsInitialized;
2929
SnapshotDataSnapshotDirtyData;
3030
SnapshotSnapshotDirty=&SnapshotDirtyData;
3131

32+
SnapshotQuerySnapshot=NULL;
33+
staticSnapshotSerializedSnapshot=NULL;
34+
3235
/*
3336
* XXX Transaction system override hacks start here
3437
*/
@@ -436,3 +439,159 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple)
436439

437440
return false;/* updated by other */
438441
}
442+
443+
bool
444+
HeapTupleSatisfiesSnapshot(HeapTupleHeadertuple,Snapshotsnapshot)
445+
{
446+
if (AMI_OVERRIDE)
447+
return true;
448+
449+
if (!(tuple->t_infomask&HEAP_XMIN_COMMITTED))
450+
{
451+
if (tuple->t_infomask&HEAP_XMIN_INVALID)/* xid invalid or
452+
* aborted */
453+
return false;
454+
455+
if (TransactionIdIsCurrentTransactionId(tuple->t_xmin))
456+
{
457+
if (CommandIdGEScanCommandId(tuple->t_cmin))
458+
return false;/* inserted after scan started */
459+
460+
if (tuple->t_infomask&HEAP_XMAX_INVALID)/* xid invalid */
461+
return true;
462+
463+
Assert(TransactionIdIsCurrentTransactionId(tuple->t_xmax));
464+
465+
if (tuple->t_infomask&HEAP_MARKED_FOR_UPDATE)
466+
return true;
467+
468+
if (CommandIdGEScanCommandId(tuple->t_cmax))
469+
return true;/* deleted after scan started */
470+
else
471+
return false;/* deleted before scan started */
472+
}
473+
474+
/*
475+
* this call is VERY expensive - requires a log table lookup.
476+
*/
477+
478+
if (!TransactionIdDidCommit(tuple->t_xmin))
479+
{
480+
if (TransactionIdDidAbort(tuple->t_xmin))
481+
tuple->t_infomask |=HEAP_XMIN_INVALID;/* aborted */
482+
return false;
483+
}
484+
485+
tuple->t_infomask |=HEAP_XMIN_COMMITTED;
486+
}
487+
488+
/*
489+
* By here, the inserting transaction has committed -
490+
* have to check when...
491+
*/
492+
493+
if (tuple->t_xmin >=snapshot->xmax)
494+
return false;
495+
if (tuple->t_xmin >=snapshot->xmin)
496+
{
497+
uint32i;
498+
499+
for (i=0;i<snapshot->xcnt;i++)
500+
{
501+
if (tuple->t_xmin==snapshot->xip[i])
502+
return false;
503+
}
504+
}
505+
506+
if (tuple->t_infomask&HEAP_XMAX_INVALID)/* xid invalid or aborted */
507+
return true;
508+
509+
if (tuple->t_infomask&HEAP_MARKED_FOR_UPDATE)
510+
return true;
511+
512+
if (!(tuple->t_infomask&HEAP_XMAX_COMMITTED))
513+
{
514+
if (TransactionIdIsCurrentTransactionId(tuple->t_xmax))
515+
{
516+
if (CommandIdGEScanCommandId(tuple->t_cmax))
517+
return true;/* deleted after scan started */
518+
else
519+
return false;/* deleted before scan started */
520+
}
521+
522+
if (!TransactionIdDidCommit(tuple->t_xmax))
523+
{
524+
if (TransactionIdDidAbort(tuple->t_xmax))
525+
tuple->t_infomask |=HEAP_XMAX_INVALID;/* aborted */
526+
return true;
527+
}
528+
529+
/* xmax transaction committed */
530+
tuple->t_infomask |=HEAP_XMAX_COMMITTED;
531+
}
532+
533+
if (tuple->t_xmax >=snapshot->xmax)
534+
return true;
535+
if (tuple->t_xmax >=snapshot->xmin)
536+
{
537+
uint32i;
538+
539+
for (i=0;i<snapshot->xcnt;i++)
540+
{
541+
if (tuple->t_xmax==snapshot->xip[i])
542+
return true;
543+
}
544+
}
545+
546+
return false;
547+
}
548+
549+
void
550+
SetQuerySnapshot(void)
551+
{
552+
553+
/* 1st call in xaction */
554+
if (SerializedSnapshot==NULL)
555+
{
556+
SerializedSnapshot=GetSnapshotData();
557+
QuerySnapshot=SerializedSnapshot;
558+
Assert(QuerySnapshot!=NULL);
559+
return;
560+
}
561+
562+
if (QuerySnapshot!=SerializedSnapshot)
563+
{
564+
free(QuerySnapshot->xip);
565+
free(QuerySnapshot);
566+
}
567+
568+
if (XactIsoLevel==XACT_SERIALIZED)
569+
QuerySnapshot=SerializedSnapshot;
570+
else
571+
QuerySnapshot=GetSnapshotData();
572+
573+
Assert(QuerySnapshot!=NULL);
574+
575+
}
576+
577+
void
578+
FreeXactSnapshot(void)
579+
{
580+
581+
if (QuerySnapshot!=NULL&&QuerySnapshot!=SerializedSnapshot)
582+
{
583+
free(QuerySnapshot->xip);
584+
free(QuerySnapshot);
585+
}
586+
587+
QuerySnapshot=NULL;
588+
589+
if (SerializedSnapshot!=NULL)
590+
{
591+
free(SerializedSnapshot->xip);
592+
free(SerializedSnapshot);
593+
}
594+
595+
SerializedSnapshot=NULL;
596+
597+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp