Closed floatrain closed 8 years ago
duplicate #33 , fixed in #34
I have another question , as follows : local frequency_signal_list = pgfunc ([[frequency_signal_list (nbe_pu)]], {only_internal = false}) local nbe_pu_list_count = pgfunc ([[nbe_pu_list_count (nbe_pu)]], {only_internal = false}) local nbe_pu_list_get_element = pgfunc ([[nbe_pu_list_get_element (nbe_pu, integer)]], {only_internal = false}) local nbe_list = frequency_signal_list (r.pu)
local count = nbe_pu_list_count (nbe_list) for i = 0, count-1 do local psg = nbe_pu_list_get_element (nbe_list, i) end
r is continuous view one tuple , pu field is a tuple . I use GDB debugging Found nbe_list sometimes not the same as the last in a for loop , which can cause access violation occurs mistakes . I think this should not be ah , which is why ah ?
pllua does not make datum copies and that might be the cause that you have not the same values. It's hard to say without running example
in pllua_pgfunc.c:143 rows
for (i=0; i
i modfiy plluaapi.c:1205 rows else { luaP_Datum _d = luaP_toudata(L, idx, PLLUA_DATUM); globlevarlena = *(struct varlena)d->datum; bytea *p = DatumGetByteaP(d->datum); globle_ptr = VARDATA(p); if (d == NULL) elog(ERROR, "[pllua]: raw datum expected for datum conversion, got %s", lua_typename(L, lua_type(L, idx))); dat = datumcopy(d->datum, ti); }
I found d->datum is the same ,but (struct varlena )d->datum is changed. i cann't got it when this memory was free?
Breakpoint 1, luaP_todatum (L=0x1cf647b0, type=5090, typmod=0, isnull=0x7fffe3a0b6a0 "", idx=1, fi=...) at plluaapi.c:1231 $125 = {issaved = 0, datum = 486767288, ti = 0x1d450c58} $126 = {vllen = "\360\001\000", vl_dat = 0x2b9d756d3fc4 ""} $127 = (nbe_list *) 0x1d037abc $128 = {uhd = {endian = 0, packed = 1, type = 2, m = 0, state = 0, uid = 601, offset = 0, tail = 120, avail = 0}, element_min = 20, count = 4, size = 4096}
Breakpoint 1, luaP_todatum (L=0x1cf647b0, type=5090, typmod=0, isnull=0x7fffe3a0b6a0 "", idx=1, fi=...) at plluaapi.c:1231 $129 = {issaved = 0, datum = 486767288, ti = 0x1d450c58} $130 = {vllen = "\177\177\177\177", vl_dat = 0x2b9d756d3fc4 ""} $131 = (nbe_list *) 0x1d03670c $132 = {uhd = {endian = 1, packed = 1, type = 7, m = 1, state = 1, uid = 3967, offset = 2039, tail = 2139062143, avail = 2139062143}, element_min = 32639, count = 2139062143, size = 2139062 143} in pllua_pgfunc.c:143 rows
for (i=0; i
I debug luaP_todatum function, In plluaapi.c:1205 rows, { luaP_Datum d = luaP_toudata(L, idx, PLLUA_DATUM); if (d == NULL) elog(ERROR, "[pllua]: raw datum expected for datum conversion, got %s", lua_typename(L, lua_type(L, idx))); dat = datumcopy(d->datum, ti); } I found d->datum is the same ,but (struct varlena *)(d->datum) is changed. i cann't got it when this memory was free?
Breakpoint 1, luaP_todatum (L=0x1cf647b0, type=5090, typmod=0, isnull=0x7fffe3a0b6a0 "", idx=1, fi=...) at plluaapi.c:1231 $125 = {issaved = 0, datum = 486767288, ti = 0x1d450c58} $126 = {vllen = "\360\001\000", vl_dat = 0x2b9d756d3fc4 ""} $127 = (nbe_list *) 0x1d037abc $128 = {uhd = {endian = 0, packed = 1, type = 2, m = 0, state = 0, uid = 601, offset = 0, tail = 120, avail = 0}, element_min = 20, count = 4, size = 4096}
Breakpoint 1, luaP_todatum (L=0x1cf647b0, type=5090, typmod=0, isnull=0x7fffe3a0b6a0 "", idx=1, fi=...) at plluaapi.c:1231 $129 = {issaved = 0, datum = 486767288, ti = 0x1d450c58} $130 = {vllen = "\177\177\177\177", vl_dat = 0x2b9d756d3fc4 ""} $131 = (nbe_list *) 0x1d03670c $132 = {uhd = {endian = 1, packed = 1, type = 7, m = 1, state = 1, uid = 3967, offset = 2039, tail = 2139062143, avail = 2139062143}, element_min = 32639, count = 2139062143, size = 2139062 143}
$125 and $129 value is d->datum = 486767288,but (struct varlena )(d->datum) value is not same. why?
What is postgres type of nbe_list ?
nbe_list is my defined structure
@eugwne can you debug it througth teamviewer? do you have skype number? my skype:kingkiller869
@eugwne ,i found the macro RESET_CONTEXT_AFTER value will cause my prog segfault mistake,but i cann't got why?
When transaction is over, transaction context released. But in case of doing something like:
local func = pg_func('...')
for i = 1, bigValue do
func(...)
end
you may become run out of memory, that is why there is temporary context which is dropped after counter. In your case the result of previous function call was dropped because next calls increased that counter. I think that it's better to make this option configurable from lua somehow.
Is this an empirical value? if the value is not appropriate,the postgresql will segment,but the value is too large,it may become run out of memory?i want to know,why the value is 1000 ?the value was based on what? thank you!!!
No, it's not based on anything. If you make a million function calls inside one transaction without resetting context should see growing memory consuming during that process.
but if the value is not appropriate, the programmer will be segfault? have some ways to check the address is using?
I have a couple ideas for this, but they are not perfect. Needs some time...
I am waiting for your good news.!!!
have some good news?
If you have small transactions I think we can turn off autocleanup and use transaction context. I've made this changes in my repo, but haven't tested yet. In other case lua gc should be mixed somehow with postgres memory pools.
When I was in the use of the extension, I doubt pgfunc () this function is a BUG.Such as the code below: CREATE or replace the FUNCTION test () RETURNS void AS $$ local ibase_get_hashdata = pgfunc ([[ibase_get_hashdata (integer, text)]] and {only_internal = false}) local a = ibase_get_hashdata (4, '368738464') print (" -- -- -- -- -- -- -- -- -- -- - > end ') $$LANGUAGE plluau; When the function ibase_get_hashdata (4, '368738464') to obtain the value is NULL, namely PG_RETURN_NULL, there will be a segment fault. When I was in single step debugging GDB will find in this function error luaP_pushrecord (L, dat) ——> DatumGetHeapTupleHeader (record), the reason is that the record is NULL.