Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

yb_foreign_key SEGFAULT #273

Closed
jfunston opened this issue Jun 14, 2021 · 12 comments · Fixed by #283
Closed

yb_foreign_key SEGFAULT #273

jfunston opened this issue Jun 14, 2021 · 12 comments · Fixed by #283
Labels
bug Something isn't working must_have

Comments

@jfunston
Copy link
Contributor

No description provided.

@jfunston jfunston added bug Something isn't working must_have labels Jun 14, 2021
@johnfangAFW
Copy link
Contributor

2021-06-24 16:48:51.970 UTC [8674] LOG: statement: INSERT INTO FKTABLE VALUES (2, 3);
Segmentation fault.
Backtrace:
0x0000000000c79d1c
0x0000000000c40ec0
0x0000000000c411c2
0x0000000000c41232
0x00002975024213bf
0x000000000050c871
0x00002975023382bb
/build/build/src/k2/connector/entities/libk2pgentities.so.1+0x00000000000240b4
0x0000000000ae3e05
0x0000000000a6a7d4
0x0000000000a64498
0x0000000000927722
0x0000000000928c32
0x000000000092adf9
0x00000000005fb23b
0x00000000005fcb69
0x00000000005fd175
0x0000000000603d9b
0x000000000063067f
0x00000000006306ae
0x00000000008616c2
0x00000000008618af
0x0000000000862824
0x000000000085d3e2
0x000000000085d70c
0x0000000000860141
0x00000000007bfce3
0x00000000007c3baf
0x00000000007c3ec5
0x00000000007c59cd
0x0000000000694337
0x0000000000697f97
/lib/x86_64-linux-gnu/libc.so.6+0x00000000000270b2
0x00000000003e959d

@johnfangAFW
Copy link
Contributor

