Created
June 16, 2015 22:05
-
-
Save macdice/8e5b2f0fe3827fdf3d5a to your computer and use it in GitHub Desktop.
slru-does-page-exist.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c | |
index 516a89f..ab85f6f 100644 | |
--- a/src/backend/access/transam/multixact.c | |
+++ b/src/backend/access/transam/multixact.c | |
@@ -2734,7 +2734,7 @@ find_multixact_start(MultiXactId multi, MultiXactOffset *result) | |
pageno = MultiXactIdToOffsetPage(multi); | |
entryno = MultiXactIdToOffsetEntry(multi); | |
- if (!SimpleLruDoesPhysicalPageExist(MultiXactOffsetCtl, pageno)) | |
+ if (!SimpleLruDoesPageExist(MultiXactOffsetCtl, pageno)) | |
return false; | |
/* lock is acquired by SimpleLruReadPage_ReadOnly */ | |
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c | |
index 5fcea11..caf2a82 100644 | |
--- a/src/backend/access/transam/slru.c | |
+++ b/src/backend/access/transam/slru.c | |
@@ -564,6 +564,41 @@ SimpleLruWritePage(SlruCtl ctl, int slotno) | |
} | |
/* | |
+ * Return whether the given page exists in a buffer or on disk. | |
+ */ | |
+bool | |
+SimpleLruDoesPageExist(SlruCtl ctl, int pageno) | |
+{ | |
+ return SimpleLruDoesBufferedPageExist(ctl, pageno) || | |
+ SimpleLruDoesPhysicalPageExist(ctl, pageno); | |
+} | |
+ | |
+/* | |
+ * Return whether the given page is currently buffered. | |
+ */ | |
+bool | |
+SimpleLruDoesBufferedPageExist(SlruCtl ctl, int pageno) | |
+{ | |
+ SlruShared shared = ctl->shared; | |
+ bool result = false; | |
+ int slotno; | |
+ | |
+ LWLockAcquire(shared->ControlLock, LW_SHARED); | |
+ for (slotno = 0; slotno < shared->num_slots; slotno++) | |
+ { | |
+ if (shared->page_number[slotno] == pageno && | |
+ shared->page_status[slotno] != SLRU_PAGE_EMPTY) | |
+ { | |
+ result = true; | |
+ break; | |
+ } | |
+ } | |
+ LWLockRelease(shared->ControlLock); | |
+ | |
+ return result; | |
+} | |
+ | |
+/* | |
* Return whether the given page exists on disk. | |
* | |
* A false return means that either the file does not exist, or that it's not | |
diff --git a/src/include/access/slru.h b/src/include/access/slru.h | |
index 9c7f019..3907d7d 100644 | |
--- a/src/include/access/slru.h | |
+++ b/src/include/access/slru.h | |
@@ -145,6 +145,8 @@ extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, | |
extern void SimpleLruWritePage(SlruCtl ctl, int slotno); | |
extern void SimpleLruFlush(SlruCtl ctl, bool checkpoint); | |
extern void SimpleLruTruncate(SlruCtl ctl, int cutoffPage); | |
+extern bool SimpleLruDoesPageExist(SlruCtl ctl, int pageno); | |
+extern bool SimpleLruDoesBufferedPageExist(SlruCtl ctl, int pageno); | |
extern bool SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno); | |
typedef bool (*SlruScanCallback) (SlruCtl ctl, char *filename, int segpage, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment