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

Commit19422a9

Browse files
committed
get rid of gtid2xid hash
1 parentc69da66 commit19422a9

File tree

5 files changed

+48
-62
lines changed

5 files changed

+48
-62
lines changed

‎contrib/postgres_fdw/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ pgfdw_xact_callback(XactEvent event, void *arg)
832832
}
833833
else/* Otherwise, just finalize dtm and proceed below to COMMIT */
834834
{
835-
finalize_dtm();
835+
//finalize_dtm();
836836
}
837837
}
838838

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

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ typedef struct
8585

8686
// static shmem_startup_hook_type prev_shmem_startup_hook;
8787
staticHTAB*xid2status;
88-
staticHTAB*gtid2xid;
8988
staticDtmNodeState*local;
9089
staticuint64totalSleepInterrupts;
9190
staticintDtmVacuumDelay=15;/* sec */
@@ -432,13 +431,6 @@ DtmInitialize()
432431
&info,
433432
HASH_ELEM |HASH_BLOBS);
434433

435-
info.keysize=MAX_GTID_SIZE;
436-
info.entrysize=sizeof(DtmTransId);
437-
gtid2xid=ShmemInitHash("gtid2xid",
438-
DTM_HASH_INIT_SIZE,DTM_HASH_INIT_SIZE,
439-
&info,
440-
HASH_ELEM);
441-
442434
TM=&DtmTM;
443435

444436
LWLockAcquire(AddinShmemInitLock,LW_EXCLUSIVE);
@@ -478,16 +470,7 @@ DtmLocalExtend(GlobalTransactionId gtid)
478470

479471
if (gtid!=NULL)
480472
{
481-
SpinLockAcquire(&local->lock);
482-
{
483-
DtmTransId*id= (DtmTransId*)hash_search(gtid2xid,gtid,HASH_ENTER,NULL);
484-
485-
id->xid=GetCurrentTransactionId();
486-
id->nSubxids=0;
487-
id->subxids=0;
488-
}
489473
strncpy(x->gtid,gtid,MAX_GTID_SIZE);
490-
SpinLockRelease(&local->lock);
491474
}
492475
DtmInitGlobalXmin(TransactionXmin);
493476
returnx->snapshot;
@@ -506,14 +489,6 @@ DtmLocalAccess(DtmCurrentTrans * x, GlobalTransactionId gtid, cid_t global_cid)
506489

