FirebirdSQL / firebird

Firebird server, client and tools
https://www.firebirdsql.org/
1.22k stars 213 forks source link

No initialization of rpb's runtime flags causes problems with SKIP LOCKED when config ReadConsistency = 0 and SuperServer #7486

Closed asfernandes closed 11 months ago

asfernandes commented 1 year ago

This relates to comments in https://github.com/FirebirdSQL/firebird/pull/7350

Test case:

isql-1:

recreate table test(id int primary key, f01 int);

set term !;
create or alter procedure select_proc returns (o integer)
as
begin
    for select id from test rows 2 with lock skip locked into o do suspend;
end!
set term ;!

commit;
insert into test(id, f01) select row_number()over(), 0 from rdb$types rows 10;
commit;
update test set f01 = 1 where id in (1,5,9);
SQL> 

isql-2:

SQL> -- first time it works
SQL> rollback; set transaction read committed record_version NO wait; select * from select_proc;

SQL> -- second time it do not work
SQL> rollback; set transaction read committed record_version NO wait; select * from select_proc;
Statement failed, SQLSTATE = 40001
deadlock
-read conflicts with concurrent update
-concurrent transaction number is 107
-- Why error here ?
asfernandes commented 1 year ago

This no-initialization may cause others problems unrelated with SKIP LOCKED, but I'm not sure what exactly.

pavel-zotov commented 1 year ago

@@@ QA notes @@@ See test for #7350

hvlad commented 11 months ago

The fix is incomplete, try to select more records in select_proc, all 10 for example. Or try to update records with id's (1, 2) before call select_proc.

It looks like rpb_runtime_flags should be cleared before every fetch, not on execution start only.

asfernandes commented 11 months ago

I think you were wrong in reopening this bug as nature of cause seems completely unrelated. The original test case causes a problem of the loaded procedure metadata to share an uninitialized state.

What you are describing now happens even if the second session do not use the procedure.

hvlad commented 11 months ago

Ticket description not mentions 'procedure'. Both the issue and the committed fix is related with rpb_runtime_flags. This is why I reopened this ticket.

asfernandes commented 11 months ago

Another difference is that original issue do not happens in classic, and as stated, it may have others consequences (not deeply investigated) non-related with SKIP LOCKED.

The one you said also happens in classic.