[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: postgres postgres 127.0.0.1(35202) INSERT '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 K2SqlDatumToBinary (datum=0, data=0x7ffc00d32518, bytes=0x7ffc00d32520) at /build/src/k2/postgres/src/backend/catalog/ybctype.c:240
240 data = VARDATA_ANY(datum);
[Current thread is 1 (Thread 0x7f6fd88fed80 (LWP 8674))]
(gdb) bt
#0 K2SqlDatumToBinary (datum=0, data=0x7ffc00d32518, bytes=0x7ffc00d32520) at /build/src/k2/postgres/src/backend/catalog/ybctype.c:240
#1 0x00007f6fda8d42bc in k2pg::sql::SqlValue::SqlValue (this=0x55fada0a3800, type_entity=0x55fad99d11c8 <K2SqlTypeEntityTable+40>, datum=,
is_null=) at /build/src/k2/connector/entities/value.cc:154
#2 0x00007f6fda8c40b5 in k2pg::sql::PgConstant::PgConstant (this=0x55fada0a37e0, type_entity=0x55fad99d11c8 <K2SqlTypeEntityTable+40>, datum=0,
is_null=, opcode=) at /build/src/k2/connector/entities/expr.cc:130
#3 0x000055fad907fe06 in std::make_unique<k2pg::sql::PgConstant, PgTypeEntity const
const&, unsigned long const&, bool> () at /usr/include/c++/9/bits/unique_ptr.h:856
#4 k2pg::gate::PgDml::BuildPgTupleId[abi:cxx11](PgAttrValueDescriptor const*, int) (this=0x55fada9a5200, attrs=0x55fada953460, nattrs=)
at /build/src/k2/connector/pggate/pg_dml.cc:373
#5 0x000055fad90067d5 in k2pg::gate::PgGateApiImpl::DmlBuildPgTupleId (this=0x55fad9f6bd40, handle=, attrs=attrs@entry=0x55fada953460,
nattrs=nattrs@entry=2, k2pgctid=k2pgctid@entry=0x7ffc00d32888) at /build/src/k2/connector/pggate/pg_gate_impl.cc:683
#6 0x000055fad9000499 in k2pg::gate::PgGate_DmlBuildPgTupleId (handle=, attrs=attrs@entry=0x55fada953460, nattrs=nattrs@entry=2,
k2pgctid=k2pgctid@entry=0x7ffc00d32888) at /build/src/k2/connector/pggate/pg_gate_api.cc:618
#7 0x000055fad8ec3723 in BuildPgTupleId (pk_rel=pk_rel@entry=0x7f6fd428da78, fk_rel=fk_rel@entry=0x7f6fd428eff8, idx_rel=0x7f6fd428ea00,
riinfo=riinfo@entry=0x55fada40b8c8, tup=tup@entry=0x55fadae8ba90, value=value@entry=0x7ffc00d32928, bytes=0x7ffc00d32930)
at /build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:2751
#8 0x000055fad8ec4c33 in RI_FKey_check (trigdata=) at /build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:417
#9 0x000055fad8ec6dfa in RI_FKey_check_ins (fcinfo=0x7ffc00d32d30) at /build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:527
#10 0x000055fad8b9723c in ExecCallTriggerFunc (trigdata=trigdata@entry=0x7ffc00d33190, tgindx=tgindx@entry=0, finfo=finfo@entry=0x55fadae8a938, instr=instr@entry=0x0,
per_tuple_context=per_tuple_context@entry=0x55fada952c00) at /build/src/k2/postgres/src/backend/commands/trigger.c:2413
#11 0x000055fad8b98b6a in AfterTriggerExecute (event=event@entry=0x55fada995f80, rel=rel@entry=0x7f6fd428eff8, trigdesc=trigdesc@entry=0x55fadae8a758,
finfo=finfo@entry=0x55fadae8a938, instr=instr@entry=0x0, per_tuple_context=per_tuple_context@entry=0x55fada952c00, trig_tuple_slot1=0x55fadae8b860,
trig_tuple_slot2=0x55fadae8b978) at /build/src/k2/postgres/src/backend/commands/trigger.c:4393
#12 0x000055fad8b99176 in afterTriggerInvokeEvents (events=events@entry=0x55fada0518f0, firing_id=1, estate=estate@entry=0x55fadae8a3f0, delete_ok=delete_ok@entry=false)
at /build/src/k2/postgres/src/backend/commands/trigger.c:4589
#13 0x000055fad8b9fd9c in AfterTriggerEndQuery (estate=estate@entry=0x55fadae8a3f0) at /build/src/k2/postgres/src/backend/commands/trigger.c:4900
#14 0x000055fad8bcc680 in standard_ExecutorFinish (queryDesc=0x55fad9f11950) at /build/src/k2/postgres/src/backend/executor/execMain.c:441
#15 0x000055fad8bcc6af in ExecutorFinish (queryDesc=queryDesc@entry=0x55fad9f11950) at /build/src/k2/postgres/src/backend/executor/execMain.c:409
#16 0x000055fad8dfd6c3 in ProcessQuery (plan=plan@entry=0x55fada146518, sourceText=0x55fad9ef1190 "INSERT INTO FKTABLE VALUES (2, 3);", params=,
queryEnv=0x0, dest=dest@entry=0x55fada146690, completionTag=completionTag@entry=0x7ffc00d335a0 "INSERT 0 1", isSingleRowModifyTxn=true)
at /build/src/k2/postgres/src/backend/tcop/pquery.c:215
#17 0x000055fad8dfd8b0 in PortalRunMulti (portal=portal@entry=0x55fad9f67000, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false,
dest=dest@entry=0x55fada146690, altdest=altdest@entry=0x55fada146690, completionTag=completionTag@entry=0x7ffc00d335a0 "INSERT 0 1")
at /build/src/k2/postgres/src/backend/tcop/pquery.c:1306
#18 0x000055fad8dfe825 in PortalRun (portal=portal@entry=0x55fad9f67000, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true,
run_once=run_once@entry=true, dest=dest@entry=0x55fada146690, altdest=altdest@entry=0x55fada146690, completionTag=0x7ffc00d335a0 "INSERT 0 1")
at /build/src/k2/postgres/src/backend/tcop/pquery.c:809
#19 0x000055fad8df93e3 in exec_simple_query (query_string=query_string@entry=0x55fad9ef1190 "INSERT INTO FKTABLE VALUES (2, 3);")
at /build/src/k2/postgres/src/backend/tcop/postgres.c:1160
#20 0x000055fad8df970d in k2pg_exec_simple_query_attempting_to_restart_read (query_string=query_string@entry=0x55fad9ef1190 "INSERT INTO FKTABLE VALUES (2, 3);",
exec_context=exec_context@entry=0x55fad9ef1070) at /build/src/k2/postgres/src/backend/tcop/postgres.c:4237
#21 0x000055fad8dfc142 in PostgresMain (argc=, argv=argv@entry=0x55fad9eee0c0, dbname=, username=0x55fad9eedef0 "postgres")
at /build/src/k2/postgres/src/backend/tcop/postgres.c:4838
#22 0x000055fad8d5bce4 in BackendRun (port=port@entry=0x55fad9f13180) at /build/src/k2/postgres/src/backend/postmaster/postmaster.c:4444
#23 0x000055fad8d5fbb0 in BackendStartup (port=port@entry=0x55fad9f13180) at /build/src/k2/postgres/src/backend/postmaster/postmaster.c:4097
#24 0x000055fad8d5fec6 in ServerLoop () at /build/src/k2/postgres/src/backend/postmaster/postmaster.c:1740
#25 0x000055fad8d619ce in PostmasterMain (argc=argc@entry=7, argv=argv@entry=0x55fad9ee8480) at /build/src/k2/postgres/src/backend/postmaster/postmaster.c:1402
#26 0x000055fad8c30338 in PostgresServerProcessMain (argc=7, argv=0x55fad9ee8480) at /build/src/k2/postgres/src/backend/main/main.c:234
#27 0x000055fad8c33f98 in main () at /usr/include/c++/9/bits/stl_deque.h:273

@johnfangAFW
Copy link
Contributor

echo " 0x0000000000ae3e05

0x0000000000a6a7d4
0x0000000000a64498
0x0000000000927722
0x0000000000928c32
0x000000000092adf9
0x00000000005fb23b
0x00000000005fcb69
0x00000000005fd175
0x0000000000603d9b
0x000000000063067f
0x> 00000000006306ae
0x00000000008616c2
0x00000000008618af
0x0000000000862824
0x000000000085d3e2
0x000000000085d70c
0x0000000000860141
0x00000000007bf> ce3
0x00000000007c3baf
0x00000000007c3ec5
0x0000> 0000007c59cd
0x0000000000694337
0x00000000006> > > > > > > > > > > > > > > > > > > > > > > 97f97" | addr2line -e /build/src/k2/postgres/bin/postgres
/usr/include/c++/9/bits/unique_ptr.h:857
/build/src/k2/connector/pggate/pg_gate_impl.cc:683 (discriminator 4)
/build/src/k2/connector/pggate/pg_gate_api.cc:618
/build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:2751
/build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:417 (discriminator 4)
/build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:527
/build/src/k2/postgres/src/backend/commands/trigger.c:2413 (discriminator 3)
/build/src/k2/postgres/src/backend/commands/trigger.c:4393
/build/src/k2/postgres/src/backend/commands/trigger.c:4589 (discriminator 5)
/build/src/k2/postgres/src/backend/commands/trigger.c:4900
/build/src/k2/postgres/src/backend/executor/execMain.c:441
??:0
/build/src/k2/postgres/src/backend/tcop/pquery.c:215
/build/src/k2/postgres/src/backend/tcop/pquery.c:1306
/build/src/k2/postgres/src/backend/tcop/pquery.c:809
/build/src/k2/postgres/src/backend/tcop/postgres.c:1160
/build/src/k2/postgres/src/backend/tcop/postgres.c:4237 (discriminator 3)
/build/src/k2/postgres/src/backend/tcop/postgres.c:4838
/usr/include/c++/9/bits/stl_deque.h:760
/build/src/k2/postgres/src/backend/postmaster/postmaster.c:4097
/build/src/k2/postgres/src/backend/postmaster/postmaster.c:1740
??:0
/build/src/k2/postgres/src/backend/main/main.c:234
??:?

@johnfangAFW
Copy link
Contributor

johnfangAFW commented Jun 24, 2021

The following line of code caused the issue:

Status PgGateApiImpl::DmlBuildPgTupleId(PgStatement *handle, const PgAttrValueDescriptor *attrs,
int32_t nattrs, uint64_t k2pgctid) {
const string id = VERIFY_RESULT(dynamic_cast<PgDml>(handle)->BuildPgTupleId(attrs, nattrs));

const K2PgTypeEntity *type_entity = FindTypeEntity(kPgByteArrayOid);
k2pgctid = type_entity->k2pg_to_datum(id.data(), id.size(), nullptr / type_attrs */);
return Status::OK();
}

@johnfangAFW
Copy link
Contributor

(gdb) up
#5 0x000055fad90067d5 in k2pg::gate::PgGateApiImpl::DmlBuildPgTupleId (this=0x55fad9f6bd40, handle=, attrs=attrs@entry=0x55fada953460,
nattrs=nattrs@entry=2, k2pgctid=k2pgctid@entry=0x7ffc00d32888) at /build/src/k2/connector/pggate/pg_gate_impl.cc:683
683 const string id = VERIFY_RESULT(dynamic_cast<PgDml*>(handle)->BuildPgTupleId(attrs, nattrs));
(gdb) p attrs
$4 = (const PgAttrValueDescriptor *) 0x55fada953460
(gdb) p *attrs
$5 = {attr_num = -102, datum = 2, is_null = false, type_entity = 0x55fad99d12b8 <K2SqlTypeEntityTable+280>}
(gdb) p nattrs
$6 = 2
(gdb) p *attrs@1
$7 = {{attr_num = -102, datum = 2, is_null = false, type_entity = 0x55fad99d12b8 <K2SqlTypeEntityTable+280>}}
(gdb) p *attrs@2
$8 = {{attr_num = -102, datum = 2, is_null = false, type_entity = 0x55fad99d12b8 <K2SqlTypeEntityTable+280>}, {attr_num = 1, datum = 0, is_null = true,
type_entity = 0x55fad99d11c8 <K2SqlTypeEntityTable+40>}}

@johnfangAFW
Copy link
Contributor

tests:

-- FOREIGN KEY (YB-added tests)

--
-- MATCH FULL

-- First test, check and cascade

CREATE TABLE ITABLE ( ptest1 int, ptest2 text );
CREATE UNIQUE INDEX ITABLE_IDX ON ITABLE(ptest1);
CREATE TABLE FKTABLE ( ftest1 int REFERENCES ITABLE(ptest1) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE, ftest2 int );
-- Insert test data into ITABLE
INSERT INTO ITABLE VALUES (1, 'Test1');
INSERT INTO ITABLE VALUES (2, 'Test2');
INSERT INTO ITABLE VALUES (3, 'Test3');
INSERT INTO ITABLE VALUES (4, 'Test4');
INSERT INTO ITABLE VALUES (5, 'Test5');
-- Insert successful rows into FK TABLE
INSERT INTO FKTABLE VALUES (1, 2);
INSERT INTO FKTABLE VALUES (2, 3); <-- failed

@johnfangAFW
Copy link
Contributor

After fix the null value flag in pg_dml.cc:373 as

      std::unique_ptr<PgConstant> pg_const = std::make_unique<PgConstant>(attr->type_entity, attr->datum, attr->is_null);

we ran into a schema mismatch issue while running "INSERT INTO FKTABLE VALUES (1, 2);"

terminate called after throwing an instance of 'k2::dto::TypeMismatchException'
what(): Schema not followed in record serialization’

@johnfangAFW
Copy link
Contributor

stack trace:

[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: postgres postgres 127.0.0.1(35658) 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.
[Current thread is 1 (Thread 0x7f253a981d80 (LWP 8726))]
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007f253b9a292e in __GI_abort () at abort.c:100
#2 0x00007f253bd79951 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007f253bd8547c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007f253bd854e7 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007f253bd85799 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x000055f5bc15d802 in k2::dto::SKVRecord::serializeNext (this=this@entry=0x7ffdae084560, field=)
at /usr/local/include/seastar/core/sstring.hh:197
#7 0x000055f5bc16515c in k2pg::gate::K2Adapter::SerializeValueToSKVRecord (value=..., record=...) at /build/src/k2/connector/pggate/k2_adapter.cc:1038
#8 0x000055f5bc16a66b in k2pg::gate::K2Adapter::GetRowId (this=, collection_name=...,
schema_name='0' <repeats 12 times>, "30008", '0' <repeats 11 times>, "4245", schema_version=, base_table_oid=16960, index_oid=16965,
key_values=std::vector of length 2, capacity 2 = {...}) at /build/src/k2/connector/pggate/k2_adapter.cc:998
#9 0x000055f5bc183f16 in k2pg::gate::PgSession::GetRowId (key_values=std::vector of length 2, capacity 2 = {...}, index_oid=,
base_table_oid=, schema_version=, table_id=..., database_id=..., this=)
at /usr/include/c++/9/bits/shared_ptr_base.h:1020
#10 k2pg::gate::PgDml::BuildPgTupleId[abi:cxx11](PgAttrValueDescriptor const*, int) (this=0x55f5bd8c5860, attrs=0x55f5bd0383d0, nattrs=)
at /build/src/k2/connector/pggate/pg_dml.cc:382
#11 0x000055f5bc10a7d5 in k2pg::gate::PgGateApiImpl::DmlBuildPgTupleId (this=0x55f5bceb4d40, handle=, attrs=attrs@entry=0x55f5bd0383d0,
nattrs=nattrs@entry=2, k2pgctid=k2pgctid@entry=0x7ffdae0848e8) at /build/src/k2/connector/pggate/pg_gate_impl.cc:683
#12 0x000055f5bc104499 in k2pg::gate::PgGate_DmlBuildPgTupleId (handle=, attrs=attrs@entry=0x55f5bd0383d0, nattrs=nattrs@entry=2,
k2pgctid=k2pgctid@entry=0x7ffdae0848e8) at /build/src/k2/connector/pggate/pg_gate_api.cc:618
#13 0x000055f5bbfc7723 in BuildPgTupleId (pk_rel=pk_rel@entry=0x7f252a526ea8, fk_rel=fk_rel@entry=0x7f252a528428, idx_rel=0x7f252a527e30,
riinfo=riinfo@entry=0x55f5bd340508, tup=tup@entry=0x55f5bd03de30, value=value@entry=0x7ffdae084988, bytes=0x7ffdae084990)
at /build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:2751
#14 0x000055f5bbfc8c33 in RI_FKey_check (trigdata=) at /build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:417
#15 0x000055f5bbfcadfa in RI_FKey_check_ins (fcinfo=0x7ffdae084d90) at /build/src/k2/postgres/src/backend/utils/adt/ri_triggers.c:527
#16 0x000055f5bbc9b23c in ExecCallTriggerFunc (trigdata=trigdata@entry=0x7ffdae0851f0, tgindx=tgindx@entry=0, finfo=finfo@entry=0x55f5bd03ccd8, instr=instr@entry=0x0,
per_tuple_context=per_tuple_context@entry=0x55f5bd037b70) at /build/src/k2/postgres/src/backend/commands/trigger.c:2413
#17 0x000055f5bbc9cb6a in AfterTriggerExecute (event=event@entry=0x55f5bd2466a0, rel=rel@entry=0x7f252a528428, trigdesc=trigdesc@entry=0x55f5bd03caf8,
finfo=finfo@entry=0x55f5bd03ccd8, instr=instr@entry=0x0, per_tuple_context=per_tuple_context@entry=0x55f5bd037b70, trig_tuple_slot1=0x55f5bd03dc00,
trig_tuple_slot2=0x55f5bd03dd18) at /build/src/k2/postgres/src/backend/commands/trigger.c:4393
#18 0x000055f5bbc9d176 in afterTriggerInvokeEvents (events=events@entry=0x55f5bcf87a90, firing_id=1, estate=estate@entry=0x55f5bd03c790, delete_ok=delete_ok@entry=false)
at /build/src/k2/postgres/src/backend/commands/trigger.c:4589
#19 0x000055f5bbca3d9c in AfterTriggerEndQuery (estate=estate@entry=0x55f5bd03c790) at /build/src/k2/postgres/src/backend/commands/trigger.c:4900
#20 0x000055f5bbcd0680 in standard_ExecutorFinish (queryDesc=0x55f5bce5a950) at /build/src/k2/postgres/src/backend/executor/execMain.c:441
#21 0x000055f5bbcd06af in ExecutorFinish (queryDesc=queryDesc@entry=0x55f5bce5a950) at /build/src/k2/postgres/src/backend/executor/execMain.c:409
#22 0x000055f5bbf016c3 in ProcessQuery (plan=plan@entry=0x55f5bd8c50c0, sourceText=0x55f5bce3a190 "INSERT INTO FKTABLE VALUES (2, 3);", params=,
queryEnv=0x0, dest=dest@entry=0x55f5bcfcfab8, completionTag=completionTag@entry=0x7ffdae085600 "INSERT 0 1", isSingleRowModifyTxn=true)
at /build/src/k2/postgres/src/backend/tcop/pquery.c:215
#23 0x000055f5bbf018b0 in PortalRunMulti (portal=portal@entry=0x55f5bceb0000, isTopLevel=isTopLevel@entry=true, setHoldSnapshot=setHoldSnapshot@entry=false,
dest=dest@entry=0x55f5bcfcfab8, altdest=altdest@entry=0x55f5bcfcfab8, completionTag=completionTag@entry=0x7ffdae085600 "INSERT 0 1")
at /build/src/k2/postgres/src/backend/tcop/pquery.c:1306
#24 0x000055f5bbf02825 in PortalRun (portal=portal@entry=0x55f5bceb0000, count=count@entry=9223372036854775807, isTopLevel=isTopLevel@entry=true,
run_once=run_once@entry=true, dest=dest@entry=0x55f5bcfcfab8, altdest=altdest@entry=0x55f5bcfcfab8, completionTag=0x7ffdae085600 "INSERT 0 1")
at /build/src/k2/postgres/src/backend/tcop/pquery.c:809
#25 0x000055f5bbefd3e3 in exec_simple_query (query_string=query_string@entry=0x55f5bce3a190 "INSERT INTO FKTABLE VALUES (2, 3);")
at /build/src/k2/postgres/src/backend/tcop/postgres.c:1160
#26 0x000055f5bbefd70d in k2pg_exec_simple_query_attempting_to_restart_read (query_string=query_string@entry=0x55f5bce3a190 "INSERT INTO FKTABLE VALUES (2, 3);",
exec_context=exec_context@entry=0x55f5bce3a070) at /build/src/k2/postgres/src/backend/tcop/postgres.c:4237
#27 0x000055f5bbf00142 in PostgresMain (argc=, argv=argv@entry=0x55f5bce36c98, dbname=, username=0x55f5bce36ac8 "postgres")
at /build/src/k2/postgres/src/backend/tcop/postgres.c:4838
#28 0x000055f5bbe5fce4 in BackendRun (port=port@entry=0x55f5bce5c180) at /build/src/k2/postgres/src/backend/postmaster/postmaster.c:4444
#29 0x000055f5bbe63bb0 in BackendStartup (port=port@entry=0x55f5bce5c180) at /build/src/k2/postgres/src/backend/postmaster/postmaster.c:4097
#30 0x000055f5bbe63ec6 in ServerLoop () at /build/src/k2/postgres/src/backend/postmaster/postmaster.c:1740
#31 0x000055f5bbe659ce in PostmasterMain (argc=argc@entry=7, argv=argv@entry=0x55f5bce31480) at /build/src/k2/postgres/src/backend/postmaster/postmaster.c:1402
#32 0x000055f5bbd34338 in PostgresServerProcessMain (argc=7, argv=0x55f5bce31480) at /build/src/k2/postgres/src/backend/main/main.c:234
#33 0x000055f5bbd37f98 in main () at /usr/include/c++/9/bits/stl_deque.h:273

@johnfangAFW
Copy link
Contributor

Debug info:

(gdb) up
#7 0x000055f5bc16515c in k2pg::gate::K2Adapter::SerializeValueToSKVRecord (value=..., record=...) at /build/src/k2/connector/pggate/k2_adapter.cc:1038
1038 record.serializeNext<int64_t>(value.data_.int_val_);
(gdb) p record
$11 = (k2::dto::SKVRecord &) @0x7ffdae084560: {schema = std::shared_ptrk2::dto::Schema (use count 3, weak count 0) = {get() = 0x6010003f8a20}, collectionName = {u = {
external = {str = 0x55f5bdc10bb0 "00004239000030008", '0' <repeats 15 times>, size = 32, pad = -11 '\365'}, internal = {
str = "\260\v\301\275\365U\000\000 \000\000\000\365U", size = -1 '\377'}}, static npos = }, storage = {
excludedFields = std::vector of length 5, capacity 64 = {false, false, true, false, false}, fieldData = {_buffers = std::vector of length 1, capacity 1 = {{
_buffer = 0x55f5bd030980 "@b", _size = 8192, _deleter = {_impl = 0x55f5bd030981}}}, _size = 16, _capacity = 8192,
_allocator = {<std::_Maybe_unary_or_binary_function<seastar::temporary_buffer >> = {}, std::_Function_base = {static _M_max_size = 16,
static _M_max_align = 8, _M_functor = {_M_unused = {_M_object = 0x55f5bc2419a0 k2::Payload::DefaultAllocator(),
_M_const_object = 0x55f5bc2419a0 k2::Payload::DefaultAllocator(), _M_function_pointer = 0x55f5bc2419a0 k2::Payload::DefaultAllocator(),
_M_member_pointer = (void (std::_Undefined_class::)(std::_Undefined_class * const)) 0x55f5bc2419a0 k2::Payload::DefaultAllocator(), this adjustment 94510755348680}, _M_pod_data = "\240\031$\274\365U\000\000\310\000\000\000\365U\000"},
_M_manager = 0x55f5bc15aff0 <std::_Function_base::_Base_manager<seastar::temporary_buffer (
)()>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation)>},
_M_invoker = 0x55f5bc15afb0 <std::_Function_handler<seastar::temporary_buffer (), seastar::temporary_buffer (*)()>::_M_invoke(std::_Any_data const&)>}, _currentPosition = {bufferIndex = 0, bufferOffset = 16, offset = 16}}, schemaVersion = 0}, partitionKeys = std::vector of length 4, capacity 4 = {{u = {external = {
str = 0x304 <error: Cannot access memory at address 0x304>, size = 16793666, pad = 0 '\000'}, internal = {
str = "\004\003\000\000\000\000\000\000B@\000\001\000U", size = 12 '\f'}}, static npos = }, {u = {external = {
str = 0x304 <error: Cannot access memory at address 0x304>, size = 16794946, pad = 0 '\000'}, internal = {
str = "\004\003\000\000\000\000\000\000BE\000\001\000U", size = 12 '\f'}}, static npos = }, {u = {external = {
str = 0x10000 <error: Cannot access memory at address 0x10000>, size = 428997888, pad = -26 '\346'}, internal = {
str = "\000\000\001\000\000\000\000\000\000\375\221\031\346/'", size = 3 '\003'}}, static npos = }, {u = {external = {str = 0x0,
size = 3170658305, pad = -11 '\365'}, internal = {str = "\000\000\000\000\000\000\000\000\001h\374\274\365U", size = 0 '\000'}},
static npos = }}, rangeKeys = std::vector of length 0, capacity 0, fieldCursor = 3, keyValuesAvailable = true, keyStringsConstructed = true}
(gdb) p record->schema
$13 = std::shared_ptrk2::dto::Schema (use count 3, weak count 0) = {get() = 0x6010003f8a20}
(gdb) p *record->schema
$14 = {name = {u = {external = {str = 0x6010003fc1b0 '0' <repeats 12 times>, "30008", '0' <repeats 11 times>, "4245", size = 32, pad = 0 '\000'}, internal = {
str = "\260\301?\000\020\000\000 \000\000\000\000\000", size = -1 '\377'}}, static npos = <optimized out>}, version = 0, fields = std::vector of length 5, capacity 5 = {{type = k2::dto::FieldType::INT64T, name = {u = {external = { str = 0x6449656c626154 <error: Cannot access memory at address 0x6449656c626154>, size = 0, pad = 0 '\000'}, internal = { str = "TableId\000\000\000\000\000\000\000", size = 7 '\a'}}, static npos = <optimized out>}, descending = false, nullLast = false}, { type = k2::dto::FieldType::INT64T, name = {u = {external = {str = 0x64497865646e49 <error: Cannot access memory at address 0x64497865646e49>, size = 0, pad = 0 '\000'}, internal = {str = "IndexId\000\000\000\000\000\000\000", size = 7 '\a'}}, static npos = <optimized out>}, descending = false, nullLast = false}, {type = k2::dto::FieldType::INT64T, name = {u = {external = {str = 0x317473657470 <error: Cannot access memory at address 0x317473657470>, size = 0, pad = 0 '\000'}, internal = {str = "ptest1\000\000\000\000\000\000\000\000", size = 6 '\006'}}, static npos = <optimized out>}, descending = false, nullLast = false}, {type = k2::dto::FieldType::STRING, name = {u = {external = {str = 0x6010003d9880 "k2pguniqueidxkeysuffix", size = 22, pad = 0 '\000'}, internal = {str = "\200\230=\000\020\000\000\026\000\000\000\000\000", size = -1 '\377'}}, static npos = },
descending = false, nullLast = false}, {type = k2::dto::FieldType::STRING, name = {u = {external = {str = 0x6010003e6bb0 "k2pgidxbasectid", size = 15,
pad = 0 '\000'}, internal = {str = "\260k>\000\020`\000\000\017\000\000\000\000\000", size = -1 '\377'}}, static npos = },
descending = false, nullLast = false}}, partitionKeyFields = std::vector of length 4, capacity 4 = {0, 1, 2, 3},
rangeKeyFields = std::vector of length 0, capacity 0}

@johnfangAFW
Copy link
Contributor

branch foreign-key-validation-issue

@johnfangAFW
Copy link
Contributor

CREATE TABLE ITABLE ( ptest1 int, ptest2 text );

[0001:03:42:11.669.921]-k2_pg-[139635505937792]-(k2::pg_catalog) [DEBUG] [/build/src/k2/connector/pggate/catalog/sql_catalog_manager.cc:553 @createtable] Creating table ns name: postgres, ns oid: 12456, table name: itable, table oid: 16384, systable: false, shared: false
[0001:03:46:47.202.134]-k2_pg-[0]-(k2::pg_seastar) [INFO] [/build/src/k2/connector/pggate/k2_seastar_app.cc:177 @operator()] Schema create... {collectionName=000030a8000030008000000000000000, schema={name=00000000000030008000000000004004, version=0, fields={
{type=INT64T, name=TableId, descending=false, nullLast=false},
{type=INT64T, name=IndexId, descending=false, nullLast=false},
{type=STRING, name=k2pgrowid, descending=false, nullLast=false},
{type=INT64T, name=ftest1, descending=false, nullLast=false},
{type=INT64T, name=ftest2, descending=false, nullLast=false}},
partitionKeyFields={0, 1, 2}, rangeKeyFields={}}}

CREATE UNIQUE INDEX ITABLE_IDX ON ITABLE(ptest1);
I20210624 21:40:10.978925 189 ybccmds.c:514] Creating index postgres.public.itable_idx
[0001:03:44:18.701.332]-k2_pg-[139635505937792]-(k2::pg_catalog) [DEBUG] [/build/src/k2/connector/pggate/catalog/sql_catalog_manager.cc:631 @CreateIndexTable] Creating index ns name: postgres, ns oid: 12456, index name: itable_idx, index oid: 16387, base table oid: 16384
[0001:03:46:47.202.134]-k2_pg-[0]-(k2::pg_seastar) [INFO] [/build/src/k2/connector/pggate/k2_seastar_app.cc:177 @operator()] Schema create... {collectionName=000030a8000030008000000000000000, schema={name=00000000000030008000000000004004, version=0, fields={
{type=INT64T, name=TableId, descending=false, nullLast=false},
{type=INT64T, name=IndexId, descending=false, nullLast=false},
{type=STRING, name=k2pgrowid, descending=false, nullLast=false},
{type=INT64T, name=ftest1, descending=false, nullLast=false},
{type=INT64T, name=ftest2, descending=false, nullLast=false}},
partitionKeyFields={0, 1, 2}, rangeKeyFields={}}}

CREATE TABLE FKTABLE ( ftest1 int REFERENCES ITABLE(ptest1) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE, ftest2 int );
I20210624 21:42:39.303889 189 ybccmds.c:311] Creating Table postgres.public.fktable
[0001:03:46:47.196.293]-k2_pg-[139635505937792]-(k2::pg_catalog) [DEBUG] [/build/src/k2/connector/pggate/catalog/sql_catalog_manager.cc:553 @createtable] Creating table ns name: postgres, ns oid: 12456, table name: fktable, table oid: 16388, systable: false, shared: false
[0001:03:46:47.202.134]-k2_pg-[0]-(k2::pg_seastar) [INFO] [/build/src/k2/connector/pggate/k2_seastar_app.cc:177 @operator()] Schema create... {collectionName=000030a8000030008000000000000000, schema={name=00000000000030008000000000004004, version=0, fields={
{type=INT64T, name=TableId, descending=false, nullLast=false},
{type=INT64T, name=IndexId, descending=false, nullLast=false},
{type=STRING, name=k2pgrowid, descending=false, nullLast=false},
{type=INT64T, name=ftest1, descending=false, nullLast=false},
{type=INT64T, name=ftest2, descending=false, nullLast=false}},
partitionKeyFields={0, 1, 2}, rangeKeyFields={}}}

@johnfangAFW
Copy link
Contributor

postgres=# \d itable;
Table "public.itable"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
ptest1 | integer | | |
ptest2 | text | | |
Indexes:
"itable_idx" UNIQUE, lsm (ptest1 HASH)
Referenced by:
TABLE "fktable" CONSTRAINT "fktable_ftest1_fkey" FOREIGN KEY (ftest1) REFERENCES itable(ptest1) MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE

postgres=# \d ITABLE_IDX;
Index "public.itable_idx"
Column | Type | Key? | Definition
--------+---------+------+------------
ptest1 | integer | yes | ptest1
unique, lsm, for table "public.itable"

postgres=# \d FKTABLE;
Table "public.fktable"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
ftest1 | integer | | |
ftest2 | integer | | |
Foreign-key constraints:
"fktable_ftest1_fkey" FOREIGN KEY (ftest1) REFERENCES itable(ptest1) MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE

postgres=# INSERT INTO ITABLE VALUES (1, 'Test1');
INSERT 0 1
postgres=# INSERT INTO ITABLE VALUES (2, 'Test2');
INSERT 0 1
postgres=# INSERT INTO ITABLE VALUES (3, 'Test3');
INSERT 0 1
postgres=# INSERT INTO ITABLE VALUES (4, 'Test4');
INSERT 0 1
postgres=# INSERT INTO ITABLE VALUES (5, 'Test5');
INSERT 0 1
postgres=# select * from itable;
ptest1 | ptest2
--------+--------
3 | Test3
2 | Test2
5 | Test5
4 | Test4
1 | Test1
(5 rows)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working must_have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants