snapshot-error-v1.patch
application/octet-stream
Filename: snapshot-error-v1.patch
Type: application/octet-stream
Part: 0
Message:
getting rid of SnapshotNow
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/backend/access/index/genam.c | 1 | 1 |
| src/backend/executor/execUtils.c | 1 | 1 |
| src/backend/utils/time/tqual.c | 16 | 0 |
| src/include/utils/tqual.h | 4 | 0 |
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 60a2b4e..5ecd360 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -79,7 +79,7 @@ RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
scan->heapRelation = NULL; /* may be set later */
scan->indexRelation = indexRelation;
- scan->xs_snapshot = SnapshotNow; /* may be set later */
+ scan->xs_snapshot = SnapshotError; /* *must* be set later */
scan->numberOfKeys = nkeys;
scan->numberOfOrderBys = norderbys;
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index b449e0a..2a1ac0c 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -105,7 +105,7 @@ CreateExecutorState(void)
* Initialize all fields of the Executor State structure
*/
estate->es_direction = ForwardScanDirection;
- estate->es_snapshot = SnapshotNow;
+ estate->es_snapshot = SnapshotError;
estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
estate->es_range_table = NIL;
estate->es_plannedstmt = NULL;
diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c
index 55563ea..e8c9409 100644
--- a/src/backend/utils/time/tqual.c
+++ b/src/backend/utils/time/tqual.c
@@ -72,6 +72,7 @@ SnapshotData SnapshotNowData = {HeapTupleSatisfiesNow};
SnapshotData SnapshotSelfData = {HeapTupleSatisfiesSelf};
SnapshotData SnapshotAnyData = {HeapTupleSatisfiesAny};
SnapshotData SnapshotToastData = {HeapTupleSatisfiesToast};
+SnapshotData SnapshotErrorData = {HeapTupleSatisfiesError};
/* local functions */
static bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
@@ -600,6 +601,21 @@ HeapTupleSatisfiesToast(HeapTupleHeader tuple, Snapshot snapshot,
}
/*
+ * HeapTupleSatisfiesError
+ * Illegal "satisfies" method to catch programming errors.
+ *
+ * This is used as a default in various places, so that failure to
+ * install a sane value will result in an error, rather than wrong
+ * behavior or a core dump.
+ */
+bool
+HeapTupleSatisfiesError(HeapTupleHeader tuple, Snapshot snapshot,
+ Buffer buffer)
+{
+ elog(ERROR, "snapshot not initialized");
+}
+
+/*
* HeapTupleSatisfiesUpdate
*
* Same logic as HeapTupleSatisfiesNow, but returns a more detailed result
diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h
index 465231c..9b05677 100644
--- a/src/include/utils/tqual.h
+++ b/src/include/utils/tqual.h
@@ -23,11 +23,13 @@ extern PGDLLIMPORT SnapshotData SnapshotNowData;
extern PGDLLIMPORT SnapshotData SnapshotSelfData;
extern PGDLLIMPORT SnapshotData SnapshotAnyData;
extern PGDLLIMPORT SnapshotData SnapshotToastData;
+extern PGDLLIMPORT SnapshotData SnapshotErrorData;
#define SnapshotNow (&SnapshotNowData)
#define SnapshotSelf (&SnapshotSelfData)
#define SnapshotAny (&SnapshotAnyData)
#define SnapshotToast (&SnapshotToastData)
+#define SnapshotError (&SnapshotErrorData)
/*
* We don't provide a static SnapshotDirty variable because it would be
@@ -77,6 +79,8 @@ extern bool HeapTupleSatisfiesToast(HeapTupleHeader tuple,
Snapshot snapshot, Buffer buffer);
extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple,
Snapshot snapshot, Buffer buffer);
+extern bool HeapTupleSatisfiesError(HeapTupleHeader tuple,
+ Snapshot snapshot, Buffer buffer);
/* Special "satisfies" routines with different APIs */
extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTupleHeader tuple,