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

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

commit 1a56de3f07d6e95ddcaf04dbd51a8c7484cc422a
Author: Adam Lee <[email protected]>
AuthorDate: Mon Nov 28 15:33:01 2022 +0800

    Ensure that an active outer snapshot exists prior to executing SPI
    
    "795278996fc - Fix the test extension to execute SQL code inside of a 
Portal"
    (#14515) "fixed" it but also failed an assertion, this commit fixes it in
    another way as the pgsql-hackers suggests.
    
    Ref: 
https://www.mail-archive.com/[email protected]/msg95584.html
    
            commit 41c6a5bec25e720d98bd60d77dd5c2939189ed3c
            Author: Tom Lane <[email protected]>
            Date:   Fri May 21 14:03:53 2021 -0400
    
                Restore the portal-level snapshot after procedure 
COMMIT/ROLLBACK.
    
    And quote the release note:
    
    > Some extensions may attempt to execute SQL code outside of any Portal.
    > They are responsible for ensuring that an outer snapshot exists before
    > doing so. Previously, not providing a snapshot might work or it might
    > not; now it will consistently fail with “cannot execute SQL without an
    > outer snapshot or portal”.
---
 src/test/fdw/.gitignore                                    |  2 ++
 src/test/fdw/extension/extended_protocol_commit_test_fdw.c | 13 ++++---------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/test/fdw/.gitignore b/src/test/fdw/.gitignore
new file mode 100644
index 0000000000..47b955c13c
--- /dev/null
+++ b/src/test/fdw/.gitignore
@@ -0,0 +1,2 @@
+extended_protocol_commit_test
+results/
diff --git a/src/test/fdw/extension/extended_protocol_commit_test_fdw.c 
b/src/test/fdw/extension/extended_protocol_commit_test_fdw.c
index 7940a05190..069d635aa5 100644
--- a/src/test/fdw/extension/extended_protocol_commit_test_fdw.c
+++ b/src/test/fdw/extension/extended_protocol_commit_test_fdw.c
@@ -16,7 +16,7 @@
 #include "optimizer/pathnode.h"
 #include "optimizer/planmain.h"
 #include "optimizer/restrictinfo.h"
-#include "tcop/pquery.h"
+#include "utils/snapmgr.h"
 
 #ifdef PG_MODULE_MAGIC
 PG_MODULE_MAGIC;
@@ -34,10 +34,7 @@ test_execute_spi_expression(const char *query)
 {
        int                     r;
 
-       /* Set up the global portal */
-       Portal saveActivePortal = ActivePortal;
-
-       ActivePortal = CreateNewPortal();
+       PushActiveSnapshot(GetTransactionSnapshot());
 
        PG_TRY();
        {
@@ -52,8 +49,7 @@ test_execute_spi_expression(const char *query)
        {
                SPI_finish();
 
-               /* Restore the global portal */
-               ActivePortal = saveActivePortal;
+               PopActiveSnapshot();
 
                PG_RE_THROW();
        }
@@ -61,8 +57,7 @@ test_execute_spi_expression(const char *query)
 
        SPI_finish();
 
-       /* Restore the global portal */
-       ActivePortal = saveActivePortal;
+       PopActiveSnapshot();
 }
 
 static void


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

Reply via email to