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

Commit49f68a8

Browse files
committed
Avoid disk writes for read-only transactions.
1 parentcffd0f9 commit49f68a8

File tree

2 files changed

+49
-29
lines changed

2 files changed

+49
-29
lines changed

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

Lines changed: 33 additions & 28 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.41 1999/06/10 14:17:06 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.42 1999/06/29 04:54:46 vadim Exp $
1111
*
1212
* NOTES
1313
*Transaction aborts can now occur two ways:
@@ -158,6 +158,8 @@
158158
#include<commands/sequence.h>
159159
#include<libpq/be-fsstubs.h>
160160

161+
externboolSharedBufferChanged;
162+
161163
staticvoidAbortTransaction(void);
162164
staticvoidAtAbort_Cache(void);
163165
staticvoidAtAbort_Locks(void);
@@ -618,30 +620,36 @@ RecordTransactionCommit()
618620
*/
619621
xid=GetCurrentTransactionId();
620622

621-
/*----------------
623+
/*
622624
*flush the buffer manager pages. Note: if we have stable
623625
*main memory, dirty shared buffers are not flushed
624626
*plai 8/7/90
625-
* ----------------
626627
*/
627628
leak=BufferPoolCheckLeak();
628-
FlushBufferPool(!TransactionFlushEnabled());
629-
if (leak)
630-
ResetBufferPool();
631629

632-
/* ----------------
633-
*have the transaction access methods record the status
634-
*of this transaction id in the pg_log / pg_time relations.
635-
* ----------------
630+
/*
631+
* If no one shared buffer was changed by this transaction then
632+
* we don't flush shared buffers and don't record commit status.
636633
*/
637-
TransactionIdCommit(xid);
634+
if (SharedBufferChanged)
635+
{
636+
FlushBufferPool(!TransactionFlushEnabled());
637+
if (leak)
638+
ResetBufferPool();
639+
640+
/*
641+
*have the transaction access methods record the status
642+
*of this transaction id in the pg_log relation.
643+
*/
644+
TransactionIdCommit(xid);
645+
646+
/*
647+
*Now write the log info to the disk too.
648+
*/
649+
leak=BufferPoolCheckLeak();
650+
FlushBufferPool(!TransactionFlushEnabled());
651+
}
638652

639-
/* ----------------
640-
*Now write the log/time info to the disk too.
641-
* ----------------
642-
*/
643-
leak=BufferPoolCheckLeak();
644-
FlushBufferPool(!TransactionFlushEnabled());
645653
if (leak)
646654
ResetBufferPool();
647655
}
@@ -731,19 +739,14 @@ RecordTransactionAbort()
731739
*/
732740
xid=GetCurrentTransactionId();
733741

734-
/*----------------
735-
*havethe transaction access methods record the status
736-
*of this transaction id in the pg_log/ pg_time relations.
737-
*----------------
742+
/*
743+
* Havethe transaction access methods record the status of
744+
* this transaction id in the pg_logrelation. We skip it
745+
*if no one shared buffer was changed by this transaction.
738746
*/
739-
TransactionIdAbort(xid);
747+
if (SharedBufferChanged)
748+
TransactionIdAbort(xid);
740749

741-
/* ----------------
742-
*flush the buffer manager pages. Note: if we have stable
743-
*main memory, dirty shared buffers are not flushed
744-
*plai 8/7/90
745-
* ----------------
746-
*/
747750
ResetBufferPool();
748751
}
749752

@@ -965,6 +968,7 @@ CommitTransaction()
965968
* ----------------
966969
*/
967970
s->state=TRANS_DEFAULT;
971+
SharedBufferChanged= false;/* safest place to do it */
968972

969973
}
970974

@@ -1028,6 +1032,7 @@ AbortTransaction()
10281032
* ----------------
10291033
*/
10301034
s->state=TRANS_DEFAULT;
1035+
SharedBufferChanged= false;/* safest place to do it */
10311036
}
10321037

10331038
/* --------------------------------

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 16 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/buffer/bufmgr.c,v 1.55 1999/06/11 09:00:02 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.56 1999/06/29 04:54:47 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -78,6 +78,15 @@ extern long int LocalBufferHitCount;
7878
externlongintBufferFlushCount;
7979
externlongintLocalBufferFlushCount;
8080

81+
/*
82+
* It's used to avoid disk writes for read-only transactions
83+
* (i.e. when no one shared buffer was changed by transaction).
84+
* We set it to true in WriteBuffer/WriteNoReleaseBuffer when
85+
* marking shared buffer as dirty. We set it to false in xact.c
86+
* after transaction is committed/aborted.
87+
*/
88+
boolSharedBufferChanged= false;
89+
8190
staticintWriteMode=BUFFER_LATE_WRITE;/* Delayed write is
8291
* default */
8392

@@ -699,6 +708,8 @@ WriteBuffer(Buffer buffer)
699708

700709
bufHdr=&BufferDescriptors[buffer-1];
701710

711+
SharedBufferChanged= true;
712+
702713
SpinAcquire(BufMgrLock);
703714
Assert(bufHdr->refcount>0);
704715
bufHdr->flags |= (BM_DIRTY |BM_JUST_DIRTIED);
@@ -810,6 +821,8 @@ FlushBuffer(Buffer buffer, bool release)
810821
bufrel=RelationIdCacheGetRelation(bufHdr->tag.relId.relId);
811822
Assert(bufrel!= (Relation)NULL);
812823

824+
SharedBufferChanged= true;
825+
813826
/* To check if block content changed while flushing. - vadim 01/17/97 */
814827
SpinAcquire(BufMgrLock);
815828
bufHdr->flags &= ~BM_JUST_DIRTIED;
@@ -875,6 +888,8 @@ WriteNoReleaseBuffer(Buffer buffer)
875888

876889
bufHdr=&BufferDescriptors[buffer-1];
877890

891+
SharedBufferChanged= true;
892+
878893
SpinAcquire(BufMgrLock);
879894
bufHdr->flags |= (BM_DIRTY |BM_JUST_DIRTIED);
880895
SpinRelease(BufMgrLock);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp