Re: [Proposal] Global temporary tables

Wenjing Zeng <wjzeng2012@gmail.com>

From: wenjing <wjzeng2012@gmail.com>
To: Andrew Bille <andrewbille@gmail.com>
Cc: wenjing <wenjing@gmail.com>, Pavel Stehule <pavel.stehule@gmail.com>, Tony Zhu <tony.zhu@ww-it.cn>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2021-10-18T12:00:05Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. PageAddItemExtended(): Add LP_UNUSED assertion.

  2. Remove temporary files after backend crash

  3. Fix comment in indexing.c

  4. Fix failure to ignore leftover temp tables after a server crash.

Attachments

Andrew Bille <andrewbille@gmail.com> 于2021年10月15日周五 下午3:44写道:

> On master with the v55 patches applied the following script leads to crash:
> initdb -D data
> pg_ctl -w -t 5 -D data -l server.log start
>
> psql -t -c "begin; create global temp table gtt_with_index(a int primary
> key, b text); commit; select pg_sleep(5);" >psql1.log &
> psql -t -c "select pg_sleep(1); create index idx_b on gtt_with_index(b);"
> >psql2.log &
> for i in `seq 40`; do (psql -t -c "select pg_sleep(1); insert into
> gtt_with_index values(1,'test');" &); done
>
> sleep 10
>
>
> and I got crash
> INSERT 0 1
> ...
> INSERT 0 1
> server closed the connection unexpectedly
>         This probably means the server terminated abnormally
>         before or while processing the request.
> connection to server was lost
> WARNING:  terminating connection because of crash of another server process
> DETAIL:  The postmaster has commanded this server process to roll back the
> current transaction and exit, because another server process exited
> abnormally and possibly corrupted shared memory.
> HINT:  In a moment you should be able to reconnect to the database and
> repeat your command.
> server closed the connection unexpectedly
>         This probably means the server terminated abnormally
>         before or while processing the request.
> connection to server was lost
>
> and some coredumps with the following stack:
>
> [New LWP 1821493]
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
> Core was generated by `postgres: andrew regression [local] INSERT
>                            '.
> Program terminated with signal SIGABRT, Aborted.
> #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
> 50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
> (gdb) bt
> #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
> #1  0x00007f021d809859 in __GI_abort () at abort.c:79
> #2  0x0000564dc1bd22e8 in ExceptionalCondition
> (conditionName=conditionName@entry=0x564dc1c5c957
> "index->rd_index->indisvalid", errorType=errorType@entry=0x564dc1c2a00b
> "FailedAssertion", fileName=fileName@entry=0x564dc1c5c854
> "storage_gtt.c",
>     lineNumber=lineNumber@entry=1381) at assert.c:69
> #3  0x0000564dc185778b in init_gtt_storage (operation=operation@entry=CMD_INSERT,
> resultRelInfo=resultRelInfo@entry=0x564dc306f6c0) at storage_gtt.c:1381
> #4  0x0000564dc194c888 in ExecInsert (mtstate=0x564dc306f4a8,
> resultRelInfo=0x564dc306f6c0, slot=0x564dc30706d0, planSlot=0x564dc306fca0,
> estate=0x564dc306f230, canSetTag=<optimized out>) at nodeModifyTable.c:638
> #5  0x0000564dc194d945 in ExecModifyTable (pstate=<optimized out>) at
> nodeModifyTable.c:2565
> #6  0x0000564dc191ca83 in ExecProcNode (node=0x564dc306f4a8) at
> ../../../src/include/executor/executor.h:257
> #7  ExecutePlan (execute_once=<optimized out>, dest=0x564dc310ed80,
> direction=<optimized out>, numberTuples=0, sendTuples=<optimized out>,
> operation=CMD_INSERT, use_parallel_mode=<optimized out>,
> planstate=0x564dc306f4a8, estate=0x564dc306f230) at execMain.c:1555
> #8  standard_ExecutorRun (queryDesc=0x564dc306bce0, direction=<optimized
> out>, count=0, execute_once=<optimized out>) at execMain.c:361
> #9  0x0000564dc1ab47a0 in ProcessQuery (plan=<optimized out>,
> sourceText=0x564dc3049a30 "select pg_sleep(1); insert into gtt_with_index
> values(1,'test');", params=0x0, queryEnv=0x0, dest=0x564dc310ed80,
> qc=0x7ffd3a6cf2e0) at pquery.c:160
> #10 0x0000564dc1ab52e2 in PortalRunMulti (portal=portal@entry=0x564dc30acd80,
> isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false,
> dest=dest@entry=0x564dc310ed80, altdest=altdest@entry=0x564dc310ed80,
> qc=qc@entry=0x7ffd3a6cf2e0)
>     at pquery.c:1274
> #11 0x0000564dc1ab5861 in PortalRun (portal=portal@entry=0x564dc30acd80,
> count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true,
> run_once=run_once@entry=true, dest=dest@entry=0x564dc310ed80,
> altdest=altdest@entry=0x564dc310ed80, qc=0x7ffd3a6cf2e0)
>     at pquery.c:788
> #12 0x0000564dc1ab1522 in exec_simple_query (query_string=0x564dc3049a30
> "select pg_sleep(1); insert into gtt_with_index values(1,'test');") at
> postgres.c:1214
> #13 0x0000564dc1ab327a in PostgresMain (dbname=<optimized out>,
> username=<optimized out>) at postgres.c:4497
> #14 0x0000564dc1a1f539 in BackendRun (port=<optimized out>,
> port=<optimized out>) at postmaster.c:4560
> #15 BackendStartup (port=<optimized out>) at postmaster.c:4288
> #16 ServerLoop () at postmaster.c:1801
> #17 0x0000564dc1a2053c in PostmasterMain (argc=<optimized out>,
> argv=0x564dc3043fc0) at postmaster.c:1473
> #18 0x0000564dc1750180 in main (argc=3, argv=0x564dc3043fc0) at main.c:198
> (gdb) q
>
>
> I've built the server using gcc 9 as following:
> ./configure --enable-debug --enable-cassert
>
> Thanks to Alexander Lakhin for simplifying the repro.
>
> On Thu, Oct 14, 2021 at 3:29 PM wenjing zeng <wjzeng2012@gmail.com> wrote:
>
>>
>> Be deeply grateful.
>> Perhaps you can give the stack of problems so that you can start
>> analyzing them as soon as possible.
>>
>> Wenjing
>>
>>
Hi Andrew
I fixed the problem, please confirm again.
Thanks

Wenjing