Option2_v3-0001-Bug-fix-in-case-of-leftover-hash-after-spec-abort.patch
text/x-patch
Filename: Option2_v3-0001-Bug-fix-in-case-of-leftover-hash-after-spec-abort.patch
Type: text/x-patch
Part: 1
Patch
Format: format-patch
Series: patch v3-0001
Subject: Bug fix in case of leftover hash after spec abort
| File | + | − |
|---|---|---|
| src/backend/replication/logical/reorderbuffer.c | 22 | 10 |
From 68c672ec05b1867e3b170435f929321e43d05020 Mon Sep 17 00:00:00 2001
From: Dilip Kumar <dilipkumar@localhost.localdomain>
Date: Wed, 2 Jun 2021 11:16:34 +0530
Subject: [PATCH v3] Bug fix in case of leftover hash after spec abort
Basically, if the toast table insertion for spec insert followup
by spec abort then the toast hash was not cleaned up immeditely
and there was some assert and error based on that situation so
just ignore them.
---
src/backend/replication/logical/reorderbuffer.c | 32 +++++++++++++++++--------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 2d9e127..5c20e13 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -437,6 +437,9 @@ ReorderBufferReturnTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
txn->tuplecid_hash = NULL;
}
+ /* cleanup the toast hash */
+ ReorderBufferToastReset(rb, txn);
+
if (txn->invalidations)
{
pfree(txn->invalidations);
@@ -4583,6 +4586,25 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,
return;
/*
+ * If the current change is not a INSERT or UPDATE then it might be the
+ * leftover toast hash from previous spec insert without spec confirm. So
+ * we can just ignore it.
+ */
+ if (change->data.tp.newtuple == NULL)
+ return;
+
+ desc = RelationGetDescr(relation);
+
+ /*
+ * If the current relation doesn't have a toast relation then it might be
+ * the leftover toast hash from previous spec insert without spec confirm.
+ * So we can just ignore it.
+ */
+ toast_rel = RelationIdGetRelation(relation->rd_rel->reltoastrelid);
+ if (!RelationIsValid(toast_rel))
+ return;
+
+ /*
* We're going to modify the size of the change, so to make sure the
* accounting is correct we'll make it look like we're removing the change
* now (with the old size), and then re-add it at the end.
@@ -4591,16 +4613,6 @@ ReorderBufferToastReplace(ReorderBuffer *rb, ReorderBufferTXN *txn,
oldcontext = MemoryContextSwitchTo(rb->context);
- /* we should only have toast tuples in an INSERT or UPDATE */
- Assert(change->data.tp.newtuple);
-
- desc = RelationGetDescr(relation);
-
- toast_rel = RelationIdGetRelation(relation->rd_rel->reltoastrelid);
- if (!RelationIsValid(toast_rel))
- elog(ERROR, "could not open relation with OID %u",
- relation->rd_rel->reltoastrelid);
-
toast_desc = RelationGetDescr(toast_rel);
/* should we allocate from stack instead? */
--
1.8.3.1