507490
SpinLockAcquire(&local->lock);
508491
{
509-
if (gtid!=NULL)
510-
{
511-
DtmTransId*id= (DtmTransId*)hash_search(gtid2xid,gtid,HASH_ENTER,NULL);
512-
513-
id->xid=GetCurrentTransactionId();
514-
id->nSubxids=0;
515-
id->subxids=0;
516-
}
517492
local_cid=dtm_sync(global_cid);
518493
x->snapshot=global_cid;
519494
}
@@ -536,18 +511,20 @@ DtmLocalAccess(DtmCurrentTrans * x, GlobalTransactionId gtid, cid_t global_cid)
536511
void
537512
DtmLocalBeginPrepare(GlobalTransactionIdgtid)
538513
{
539-
// TransactionId xid = TwoPhaseGetTransactionId(gtid);
514+
TransactionIdxid=TwoPhaseGetTransactionId(gtid);
515+
516+
if (!TransactionIdIsValid(xid))
517+
{
518+
// XXX: check that it is global tx with the same xid, XactTopTransactionId?
519+
xid=GetCurrentTransactionId();
520+
}
540521

541522
SpinLockAcquire(&local->lock);
542523
{
543524
DtmTransStatus*ts;
544-
DtmTransId*id;
545525
boolfound;
546526

547-
id= (DtmTransId*)hash_search(gtid2xid,gtid,HASH_FIND,NULL);
548-
Assert(id!=NULL);
549-
Assert(TransactionIdIsValid(id->xid));
550-
ts= (DtmTransStatus*)hash_search(xid2status,&id->xid,HASH_ENTER,&found);
527+
ts= (DtmTransStatus*)hash_search(xid2status,&xid,HASH_ENTER,&found);
551528
ts->status=TRANSACTION_STATUS_UNKNOWN;
552529
ts->cid=dtm_get_cid();
553530
if (!found)
@@ -582,15 +559,23 @@ DtmLocalPrepare(GlobalTransactionId gtid, cid_t global_cid)
582559
void
583560
DtmLocalEndPrepare(GlobalTransactionIdgtid,cid_tcid)
584561
{
562+
TransactionIdxid=TwoPhaseGetTransactionId(gtid);
563+
564+
if (!TransactionIdIsValid(xid))
565+
{
566+
// XXX: check that it is global tx with the same xid, XactTopTransactionId?
567+
xid=GetCurrentTransactionId();
568+
}
569+
570+
dtm_tx.xid=xid;
571+
585572
SpinLockAcquire(&local->lock);
586573
{
587574
DtmTransStatus*ts;
588575
DtmTransId*id;
589576
inti;
590577

591-
id= (DtmTransId*)hash_search(gtid2xid,gtid,HASH_FIND,NULL);
592-
593-
ts= (DtmTransStatus*)hash_search(xid2status,&id->xid,HASH_FIND,NULL);
578+
ts= (DtmTransStatus*)hash_search(xid2status,&xid,HASH_FIND,NULL);
594579
Assert(ts!=NULL);
595580
ts->cid=cid;
596581
DtmAdjustSubtransactions(ts);
@@ -613,19 +598,7 @@ DtmLocalFinish(bool is_commit)
613598

614599
if (x->gtid[0]&&finishing_prepared)
615600
{
616-
// Assert(!TransactionIdIsValid(xid));
617-
618-
SpinLockAcquire(&local->lock);
619-
{
620-
DtmTransId*id= (DtmTransId*)hash_search(gtid2xid,x->gtid,HASH_REMOVE,NULL);
621-
622-
Assert(id!=NULL);
623-
Assert(TransactionIdIsValid(id->xid));
624-
625-
xid=id->xid;
626-
free(id->subxids);
627-
}
628-
SpinLockRelease(&local->lock);
601+
xid=x->xid;
629602
}
630603
elseif (!TransactionIdIsValid(xid))
631604
{
@@ -716,20 +689,6 @@ DtmLocalSavePreparedState(DtmCurrentTrans * x)
716689
intnSubxids=xactGetCommittedChildren(&subxids);
717690

718691
SpinLockAcquire(&local->lock);
719-
{
720-
DtmTransId*id= (DtmTransId*)hash_search(gtid2xid,x->gtid,HASH_FIND,NULL);
721-
722-
if (id!=NULL)
723-
{
724-
id->xid=GetCurrentTransactionId();
725-
726-
}
727-
}
728-
// SpinLockRelease(&local->lock);
729-
730-
731-
732-
// SpinLockAcquire(&local->lock);
733692
{
734693
DtmTransStatus*ts;
735694

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,31 @@ TwoPhaseGetDummyProc(TransactionId xid)
872872
return&ProcGlobal->allProcs[gxact->pgprocno];
873873
}
874874

875+
TransactionId
876+
TwoPhaseGetTransactionId(constchar*gid)
877+
{
878+
inti;
879+
880+
LWLockAcquire(TwoPhaseStateLock,LW_SHARED);
881+
for (i=0;i<TwoPhaseState->numPrepXacts;i++)
882+
{
883+
GlobalTransactiongxact=TwoPhaseState->prepXacts[i];
884+
885+
/* Ignore not-yet-valid GIDs */
886+
if (!gxact->valid)
887+
continue;
888+
889+
if (strcmp(gxact->gid,gid)==0)
890+
{
891+
LWLockRelease(TwoPhaseStateLock);
892+
returngxact->xid;
893+
}
894+
}
895+
LWLockRelease(TwoPhaseStateLock);
896+
897+
returnInvalidTransactionId;
898+
}
899+
875900
/************************************************************************/
876901
/* State file support*/
877902
/************************************************************************/

‎src/include/access/global_snapshot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ typedef struct
1010
{
1111
cid_tsnapshot;
1212
chargtid[MAX_GTID_SIZE];
13+
TransactionIdxid;
1314
}DtmCurrentTrans;
1415

1516
typedefcharconst*GlobalTransactionId;

‎src/include/access/twophase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extern void PostPrepare_Twophase(void);
3535

3636
externPGPROC*TwoPhaseGetDummyProc(TransactionIdxid);
3737
externBackendIdTwoPhaseGetDummyBackendId(TransactionIdxid);
38+
externTransactionIdTwoPhaseGetTransactionId(constchar*gid);
3839

3940
externGlobalTransactionMarkAsPreparing(TransactionIdxid,constchar*gid,
4041
TimestampTzprepared_at,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp