Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoupdate broken:insert cause backend segment fault #20

Closed
amutu opened this issue Mar 13, 2014 · 6 comments
Closed

autoupdate broken:insert cause backend segment fault #20

amutu opened this issue Mar 13, 2014 · 6 comments

Comments

@amutu
Copy link

amutu commented Mar 13, 2014

create table test_trig2(ts timestamp,v char(10),v2 char(10));
select cs_create('test_trig2','ts',autoupdate:=true);
insert into test_trig2 values(now(),'123','456');
The connection to the server was lost. Attempting reset: Failed.
!> \q

@knizhnik
Copy link
Owner

Sorry, I can not reproduce the problem:
postgres=# create table test_trig2(ts timestamp,v char(10),v2 char(10));
CREATE TABLE
postgres=# select cs_create('test_trig2','ts',autoupdate:=true);

cs_create

(1 row)

postgres=# insert into test_trig2 values(now(),'123','456');
INSERT 0 1

Can you try it once more with some other table, for example test_trig22?
Does the problem persists? It the version of IMCS you are using exactly the same as in repository?

@amutu
Copy link
Author

amutu commented Mar 14, 2014

wired,I can reproduce it realiable,this is the gdb stack:
Program not restarted.
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
pg_detoast_datum (datum=0x1978dc6f20351) at fmgr.c:2241
2241 if (VARATT_IS_EXTENDED(datum))
(gdb) l
2236 */
2237
2238 struct varlena *
2239 pg_detoast_datum(struct varlena * datum)
2240 {
2241 if (VARATT_IS_EXTENDED(datum))
2242 return heap_tuple_untoast_attr(datum);
2243 else
2244 return datum;
2245 }
(gdb) bt
#0 pg_detoast_datum (datum=0x1978dc6f20351) at fmgr.c:2241
#1 0x00007f63ea3cecb3 in columnar_store_insert_trigger () from /data/postgres/pgsql933_debugb/imcs.so
#2 0x0000000000561ca5 in ExecCallTriggerFunc (trigdata=0x7fffa3f8cfb0, tgindx=1, finfo=0x2668798, instr=0x0,
per_tuple_context=0x268fc90) at trigger.c:1871
#3 0x000000000056212e in AfterTriggerExecute (events=0x25aa030, firing_id=1, estate=0x2668180, delete_ok=1 '\001')
at trigger.c:3454
#4 afterTriggerInvokeEvents (events=0x25aa030, firing_id=1, estate=0x2668180, delete_ok=1 '\001') at trigger.c:3633
#5 0x0000000000562e7a in AfterTriggerEndQuery (estate=0x2668180) at trigger.c:3823
#6 0x000000000057bfc4 in standard_ExecutorFinish (queryDesc=0x266e1a0) at execMain.c:379
#7 0x0000000000652f08 in ProcessQuery (plan=0x2634f70,
sourceText=0x2633bf0 "insert into test_trig2 values(now(),'123','456');", params=0x0, dest=,
completionTag=0x7fffa3f8d2d0 "INSERT 0 1") at pquery.c:225
#8 0x00000000006530ef in PortalRunMulti (portal=0x2691200, isTopLevel=1 '\001', dest=0x2635000, altdest=0x2635000,
completionTag=0x7fffa3f8d2d0 "INSERT 0 1") at pquery.c:1279
#9 0x00000000006537e3 in PortalRun (portal=0x2691200, count=9223372036854775807, isTopLevel=1 '\001', dest=0x2635000,
altdest=0x2635000, completionTag=0x7fffa3f8d2d0 "INSERT 0 1") at pquery.c:816
#10 0x0000000000650084 in exec_simple_query (query_string=0x2633bf0 "insert into test_trig2 values(now(),'123','456');")
at postgres.c:1048
#11 0x0000000000651719 in PostgresMain (argc=, argv=, dbname=0x2590e70 "postgres",
username=) at postgres.c:3997
#12 0x000000000060edd5 in BackendRun (argc=, argv=) at postmaster.c:3996
#13 BackendStartup (argc=, argv=) at postmaster.c:3685
#14 ServerLoop (argc=, argv=) at postmaster.c:1586
#15 PostmasterMain (argc=, argv=) at postmaster.c:1253
#16 0x00000000005ab990 in main (argc=3, argv=0x258fab0) at main.c:206

the suspension code is:
case TID_char:
if (nulls[i]) { /* substitute NULL with empty string /
imcs_append_char(ts, NULL, 0);
} else {
t = DatumGetTextP(values[i]);//----------------------here
str = (char
)VARDATA(t);
len = VARSIZE(t) - VARHDRSZ;
if (attr_type_oid[i] == BPCHAROID) {
while (len != 0 && str[len-1] == ' ') {
len -= 1;
}
}
imcs_append_char(ts, str, len);

I try to create new database with SQL_ASCII encoding instead of UTF-8、create new database、compile new code,but the segment always happened.

@amutu
Copy link
Author

amutu commented Mar 14, 2014

some more info:
the values[i] is the ts column,because I step the gdb and print the i, it show 0;

and more intresting is here:
[postgres@T ~/postgresql-9.3.3/contrib/imcs-master]$ psql test3
psql (9.3.3)
Type "help" for help.

test3=# insert into test_trig2 values(now()::timestamp,'123'::char(10),'456'::char(10));
The connection to the server was lost. Attempting reset: Failed.
!> \q
[postgres@T ~/postgresql-9.3.3/contrib/imcs-master]$ psql test3
psql (9.3.3)
Type "help" for help.

test3=# select * from test_trig2 ;
ts | v | v2
----------------------------+------------+------------
2015-01-01 00:00:00 | |
2014-03-14 12:48:44.018865 | 123 | 456
(2 rows)

test3=# select * from test_trig2_get();
v2 | v | ts
-----------------+-----------------+------------------------------------------------------------
bpchar10:{456,} | bpchar10:{123,} | timestamp:{2014-03-14 12:48:44.018865,2015-01-01 00:00:00}
(1 row)

test3=# insert into test_trig2 values(now()::timestamp,'123'::char(10),'456'::char(10));
ERROR: data format was changed
test3=#

So the auto load is OK,but When the CS is loaded,the insert will failed with: data format was changed;but if the CS is not loaded,the insert will cause segment.

more debug info:
771 key.id = (char_)id;
(gdb)
772 entry = (imcs_hash_entry_t_)hash_search(imcs_hash, &key, HASH_FIND, NULL);
(gdb)
773 if (entry == NULL) {
(gdb) print entry
$1 = (imcs_hash_entry_t ) 0x7f9850dbad48
(gdb) print *entry
$2 = {key = {id = 0x7f9850dbce00 "test_trig2-v2"}, value = {root_page = 0x7f9850dbce10, elem_type = TID_char,
is_timestamp = 0 '\000', elem_size = 10, count = 2}}
(gdb) n
812 ts = &entry->value;
(gdb)
814 if (elem_size != 0 /
elem_size == 0 when imcs_get_timeseries is called from columnar_store_initialized /
(gdb) print elem_size
$3 = 10
(gdb) print ts->elem_type
$4 = TID_char
(gdb) print elem_type
$5 = TID_char
(gdb) print elem_size
$6 = 10
(gdb) print ts->elem_size
$7 = 10
(gdb) print ts->is_timestamp
$8 = 0 '\000'
(gdb) print is_timestamp
$9 = 1 '\001'
(gdb) n
815 && (ts->elem_type != elem_type ||
(gdb) n
814 if (elem_size != 0 /
elem_size == 0 when imcs_get_timeseries is called from columnar_store_initialized /
(gdb) n
816 ts->elem_size != elem_size ||
(gdb) n
814 if (elem_size != 0 /
elem_size == 0 when imcs_get_timeseries is called from columnar_store_initialized /
(gdb) n
817 ts->is_timestamp != is_timestamp))
(gdb) n
814 if (elem_size != 0 /
elem_size == 0 when imcs_get_timeseries is called from columnar_store_initialized */
(gdb) n
819 ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), (errmsg("data format was changed"))));

this:
ts->is_timestamp != is_timestamp cause the Error.

@knizhnik
Copy link
Owner

Still can not reproduce the problem...
But can you try the patched version of imcs--1.1.sql (you will have to drop and recreate IMCS extension).

@knizhnik
Copy link
Owner

Can you also point me on IMCS parameters you are using.
Particularly - did you set "imcs.substitute_nulls"?

@amutu
Copy link
Author

amutu commented Mar 14, 2014

the patched version of imcs--1.1.sql solve the problem!
and the autoload then insert also work OK.
thanks very much!

this is my settings:
imcs.trace = on
imcs.shmem_size = 81920
imcs.substitute_nulls = on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants