This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 2de3a0f65dbc5d989b2cf91c0de3523abde90d85
Author: Ashwin Agrawal <[email protected]>
AuthorDate: Mon Aug 15 17:06:51 2022 -0700

    Emit ERROR if gp_fastsequence entry goes backward during update
    
    gp_fastsequnce entry semantic is to only move forward. Hence, add
    check to protect and catch if this assumption is broken. There existed
    bug which is fixed now, during AO table truncate where this assumption
    was broken and it was very hard to trace the RCA in absence of this
    check.
---
 src/backend/catalog/gp_fastsequence.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/backend/catalog/gp_fastsequence.c 
b/src/backend/catalog/gp_fastsequence.c
index fa3eaa742f..8d5b4759a1 100644
--- a/src/backend/catalog/gp_fastsequence.c
+++ b/src/backend/catalog/gp_fastsequence.c
@@ -146,10 +146,11 @@ insert_or_update_fastsequence(Relation 
gp_fastsequence_rel,
        }
        else
        {
+               bool isNull;
+               int64 currentLastSequence;
 #ifdef USE_ASSERT_CHECKING
                Oid oldObjid;
                int64 oldObjmod;
-               bool isNull;
                
                oldObjid = heap_getattr(oldTuple, Anum_gp_fastsequence_objid, 
tupleDesc, &isNull);
                Assert(!isNull);
@@ -158,6 +159,14 @@ insert_or_update_fastsequence(Relation gp_fastsequence_rel,
                Assert(oldObjid == objid && oldObjmod == objmod);
 #endif
 
+               currentLastSequence = heap_getattr(oldTuple, 
Anum_gp_fastsequence_last_sequence, tupleDesc, &isNull);
+               if (newLastSequence < currentLastSequence)
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_INTERNAL_ERROR),
+                                        errmsg("gp_fastsequence value 
shouldn't go backwards for AO table"),
+                                        errdetail("current value:" 
INT64_FORMAT " new value:" INT64_FORMAT,
+                                                          currentLastSequence, 
newLastSequence)));
+
                values[Anum_gp_fastsequence_objid - 1] = 
ObjectIdGetDatum(objid);
                values[Anum_gp_fastsequence_objmod - 1] = Int64GetDatum(objmod);
                values[Anum_gp_fastsequence_last_sequence - 1] = 
Int64GetDatum(newLastSequence);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to