On Wednesday, August 16, 2023 10:27 PM Tomas Vondra 
<tomas.von...@enterprisedb.com> wrote:

Hi,

> 
> 
> I guess we could update the origin, per attached 0004. We don't have
> timestamp to set replorigin_session_origin_timestamp, but it seems we don't
> need that.
> 
> The attached patch merges the earlier improvements, except for the part that
> experimented with adding a "fake" transaction (which turned out to have a
> number of difficult issues).

I tried to test the patch and found a crash when calling
pg_logical_slot_get_changes() to consume sequence changes.

Steps:
----
create table t1_seq(a int);
create sequence seq1;
SELECT 'init' FROM pg_create_logical_replication_slot('test_slot',
'test_decoding', false, true);
INSERT INTO t1_seq SELECT nextval('seq1') FROM generate_series(1,100);
SELECT data  FROM pg_logical_slot_get_changes('test_slot', NULL, NULL,
'include-xids', 'false', 'skip-empty-xacts', '1');
----

Attach the backtrace in bt.txt.

Best Regards,
Hou zj
(gdb) bt
#0  0x00007fc7fc0ddaff in raise () from /lib64/libc.so.6
#1  0x00007fc7fc0b0ea5 in abort () from /lib64/libc.so.6
#2  0x00007fc7fc120097 in __libc_message () from /lib64/libc.so.6
#3  0x00007fc7fc1274ec in malloc_printerr () from /lib64/libc.so.6
#4  0x00007fc7fc12929c in _int_free () from /lib64/libc.so.6
#5  0x0000000000ba3a9a in AllocSetDelete (context=0x234e820) at aset.c:652
#6  0x0000000000bae6ab in MemoryContextDelete (context=0x234e820) at mcxt.c:437
#7  0x00000000009171e2 in filter_by_origin_cb_wrapper (ctx=0x2356970, 
origin_id=0)
    at logical.c:1234
#8  0x000000000091153b in FilterByOrigin (ctx=0x2356970, origin_id=0) at 
decode.c:583
#9  0x0000000000911d5b in DecodeInsert (ctx=0x2356970, buf=0x7ffd28f1ad70) at 
decode.c:907
#10 0x0000000000911332 in heap_decode (ctx=0x2356970, buf=0x7ffd28f1ad70) at 
decode.c:488
#11 0x0000000000910983 in LogicalDecodingProcessRecord (ctx=0x2356970, 
record=0x2356d08)
    at decode.c:122
#12 0x00000000009192af in pg_logical_slot_get_changes_guts (fcinfo=0x2389380, 
confirm=true,
    binary=false) at logicalfuncs.c:258
#13 0x00000000009193e4 in pg_logical_slot_get_changes (fcinfo=0x2389380)
    at logicalfuncs.c:325
#14 0x0000000000743ab4 in ExecMakeTableFunctionResult (setexpr=0x2373828,
    econtext=0x23736f8, argContext=0x2389280, expectedDesc=0x23341c8, 
randomAccess=false)
    at execSRF.c:235
#15 0x000000000075ed3d in FunctionNext (node=0x23734e8) at nodeFunctionscan.c:95
#16 0x0000000000745312 in ExecScanFetch (node=0x23734e8, accessMtd=0x75ec8b 
<FunctionNext>,
    recheckMtd=0x75f095 <FunctionRecheck>) at execScan.c:132
#17 0x00000000007453b3 in ExecScan (node=0x23734e8, accessMtd=0x75ec8b 
<FunctionNext>,
    recheckMtd=0x75f095 <FunctionRecheck>) at execScan.c:198
#18 0x000000000075f0df in ExecFunctionScan (pstate=0x23734e8) at 
nodeFunctionscan.c:270
#19 0x0000000000741324 in ExecProcNodeFirst (node=0x23734e8) at 
execProcnode.c:464
#20 0x000000000073503c in ExecProcNode (node=0x23734e8)
    at ../../../src/include/executor/executor.h:273
#21 0x0000000000737ca7 in ExecutePlan (estate=0x23732c0, planstate=0x23734e8,
    use_parallel_mode=false, operation=CMD_SELECT, sendTuples=true, 
numberTuples=0,
    direction=ForwardScanDirection, dest=0x2330518, execute_once=true) at 
execMain.c:1670
#22 0x0000000000735682 in standard_ExecutorRun (queryDesc=0x2365020,
    direction=ForwardScanDirection, count=0, execute_once=true) at 
execMain.c:365
#23 0x00000000007354bf in ExecutorRun (queryDesc=0x2365020, 
direction=ForwardScanDirection,
    count=0, execute_once=true) at execMain.c:309
#24 0x00000000009bfc7e in PortalRunSelect (portal=0x22df3c0, forward=true, 
count=0,
    dest=0x2330518) at pquery.c:924
#25 0x00000000009bf93b in PortalRun (portal=0x22df3c0, 
count=9223372036854775807,
    isTopLevel=true, run_once=true, dest=0x2330518, altdest=0x2330518, 
qc=0x7ffd28f1b550)
    at pquery.c:768
#26 0x00000000009b94c4 in exec_simple_query (
    query_string=0x2264410 "SELECT data  FROM 
pg_logical_slot_get_changes('test_slot', NULL, NULL,\n'include-xids', 'false', 
'skip-empty-xacts', '1');") at postgres.c:1274
#27 0x00000000009bdb31 in PostgresMain (dbname=0x229d240 "postgres",
    username=0x229d228 "houzj") at postgres.c:4637
#28 0x00000000008f27ef in BackendRun (port=0x2293650) at postmaster.c:4433
#29 0x00000000008f2185 in BackendStartup (port=0x2293650) at postmaster.c:4161
#30 0x00000000008eebff in ServerLoop () at postmaster.c:1778
#31 0x00000000008ee5cf in PostmasterMain (argc=3, argv=0x225d690) at 
postmaster.c:1462

Reply via email to