PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
subtrans.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NUM_SUBTRANS_BUFFERS   32
 

Functions

void SubTransSetParent (TransactionId xid, TransactionId parent, bool overwriteOK)
 
TransactionId SubTransGetParent (TransactionId xid)
 
TransactionId SubTransGetTopmostTransaction (TransactionId xid)
 
Size SUBTRANSShmemSize (void)
 
void SUBTRANSShmemInit (void)
 
void BootStrapSUBTRANS (void)
 
void StartupSUBTRANS (TransactionId oldestActiveXID)
 
void ShutdownSUBTRANS (void)
 
void CheckPointSUBTRANS (void)
 
void ExtendSUBTRANS (TransactionId newestXact)
 
void TruncateSUBTRANS (TransactionId oldestXact)
 

Macro Definition Documentation

#define NUM_SUBTRANS_BUFFERS   32

Definition at line 15 of file subtrans.h.

Referenced by SUBTRANSShmemInit(), and SUBTRANSShmemSize().

Function Documentation

void BootStrapSUBTRANS ( void  )

Definition at line 199 of file subtrans.c.

References Assert, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), SimpleLruWritePage(), SubTransCtl, and ZeroSUBTRANSPage().

Referenced by BootStrapXLOG().

200 {
201  int slotno;
202 
203  LWLockAcquire(SubtransControlLock, LW_EXCLUSIVE);
204 
205  /* Create and zero the first page of the subtrans log */
206  slotno = ZeroSUBTRANSPage(0);
207 
208  /* Make sure it's written out */
210  Assert(!SubTransCtl->shared->page_dirty[slotno]);
211 
212  LWLockRelease(SubtransControlLock);
213 }
static int ZeroSUBTRANSPage(int pageno)
Definition: subtrans.c:224
#define SubTransCtl
Definition: subtrans.c:62
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:574
#define Assert(condition)
Definition: c.h:675
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
void CheckPointSUBTRANS ( void  )

Definition at line 287 of file subtrans.c.

References SimpleLruFlush(), and SubTransCtl.

Referenced by CheckPointGuts().

288 {
289  /*
290  * Flush dirty SUBTRANS pages to disk
291  *
292  * This is not actually necessary from a correctness point of view. We do
293  * it merely to improve the odds that writing of dirty pages is done by
294  * the checkpoint process and not by backends.
295  */
296  TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_START(true);
298  TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_DONE(true);
299 }
void SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1100
#define SubTransCtl
Definition: subtrans.c:62
void ExtendSUBTRANS ( TransactionId  newestXact)

Definition at line 311 of file subtrans.c.

References FirstNormalTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransactionIdEquals, TransactionIdToEntry, TransactionIdToPage, and ZeroSUBTRANSPage().

Referenced by GetNewTransactionId(), ProcArrayApplyRecoveryInfo(), and RecordKnownAssignedTransactionIds().

312 {
313  int pageno;
314 
315  /*
316  * No work except at first XID of a page. But beware: just after
317  * wraparound, the first XID of page zero is FirstNormalTransactionId.
318  */
319  if (TransactionIdToEntry(newestXact) != 0 &&
321  return;
322 
323  pageno = TransactionIdToPage(newestXact);
324 
325  LWLockAcquire(SubtransControlLock, LW_EXCLUSIVE);
326 
327  /* Zero the page */
328  ZeroSUBTRANSPage(pageno);
329 
330  LWLockRelease(SubtransControlLock);
331 }
static int ZeroSUBTRANSPage(int pageno)
Definition: subtrans.c:224
#define TransactionIdToEntry(xid)
Definition: subtrans.c:54
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
#define FirstNormalTransactionId
Definition: transam.h:34
#define TransactionIdToPage(xid)
Definition: subtrans.c:53
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
void ShutdownSUBTRANS ( void  )

Definition at line 270 of file subtrans.c.

References SimpleLruFlush(), and SubTransCtl.

Referenced by ShutdownXLOG().

271 {
272  /*
273  * Flush dirty SUBTRANS pages to disk
274  *
275  * This is not actually necessary from a correctness point of view. We do
276  * it merely as a debugging aid.
277  */
278  TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_START(false);
279  SimpleLruFlush(SubTransCtl, false);
280  TRACE_POSTGRESQL_SUBTRANS_CHECKPOINT_DONE(false);
281 }
void SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1100
#define SubTransCtl
Definition: subtrans.c:62
void StartupSUBTRANS ( TransactionId  oldestActiveXID)

Definition at line 237 of file subtrans.c.

References LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MaxTransactionId, VariableCacheData::nextXid, ShmemVariableCache, TransactionIdToPage, and ZeroSUBTRANSPage().

Referenced by StartupXLOG().

238 {
239  int startPage;
240  int endPage;
241 
242  /*
243  * Since we don't expect pg_subtrans to be valid across crashes, we
244  * initialize the currently-active page(s) to zeroes during startup.
245  * Whenever we advance into a new page, ExtendSUBTRANS will likewise zero
246  * the new page without regard to whatever was previously on disk.
247  */
248  LWLockAcquire(SubtransControlLock, LW_EXCLUSIVE);
249 
250  startPage = TransactionIdToPage(oldestActiveXID);
252 
253  while (startPage != endPage)
254  {
255  (void) ZeroSUBTRANSPage(startPage);
256  startPage++;
257  /* must account for wraparound */
258  if (startPage > TransactionIdToPage(MaxTransactionId))
259  startPage = 0;
260  }
261  (void) ZeroSUBTRANSPage(startPage);
262 
263  LWLockRelease(SubtransControlLock);
264 }
static int ZeroSUBTRANSPage(int pageno)
Definition: subtrans.c:224
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
TransactionId nextXid
Definition: transam.h:117
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define MaxTransactionId
Definition: transam.h:35
#define TransactionIdToPage(xid)
Definition: subtrans.c:53
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
TransactionId SubTransGetParent ( TransactionId  xid)

Definition at line 105 of file subtrans.c.

References Assert, InvalidTransactionId, LWLockRelease(), SimpleLruReadPage_ReadOnly(), SubTransCtl, TransactionIdFollowsOrEquals(), TransactionIdIsNormal, TransactionIdToEntry, TransactionIdToPage, and TransactionXmin.

Referenced by ConditionalXactLockTableWait(), SubTransGetTopmostTransaction(), TransactionIdDidAbort(), TransactionIdDidCommit(), and XactLockTableWait().

106 {
107  int pageno = TransactionIdToPage(xid);
108  int entryno = TransactionIdToEntry(xid);
109  int slotno;
110  TransactionId *ptr;
111  TransactionId parent;
112 
113  /* Can't ask about stuff that might not be around anymore */
115 
116  /* Bootstrap and frozen XIDs have no parent */
117  if (!TransactionIdIsNormal(xid))
118  return InvalidTransactionId;
119 
120  /* lock is acquired by SimpleLruReadPage_ReadOnly */
121 
122  slotno = SimpleLruReadPage_ReadOnly(SubTransCtl, pageno, xid);
123  ptr = (TransactionId *) SubTransCtl->shared->page_buffer[slotno];
124  ptr += entryno;
125 
126  parent = *ptr;
127 
128  LWLockRelease(SubtransControlLock);
129 
130  return parent;
131 }
#define TransactionIdToEntry(xid)
Definition: subtrans.c:54
uint32 TransactionId
Definition: c.h:397
bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2)
Definition: transam.c:349
TransactionId TransactionXmin
Definition: snapmgr.c:164
#define SubTransCtl
Definition: subtrans.c:62
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
#define InvalidTransactionId
Definition: transam.h:31
#define TransactionIdToPage(xid)
Definition: subtrans.c:53
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
Definition: slru.c:463
#define Assert(condition)
Definition: c.h:675
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
TransactionId SubTransGetTopmostTransaction ( TransactionId  xid)

Definition at line 146 of file subtrans.c.

References Assert, SubTransGetParent(), TransactionIdFollowsOrEquals(), TransactionIdIsValid, TransactionIdPrecedes(), and TransactionXmin.

Referenced by CheckForSerializableConflictOut(), PredicateLockTuple(), TransactionIdIsInProgress(), and XidInMVCCSnapshot().

147 {
148  TransactionId parentXid = xid,
149  previousXid = xid;
150 
151  /* Can't ask about stuff that might not be around anymore */
153 
154  while (TransactionIdIsValid(parentXid))
155  {
156  previousXid = parentXid;
157  if (TransactionIdPrecedes(parentXid, TransactionXmin))
158  break;
159  parentXid = SubTransGetParent(parentXid);
160  }
161 
162  Assert(TransactionIdIsValid(previousXid));
163 
164  return previousXid;
165 }
uint32 TransactionId
Definition: c.h:397
TransactionId SubTransGetParent(TransactionId xid)
Definition: subtrans.c:105
bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2)
Definition: transam.c:349
TransactionId TransactionXmin
Definition: snapmgr.c:164
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
#define Assert(condition)
Definition: c.h:675
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void SubTransSetParent ( TransactionId  xid,
TransactionId  parent,
bool  overwriteOK 
)

Definition at line 75 of file subtrans.c.

References Assert, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), SimpleLruReadPage(), SubTransCtl, TransactionIdIsValid, TransactionIdToEntry, and TransactionIdToPage.

Referenced by AssignTransactionId(), ProcArrayApplyXidAssignment(), ProcessTwoPhaseBuffer(), and RecoverPreparedTransactions().

76 {
77  int pageno = TransactionIdToPage(xid);
78  int entryno = TransactionIdToEntry(xid);
79  int slotno;
80  TransactionId *ptr;
81 
83 
84  LWLockAcquire(SubtransControlLock, LW_EXCLUSIVE);
85 
86  slotno = SimpleLruReadPage(SubTransCtl, pageno, true, xid);
87  ptr = (TransactionId *) SubTransCtl->shared->page_buffer[slotno];
88  ptr += entryno;
89 
90  /* Current state should be 0 */
91  Assert(*ptr == InvalidTransactionId ||
92  (*ptr == parent && overwriteOK));
93 
94  *ptr = parent;
95 
96  SubTransCtl->shared->page_dirty[slotno] = true;
97 
98  LWLockRelease(SubtransControlLock);
99 }
#define TransactionIdToEntry(xid)
Definition: subtrans.c:54
uint32 TransactionId
Definition: c.h:397
#define SubTransCtl
Definition: subtrans.c:62
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
int SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok, TransactionId xid)
Definition: slru.c:371
#define InvalidTransactionId
Definition: transam.h:31
#define TransactionIdToPage(xid)
Definition: subtrans.c:53
#define Assert(condition)
Definition: c.h:675
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
#define TransactionIdIsValid(xid)
Definition: transam.h:41
void SUBTRANSShmemInit ( void  )

Definition at line 178 of file subtrans.c.

References LWTRANCHE_SUBTRANS_BUFFERS, NUM_SUBTRANS_BUFFERS, SimpleLruInit(), SubTransCtl, and SubTransPagePrecedes().

Referenced by CreateSharedMemoryAndSemaphores().

179 {
180  SubTransCtl->PagePrecedes = SubTransPagePrecedes;
182  SubtransControlLock, "pg_subtrans",
184  /* Override default assumption that writes should be fsync'd */
185  SubTransCtl->do_fsync = false;
186 }
#define SubTransCtl
Definition: subtrans.c:62
static bool SubTransPagePrecedes(int page1, int page2)
Definition: subtrans.c:370
#define NUM_SUBTRANS_BUFFERS
Definition: subtrans.h:15
void SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, LWLock *ctllock, const char *subdir, int tranche_id)
Definition: slru.c:165
Size SUBTRANSShmemSize ( void  )

Definition at line 172 of file subtrans.c.

References NUM_SUBTRANS_BUFFERS, and SimpleLruShmemSize().

Referenced by CreateSharedMemoryAndSemaphores().

173 {
175 }
Size SimpleLruShmemSize(int nslots, int nlsns)
Definition: slru.c:145
#define NUM_SUBTRANS_BUFFERS
Definition: subtrans.h:15
void TruncateSUBTRANS ( TransactionId  oldestXact)

Definition at line 341 of file subtrans.c.

References SimpleLruTruncate(), SubTransCtl, TransactionIdRetreat, and TransactionIdToPage.

Referenced by CreateCheckPoint(), and CreateRestartPoint().

342 {
343  int cutoffPage;
344 
345  /*
346  * The cutoff point is the start of the segment containing oldestXact. We
347  * pass the *page* containing oldestXact to SimpleLruTruncate. We step
348  * back one transaction to avoid passing a cutoff page that hasn't been
349  * created yet in the rare case that oldestXact would be the first item on
350  * a page and oldestXact == next XID. In that case, if we didn't subtract
351  * one, we'd trigger SimpleLruTruncate's wraparound detection.
352  */
353  TransactionIdRetreat(oldestXact);
354  cutoffPage = TransactionIdToPage(oldestXact);
355 
356  SimpleLruTruncate(SubTransCtl, cutoffPage);
357 }
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1165
#define TransactionIdRetreat(dest)
Definition: transam.h:56
#define SubTransCtl
Definition: subtrans.c:62
#define TransactionIdToPage(xid)
Definition: subtrans.c:53