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

Config parameter 'DeadlockTimeout ': mystic affect of its PARITY / ODDNESS on DDL results [CORE5080] #5367

Closed
firebird-automations opened this issue Jan 22, 2016 · 9 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @pavel-zotov

Found for current snapshots of 2.5.6 and 3.0, all arch (SS/SC/CS).

Create this script:

set term ^;
execute block as
begin
execute statement 'drop sequence g';
when any do begin end
end
^
-- commit -------------------------- [ 1 ]
^
create sequence g
^
-- commit -------------------------- [ 2 ]
^

create or alter procedure sp_get_remote_data returns(received_value int) as
begin
for
execute statement ('execute block returns(curr_gen int) as begin curr_gen = gen_id(g,1); suspend; end')
on external rdb$get_context('SYSTEM','DB_NAME')
as user 'SYSDBA' password 'masterkey' role 'R_' || right( uuid_to_char(gen_uuid()),12 )
into received_value
do
suspend;
end
^
commit
^
set term ;^

set list on;

select g.*, gen_id(g,0) as gen_current_value
from rdb$generators g
where g.rdb$generator_name = upper('g');

Then open firebird.conf and set DeadlockTimeout to any ODD value (7,9,11,... - whatever, up to 32767).

Running this script will result (show for 2.5 only; on 3.0 we'll have more info but outcome is the same):

RDB$GENERATOR_NAME G
RDB$GENERATOR_ID 35
RDB$SYSTEM_FLAG 0
RDB$DESCRIPTION <null>
GEN_CURRENT_VALUE 0

Then change DeadlockTimeout to EVEN value (2,4,6, ...) and run script again (NOTE: restart of server can be skipped, its no matter here).
Result will be:

Statement failed, SQLSTATE = 40001
deadlock
-deadlock
-concurrent transaction number is 329

Statement failed, SQLSTATE = 42000
invalid request BLR at offset 75
-generator G is not defined

Also, not on lines marked as [ 1 ] and [ 2 ]. When comments from these COMMIT statements are removed, all work fine.
PS. Checked on:

WI-V2.5.6.26963
WI-V3.0.0.32281

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

Run your script twice using the same value for DeadlockTimeout ...

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

Add SET AUTODDL OFF at beginning of script and see what happens.

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

No matter whether DeadlockTimeout is odd or even, I get:
1) OK when running script at 1, 3, 5 - i.e. _odd_ times;
2) exceptions 40001 (read conflicts with concurrent update) and 42000 (invalid request BLR at offset 104 // -generator G is not defined) at 2,4,6 - i.e. __even_ times.

C:\MIX\firebird\QA\fbt-repo\tmp>isql /:e30 -i c5080.sql

RDB$GENERATOR_NAME G
RDB$GENERATOR_ID 12
RDB$SYSTEM_FLAG 0
RDB$DESCRIPTION <null>
RDB$SECURITY_CLASS SQL$414
RDB$OWNER_NAME SYSDBA
RDB$INITIAL_VALUE 0
RDB$GENERATOR_INCREMENT 1
GEN_CURRENT_VALUE 0

ISQL Version: WI-V3.0.0.32281 Firebird 3.0 Release Candidate 2
Server version:
Firebird/Windows/Intel/i386 (access method), version "WI-V3.0.0.32281 Firebird 3.0 Release Candidate 2"
Firebird/Windows/Intel/i386 (remote server), version "WI-V3.0.0.32281 Firebird 3.0 Release Candidate 2/tcp (csprog)/P13"
Firebird/Windows/Intel/i386 (remote interface), version "WI-V3.0.0.32281 Firebird 3.0 Release Candidate 2/tcp (csprog)/P13"
on disk structure version 12.0

C:\MIX\firebird\QA\fbt-repo\tmp>isql /:e30 -i c5080.sql
Statement failed, SQLSTATE = 40001
unsuccessful metadata update
-CREATE SEQUENCE G failed
-deadlock
-read conflicts with concurrent update
-concurrent transaction number is 13
After line 9 in file c5080.sql
Statement failed, SQLSTATE = 42000
invalid request BLR at offset 104
-generator G is not defined
After line 30 in file c5080.sql
ISQL Version: WI-V3.0.0.32281 Firebird 3.0 Release Candidate 2
Server version:
Firebird/Windows/Intel/i386 (access method), version "WI-V3.0.0.32281 Firebird 3.0 Release Candidate 2"
Firebird/Windows/Intel/i386 (remote server), version "WI-V3.0.0.32281 Firebird 3.0 Release Candidate 2/tcp (csprog)/P13"
Firebird/Windows/Intel/i386 (remote interface), version "WI-V3.0.0.32281 Firebird 3.0 Release Candidate 2/tcp (csprog)/P13"
on disk structure version 12.0

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

Observed behaviour:
a) have no relation with DeadlockTimeout setting
b) have no mystic and absolutely normal if not forget how ISQL works in AUTODDL ON mode (two transactions, etc)

@firebird-automations
Copy link
Collaborator Author

Modified by: @hvlad

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

> Add SET AUTODDL OFF at beginning of script and see what happens.

No exceptions after adding this. This is the 1st time I can recall that adding set autoddl OFF can help to solving something rlated to DDL :-)

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

Vlad, can you please explain me:
1) how sequence 'G' could be 'invisible' __after__ commit that is marked here as "[[[[ THIS ]]]]' ?
2) why did I receive opposite results for odd/even values of DeadlockTimeout when script had not 'set autoddl off' statements (see starting post) ?

create sequence g
^
-- commit -------------------------- [ 2 ]
^

create or alter procedure sp_get_remote_data returns(received_value int) as
begin
for
execute statement ('execute block returns(curr_gen int) as begin curr_gen = gen_id(g,1); suspend; end')
on external rdb$get_context('SYSTEM','DB_NAME')
as user 'SYSDBA' password 'masterkey' role 'R_' || right( uuid_to_char(gen_uuid()),12 )
into received_value
do
suspend;
end
^
commit -------------- [[[[ THIS ]]]]
^

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

In AUTODLL ON mode (which is default mode) ISQL handle DML and DDL statements in different transactions.
EXECUTE BLOCK is DML statement therefore ISQL run it in "DML" transaction and doesn't commit it automatically.
CREATE SEQUENCE is DLL and ISQL runs it in different ("DDL") transaction and commits it.
So, you drop generator in "DML" transaction, doesn't commit it and create same generator in "DDL" transaction.
Of course this is classical update conflict scenario.
After isql run COMMIT statement, "DML" transaction is committed and generator is finally dropped.

All this you may see yourself using trace :)

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

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

No branches or pull requests

1 participant