2 @message |
assert
checked_mode: table, STDLOG: Records affected: 4
checked_mode: table, STDLOG: ID
checked_mode: table, STDLOG:
checked_mode: table, STDLOG: -5
checked_mode: table, STDLOG: -2
checked_mode: table, STDLOG: -1
checked_mode: table, STDLOG: 3
checked_mode: table, STDLOG: 4
checked_mode: table, STDLOG: Records affected: 5
checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: table, STDLOG:
- checked_mode: table, STDLOG: 2 UPD 1
+ checked_mode: table, STDLOG: 2UPD 1
- checked_mode: table, STDLOG: 2 UPD 2
+ checked_mode: table, STDLOG: 2UPD 2
- checked_mode: table, STDLOG: 1 UPD 2
+ checked_mode: table, STDLOG: 1UPD 2
- checked_mode: table, STDLOG: 2 UPD 3
+ checked_mode: table, STDLOG: 2UPD 3
- checked_mode: table, STDLOG: 1 UPD 3
+ checked_mode: table, STDLOG: 1UPD 3
- checked_mode: table, STDLOG: 2 UPD 4
+ checked_mode: table, STDLOG: 2UPD 4
- checked_mode: table, STDLOG: 1 UPD 4
+ checked_mode: table, STDLOG: 1UPD 4
- checked_mode: table, STDLOG: -3 UPD 4
+ checked_mode: table, STDLOG: -3UPD 4
- checked_mode: table, STDLOG: -4 UPD 4
+ checked_mode: table, STDLOG: -4UPD 4
checked_mode: table, STDLOG: Records affected: 9
LOG DETAILS:
2025-07-02 06:07:50.984
2025-07-02 06:07:50.990 act = <firebird.qa.plugin.Action object at [hex]>
2025-07-02 06:07:50.996 fn_worker_sql = PosixPath('/var/tmp/qa_2024/test_12484/tmp_worker.sql')
2025-07-02 06:07:51.003 fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12484/tmp_worker.log')
2025-07-02 06:07:51.011 fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12484/tmp_worker.err')
2025-07-02 06:07:51.018 capsys = <_pytest.capture.CaptureFixture object at [hex]>
2025-07-02 06:07:51.029
2025-07-02 06:07:51.039 @pytest.mark.trace
2025-07-02 06:07:51.052 @pytest.mark.version('>=4.0')
2025-07-02 06:07:51.061 def test_1(act: Action, fn_worker_sql: Path, fn_worker_log: Path, fn_worker_err: Path, capsys):
2025-07-02 06:07:51.071 sql_init = (act.files_dir / 'read-consist-sttm-restart-DDL.sql').read_text()
2025-07-02 06:07:51.078
2025-07-02 06:07:51.086 for checked_mode in('table', 'view'):
2025-07-02 06:07:51.095 target_obj = 'test' if checked_mode == 'table' else 'v_test'
2025-07-02 06:07:51.102
2025-07-02 06:07:51.108 SQL_TO_BE_RESTARTED = f"""
2025-07-02 06:07:51.114 merge /* {SQL_TAG_THAT_WE_WAITING_FOR} */ into {target_obj} t
2025-07-02 06:07:51.123 using (select * from {target_obj} where id <=2 order by id DESC rows 4) s on s.id=t.id
2025-07-02 06:07:51.130 when matched then
2025-07-02 06:07:51.144 update set t.id = -t.id
2025-07-02 06:07:51.154 when not matched then
2025-07-02 06:07:51.167 insert(id,x) values(1000 + s.id, 1000 + s.x)
2025-07-02 06:07:51.178 """
2025-07-02 06:07:51.191
2025-07-02 06:07:51.205 sql_addi = f'''
2025-07-02 06:07:51.215 set term ^;
2025-07-02 06:07:51.224 execute block as
2025-07-02 06:07:51.230 begin
2025-07-02 06:07:51.239 rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
2025-07-02 06:07:51.249 end
2025-07-02 06:07:51.258 ^
2025-07-02 06:07:51.266 set term ;^
2025-07-02 06:07:51.278 insert into {target_obj}(id, x)
2025-07-02 06:07:51.290 select row_number()over(),row_number()over()
2025-07-02 06:07:51.298 from rdb$types rows 5;
2025-07-02 06:07:51.308 commit;
2025-07-02 06:07:51.320 '''
2025-07-02 06:07:51.331
2025-07-02 06:07:51.344 act.isql(switches=['-q'], input = ''.join( (sql_init, sql_addi) ) )
2025-07-02 06:07:51.357 # ::: NOTE ::: We have to immediately quit if any error raised in prepare phase.
2025-07-02 06:07:51.370 # See also letter from dimitr, 01-feb-2022 14:46
2025-07-02 06:07:51.385 assert act.stderr == ''
2025-07-02 06:07:51.396 act.reset()
2025-07-02 06:07:51.406
2025-07-02 06:07:51.418 trace_cfg_items = [
2025-07-02 06:07:51.428 'time_threshold = 0',
2025-07-02 06:07:51.439 'log_errors = true',
2025-07-02 06:07:51.451 'log_statement_start = true',
2025-07-02 06:07:51.462 'log_statement_finish = true',
2025-07-02 06:07:51.474 ]
2025-07-02 06:07:51.485
2025-07-02 06:07:51.498 with act.trace(db_events = trace_cfg_items, encoding=locale.getpreferredencoding()):
2025-07-02 06:07:51.508
2025-07-02 06:07:51.519 with act.db.connect() as con_lock_1, act.db.connect() as con_lock_2, act.db.connect() as con_monitoring:
2025-07-02 06:07:51.531
2025-07-02 06:07:51.541 tpb_monitoring = tpb(isolation=Isolation.READ_COMMITTED_RECORD_VERSION, lock_timeout=0)
2025-07-02 06:07:51.551 tx_monitoring = con_monitoring.transaction_manager(tpb_monitoring)
2025-07-02 06:07:51.563 cur_monitoring = tx_monitoring.cursor()
2025-07-02 06:07:51.572
2025-07-02 06:07:51.580 for i,c in enumerate((con_lock_1,con_lock_2)):
2025-07-02 06:07:51.588 sttm = f"execute block as begin rdb$set_context('USER_SESSION', 'WHO', 'LOCKER #{i+1}'); end"
2025-07-02 06:07:51.594 c.execute_immediate(sttm)
2025-07-02 06:07:51.600
2025-07-02 06:07:51.606 #########################
2025-07-02 06:07:51.612 ### L O C K E R - 1 ###
2025-07-02 06:07:51.617 #########################
2025-07-02 06:07:51.623
2025-07-02 06:07:51.632 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id=1' )
2025-07-02 06:07:51.645
2025-07-02 06:07:51.655 worker_sql = f'''
2025-07-02 06:07:51.665 set list on;
2025-07-02 06:07:51.676 set autoddl off;
2025-07-02 06:07:51.687 set term ^;
2025-07-02 06:07:51.698 execute block returns (whoami varchar(30)) as
2025-07-02 06:07:51.707 begin
2025-07-02 06:07:51.714 whoami = 'WORKER'; -- , ATT#' || current_connection;
2025-07-02 06:07:51.722 rdb$set_context('USER_SESSION','WHO', whoami);
2025-07-02 06:07:51.734 -- suspend;
2025-07-02 06:07:51.747 end
2025-07-02 06:07:51.760 ^
2025-07-02 06:07:51.771 set term ;^
2025-07-02 06:07:51.782 commit;
2025-07-02 06:07:51.793 SET KEEP_TRAN_PARAMS ON;
2025-07-02 06:07:51.806 set transaction read committed read consistency;
2025-07-02 06:07:51.818 set list off;
2025-07-02 06:07:51.826 set wng off;
2025-07-02 06:07:51.839 set count on;
2025-07-02 06:07:51.851
2025-07-02 06:07:51.859 -- this must hang because of locker-1:
2025-07-02 06:07:51.865 {SQL_TO_BE_RESTARTED};
2025-07-02 06:07:51.872
2025-07-02 06:07:51.878 -- check results:
2025-07-02 06:07:51.885 -- ###############
2025-07-02 06:07:51.896 select id from {target_obj} order by id; -- one record must remain, with ID = -5
2025-07-02 06:07:51.910
2025-07-02 06:07:51.920 select v.old_id, v.op, v.snap_no_rank -- snap_no_rank must have four unique values: 1,2,3 and 4.
2025-07-02 06:07:51.926 from v_worker_log v
2025-07-02 06:07:51.933 where v.op = 'upd';
2025-07-02 06:07:51.946
2025-07-02 06:07:51.956 --set width who 10;
2025-07-02 06:07:51.964 -- DO NOT check this! Values can differ here from one run to another!
2025-07-02 06:07:51.976 -- select id, trn, who, old_id, new_id, op, rec_vers, global_cn, snap_no from tlog_done order by id;
2025-07-02 06:07:51.986 rollback;
2025-07-02 06:07:51.996
2025-07-02 06:07:52.004 '''
2025-07-02 06:07:52.011
2025-07-02 06:07:52.018 fn_worker_sql.write_text(worker_sql)
2025-07-02 06:07:52.024
2025-07-02 06:07:52.036 with fn_worker_log.open(mode='w') as hang_out, fn_worker_err.open(mode='w') as hang_err:
2025-07-02 06:07:52.048
2025-07-02 06:07:52.058 ############################################################################
2025-07-02 06:07:52.071 ### L A U N C H W O R K E R U S I N G I S Q L, A S Y N C. ###
2025-07-02 06:07:52.080 ############################################################################
2025-07-02 06:07:52.088 p_worker = subprocess.Popen([act.vars['isql'], '-i', str(fn_worker_sql),
2025-07-02 06:07:52.098 '-user', act.db.user,
2025-07-02 06:07:52.109 '-password', act.db.password,
2025-07-02 06:07:52.118 '-pag', '999999',
2025-07-02 06:07:52.126 act.db.dsn
2025-07-02 06:07:52.133 ],
2025-07-02 06:07:52.141 stdout = hang_out,
2025-07-02 06:07:52.148 stderr = hang_err
2025-07-02 06:07:52.161 )
2025-07-02 06:07:52.171 # NB: when ISQL will establish attach, first record that it must lock is ID = 2 -- see above SQL_TO_BE_RESTARTED
2025-07-02 06:07:52.178 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:07:52.190 #
2025-07-02 06:07:52.200 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=2', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:07:52.211
2025-07-02 06:07:52.224
2025-07-02 06:07:52.236 #########################
2025-07-02 06:07:52.251 ### L O C K E R - 2 ###
2025-07-02 06:07:52.263 #########################
2025-07-02 06:07:52.272
2025-07-02 06:07:52.280 # Change ID so that it **will* be included in the set of rows that must be affected by session-worker:
2025-07-02 06:07:52.288 con_lock_2.execute_immediate( f'update {target_obj} set id = -5 where abs(id) = 5;' )
2025-07-02 06:07:52.294 con_lock_2.commit()
2025-07-02 06:07:52.312 con_lock_2.execute_immediate( f'update {target_obj} set id = id where abs(id) = 5;' )
2025-07-02 06:07:52.321 con_lock_1.commit() # releases record with ID=1 ==> now it can be locked by worker.
2025-07-02 06:07:52.330
2025-07-02 06:07:52.337 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 1.
2025-07-02 06:07:52.343 #
2025-07-02 06:07:52.351 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=1', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:07:52.357
2025-07-02 06:07:52.363 # If we come here then it means that record with ID = 1 for sure is locked by WORKER.
2025-07-02 06:07:52.368
2025-07-02 06:07:52.374 # Change ID so that it **will* be included in the set of rows that must be affected by session-worker:
2025-07-02 06:07:52.379 con_lock_1.execute_immediate( f'update {target_obj} set id = -4 where abs(id) = 4;' )
2025-07-02 06:07:52.385 con_lock_1.commit()
2025-07-02 06:07:52.392 con_lock_1.execute_immediate( f'update {target_obj} set id = id where abs(id) = 4;' )
2025-07-02 06:07:52.398
2025-07-02 06:07:52.405 con_lock_2.commit() # releases record with ID = -5, but session-worker is waiting for record with ID = -4 (that was changed by locker-1).
2025-07-02 06:07:52.412
2025-07-02 06:07:52.420 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -5:
2025-07-02 06:07:52.427 #
2025-07-02 06:07:52.434 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id = -5', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:07:52.445
2025-07-02 06:07:52.456 # If we come here then it means that record with ID = -5 for sure is locked by WORKER.
2025-07-02 06:07:52.463
2025-07-02 06:07:52.476 con_lock_2.execute_immediate( f'update {target_obj} set id = -3 where abs(id) = 3;' )
2025-07-02 06:07:52.486 con_lock_2.commit()
2025-07-02 06:07:52.498 con_lock_2.execute_immediate( f'update {target_obj} set id = id where abs(id) = 3;' )
2025-07-02 06:07:52.508
2025-07-02 06:07:52.516 con_lock_1.commit() # This releases row with ID=-4 but session-worker is waiting for ID = - 3 (changed by locker-2).
2025-07-02 06:07:52.523
2025-07-02 06:07:52.530
2025-07-02 06:07:52.539 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -4:
2025-07-02 06:07:52.550 #
2025-07-02 06:07:52.559 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id = -4', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:07:52.566
2025-07-02 06:07:52.577 # If we come here then it means that record with ID = -4 for sure is locked by WORKER.
2025-07-02 06:07:52.586
2025-07-02 06:07:52.595 con_lock_2.commit() # This releases row with ID=-3. No more locked rows so session-worker can finish its mission.
2025-07-02 06:07:52.603
2025-07-02 06:07:52.610 # Here we wait for ISQL complete its mission:
2025-07-02 06:07:52.619 p_worker.wait()
2025-07-02 06:07:52.628 # < with act.db.connect
2025-07-02 06:07:52.635
2025-07-02 06:07:52.642 for g in (fn_worker_log, fn_worker_err):
2025-07-02 06:07:52.652 with g.open() as f:
2025-07-02 06:07:52.660 for line in f:
2025-07-02 06:07:52.667 if line.split():
2025-07-02 06:07:52.676 if g == fn_worker_log:
2025-07-02 06:07:52.682 print(f'checked_mode: {checked_mode}, STDLOG: {line}')
2025-07-02 06:07:52.693 else:
2025-07-02 06:07:52.705 print(f'UNEXPECTED STDERR {line}')
2025-07-02 06:07:52.718
2025-07-02 06:07:52.729 expected_stdout_worker = f"""
2025-07-02 06:07:52.742 checked_mode: {checked_mode}, STDLOG: Records affected: 4
2025-07-02 06:07:52.753
2025-07-02 06:07:52.763 checked_mode: {checked_mode}, STDLOG: ID
2025-07-02 06:07:52.770 checked_mode: {checked_mode}, STDLOG: =======
2025-07-02 06:07:52.777 checked_mode: {checked_mode}, STDLOG: -5
2025-07-02 06:07:52.784 checked_mode: {checked_mode}, STDLOG: -2
2025-07-02 06:07:52.790 checked_mode: {checked_mode}, STDLOG: -1
2025-07-02 06:07:52.797 checked_mode: {checked_mode}, STDLOG: 3
2025-07-02 06:07:52.803 checked_mode: {checked_mode}, STDLOG: 4
2025-07-02 06:07:52.809 checked_mode: {checked_mode}, STDLOG: Records affected: 5
2025-07-02 06:07:52.815
2025-07-02 06:07:52.822 checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:07:52.834 checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
2025-07-02 06:07:52.845 checked_mode: {checked_mode}, STDLOG: 2 UPD 1
2025-07-02 06:07:52.853 checked_mode: {checked_mode}, STDLOG: 2 UPD 2
2025-07-02 06:07:52.861 checked_mode: {checked_mode}, STDLOG: 1 UPD 2
2025-07-02 06:07:52.867 checked_mode: {checked_mode}, STDLOG: 2 UPD 3
2025-07-02 06:07:52.874 checked_mode: {checked_mode}, STDLOG: 1 UPD 3
2025-07-02 06:07:52.884 checked_mode: {checked_mode}, STDLOG: 2 UPD 4
2025-07-02 06:07:52.896 checked_mode: {checked_mode}, STDLOG: 1 UPD 4
2025-07-02 06:07:52.906 checked_mode: {checked_mode}, STDLOG: -3 UPD 4
2025-07-02 06:07:52.915 checked_mode: {checked_mode}, STDLOG: -4 UPD 4
2025-07-02 06:07:52.923 checked_mode: {checked_mode}, STDLOG: Records affected: 9
2025-07-02 06:07:52.928 """
2025-07-02 06:07:52.935
2025-07-02 06:07:52.943 act.expected_stdout = expected_stdout_worker
2025-07-02 06:07:52.955 act.stdout = capsys.readouterr().out
2025-07-02 06:07:52.964 > assert act.clean_stdout == act.clean_expected_stdout
2025-07-02 06:07:52.971 E assert
2025-07-02 06:07:52.977 E checked_mode: table, STDLOG: Records affected: 4
2025-07-02 06:07:52.982 E checked_mode: table, STDLOG: ID
2025-07-02 06:07:52.988 E checked_mode: table, STDLOG:
2025-07-02 06:07:52.994 E checked_mode: table, STDLOG: -5
2025-07-02 06:07:53.000 E checked_mode: table, STDLOG: -2
2025-07-02 06:07:53.007 E checked_mode: table, STDLOG: -1
2025-07-02 06:07:53.019 E checked_mode: table, STDLOG: 3
2025-07-02 06:07:53.028 E checked_mode: table, STDLOG: 4
2025-07-02 06:07:53.037 E checked_mode: table, STDLOG: Records affected: 5
2025-07-02 06:07:53.049 E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:07:53.061 E checked_mode: table, STDLOG:
2025-07-02 06:07:53.071 E - checked_mode: table, STDLOG: 2 UPD 1
2025-07-02 06:07:53.094 E + checked_mode: table, STDLOG: 2UPD 1
2025-07-02 06:07:53.104 E - checked_mode: table, STDLOG: 2 UPD 2
2025-07-02 06:07:53.120 E + checked_mode: table, STDLOG: 2UPD 2
2025-07-02 06:07:53.128 E - checked_mode: table, STDLOG: 1 UPD 2
2025-07-02 06:07:53.142 E + checked_mode: table, STDLOG: 1UPD 2
2025-07-02 06:07:53.152 E - checked_mode: table, STDLOG: 2 UPD 3
2025-07-02 06:07:53.170 E + checked_mode: table, STDLOG: 2UPD 3
2025-07-02 06:07:53.176 E - checked_mode: table, STDLOG: 1 UPD 3
2025-07-02 06:07:53.188 E + checked_mode: table, STDLOG: 1UPD 3
2025-07-02 06:07:53.195 E - checked_mode: table, STDLOG: 2 UPD 4
2025-07-02 06:07:53.210 E + checked_mode: table, STDLOG: 2UPD 4
2025-07-02 06:07:53.220 E - checked_mode: table, STDLOG: 1 UPD 4
2025-07-02 06:07:53.230 E + checked_mode: table, STDLOG: 1UPD 4
2025-07-02 06:07:53.236 E - checked_mode: table, STDLOG: -3 UPD 4
2025-07-02 06:07:53.255 E + checked_mode: table, STDLOG: -3UPD 4
2025-07-02 06:07:53.269 E - checked_mode: table, STDLOG: -4 UPD 4
2025-07-02 06:07:53.283 E + checked_mode: table, STDLOG: -4UPD 4
2025-07-02 06:07:53.289 E checked_mode: table, STDLOG: Records affected: 9
2025-07-02 06:07:53.293
2025-07-02 06:07:53.298 tests/functional/transactions/test_read_consist_sttm_restart_on_merge_04.py:447: AssertionError
2025-07-02 06:07:53.303 ---------------------------- Captured stdout setup -----------------------------
2025-07-02 06:07:53.308 Creating db: localhost:/var/tmp/qa_2024/test_12484/test.fdb [page_size=None, sql_dialect=None, charset='NONE', user=SYSDBA, password=masterkey]
|
3 #text |
act = <firebird.qa.plugin.Action pytest object at [hex]>
fn_worker_sql = PosixPath('/var/tmp/qa_2024/test_12484/tmp_worker.sql')
fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12484/tmp_worker.log')
fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12484/tmp_worker.err')
capsys = <_pytest.capture.CaptureFixture pytest object at [hex]>
@pytest.mark.trace
@pytest.mark.version('>=4.0')
def test_1(act: Action, fn_worker_sql: Path, fn_worker_log: Path, fn_worker_err: Path, capsys):
sql_init = (act.files_dir / 'read-consist-sttm-restart-DDL.sql').read_text()
for checked_mode in('table', 'view'):
target_obj = 'test' if checked_mode == 'table' else 'v_test'
SQL_TO_BE_RESTARTED = f"""
merge /* {SQL_TAG_THAT_WE_WAITING_FOR} */ into {target_obj} t
using (select * from {target_obj} where id <=2 order by id DESC rows 4) s on s.id=t.id
when matched then
update set t.id = -t.id
when not matched then
insert(id,x) values(1000 + s.id, 1000 + s.x)
"""
sql_addi = f'''
set term ^;
execute block as
begin
rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
end
^
set term ;^
insert into {target_obj}(id, x)
select row_number()over(),row_number()over()
from rdb$types rows 5;
commit;
'''
act.isql(switches=['-q'], input = ''.join( (sql_init, sql_addi) ) )
# ::: NOTE ::: We have to immediately quit if any error raised in prepare phase.
# See also letter from dimitr, 01-feb-2022 14:46
assert act.stderr == ''
act.reset()
trace_cfg_items = [
'time_threshold = 0',
'log_errors = true',
'log_statement_start = true',
'log_statement_finish = true',
]
with act.trace(db_events = trace_cfg_items, encoding=locale.getpreferredencoding()):
with act.db.connect() as con_lock_1, act.db.connect() as con_lock_2, act.db.connect() as con_monitoring:
tpb_monitoring = tpb(isolation=Isolation.READ_COMMITTED_RECORD_VERSION, lock_timeout=0)
tx_monitoring = con_monitoring.transaction_manager(tpb_monitoring)
cur_monitoring = tx_monitoring.cursor()
for i,c in enumerate((con_lock_1,con_lock_2)):
sttm = f"execute block as begin rdb$set_context('USER_SESSION', 'WHO', 'LOCKER #{i+1}'); end"
c.execute_immediate(sttm)
#########################
### L O C K E R - 1 ###
#########################
con_lock_1.execute_immediate( f'update {target_obj} set id=id where id=1' )
worker_sql = f'''
set list on;
set autoddl off;
set term ^;
execute block returns (whoami varchar(30)) as
begin
whoami = 'WORKER'; -- , ATT#' || current_connection;
rdb$set_context('USER_SESSION','WHO', whoami);
-- suspend;
end
^
set term ;^
commit;
SET KEEP_TRAN_PARAMS ON;
set transaction read committed read consistency;
set list off;
set wng off;
set count on;
-- this must hang because of locker-1:
{SQL_TO_BE_RESTARTED};
-- check results:
-- ###############
select id from {target_obj} order by id; -- one record must remain, with ID = -5
select v.old_id, v.op, v.snap_no_rank -- snap_no_rank must have four unique values: 1,2,3 and 4.
from v_worker_log v
where v.op = 'upd';
--set width who 10;
-- DO NOT check this! Values can differ here from one run to another!
-- select id, trn, who, old_id, new_id, op, rec_vers, global_cn, snap_no from tlog_done order by id;
rollback;
'''
fn_worker_sql.write_text(worker_sql)
with fn_worker_log.open(mode='w') as hang_out, fn_worker_err.open(mode='w') as hang_err:
############################################################################
### L A U N C H W O R K E R U S I N G I S Q L, A S Y N C. ###
############################################################################
p_worker = subprocess.Popen([act.vars['isql'], '-i', str(fn_worker_sql),
'-user', act.db.user,
'-password', act.db.password,
'-pag', '999999',
act.db.dsn
],
stdout = hang_out,
stderr = hang_err
)
# NB: when ISQL will establish attach, first record that it must lock is ID = 2 -- see above SQL_TO_BE_RESTARTED
# We must to ensure that this (worker) attachment has been really created and LOCKS this record:
#
wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=2', SQL_TAG_THAT_WE_WAITING_FOR)
#########################
### L O C K E R - 2 ###
#########################
# Change ID so that it **will* be included in the set of rows that must be affected by session-worker:
con_lock_2.execute_immediate( f'update {target_obj} set id = -5 where abs(id) = 5;' )
con_lock_2.commit()
con_lock_2.execute_immediate( f'update {target_obj} set id = id where abs(id) = 5;' )
con_lock_1.commit() # releases record with ID=1 ==> now it can be locked by worker.
# We have to WAIT HERE until worker will actually 'catch' just released record with ID = 1.
#
wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=1', SQL_TAG_THAT_WE_WAITING_FOR)
# If we come here then it means that record with ID = 1 for sure is locked by WORKER.
# Change ID so that it **will* be included in the set of rows that must be affected by session-worker:
con_lock_1.execute_immediate( f'update {target_obj} set id = -4 where abs(id) = 4;' )
con_lock_1.commit()
con_lock_1.execute_immediate( f'update {target_obj} set id = id where abs(id) = 4;' )
con_lock_2.commit() # releases record with ID = -5, but session-worker is waiting for record with ID = -4 (that was changed by locker-1).
# We have to WAIT HERE until worker will actually 'catch' just released record with ID = -5:
#
wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id = -5', SQL_TAG_THAT_WE_WAITING_FOR)
# If we come here then it means that record with ID = -5 for sure is locked by WORKER.
con_lock_2.execute_immediate( f'update {target_obj} set id = -3 where abs(id) = 3;' )
con_lock_2.commit()
con_lock_2.execute_immediate( f'update {target_obj} set id = id where abs(id) = 3;' )
con_lock_1.commit() # This releases row with ID=-4 but session-worker is waiting for ID = - 3 (changed by locker-2).
# We have to WAIT HERE until worker will actually 'catch' just released record with ID = -4:
#
wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id = -4', SQL_TAG_THAT_WE_WAITING_FOR)
# If we come here then it means that record with ID = -4 for sure is locked by WORKER.
con_lock_2.commit() # This releases row with ID=-3. No more locked rows so session-worker can finish its mission.
# Here we wait for ISQL complete its mission:
p_worker.wait()
# < with act.db.connect
for g in (fn_worker_log, fn_worker_err):
with g.open() as f:
for line in f:
if line.split():
if g == fn_worker_log:
print(f'checked_mode: {checked_mode}, STDLOG: {line}')
else:
print(f'UNEXPECTED STDERR {line}')
expected_stdout_worker = f"""
checked_mode: {checked_mode}, STDLOG: Records affected: 4
checked_mode: {checked_mode}, STDLOG: ID
checked_mode: {checked_mode}, STDLOG: =======
checked_mode: {checked_mode}, STDLOG: -5
checked_mode: {checked_mode}, STDLOG: -2
checked_mode: {checked_mode}, STDLOG: -1
checked_mode: {checked_mode}, STDLOG: 3
checked_mode: {checked_mode}, STDLOG: 4
checked_mode: {checked_mode}, STDLOG: Records affected: 5
checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
checked_mode: {checked_mode}, STDLOG: 2 UPD 1
checked_mode: {checked_mode}, STDLOG: 2 UPD 2
checked_mode: {checked_mode}, STDLOG: 1 UPD 2
checked_mode: {checked_mode}, STDLOG: 2 UPD 3
checked_mode: {checked_mode}, STDLOG: 1 UPD 3
checked_mode: {checked_mode}, STDLOG: 2 UPD 4
checked_mode: {checked_mode}, STDLOG: 1 UPD 4
checked_mode: {checked_mode}, STDLOG: -3 UPD 4
checked_mode: {checked_mode}, STDLOG: -4 UPD 4
checked_mode: {checked_mode}, STDLOG: Records affected: 9
"""
act.expected_stdout = expected_stdout_worker
act.stdout = capsys.readouterr().out
> assert act.clean_stdout == act.clean_expected_stdout
E assert
E checked_mode: table, STDLOG: Records affected: 4
E checked_mode: table, STDLOG: ID
E checked_mode: table, STDLOG:
E checked_mode: table, STDLOG: -5
E checked_mode: table, STDLOG: -2
E checked_mode: table, STDLOG: -1
E checked_mode: table, STDLOG: 3
E checked_mode: table, STDLOG: 4
E checked_mode: table, STDLOG: Records affected: 5
E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
E checked_mode: table, STDLOG:
E - checked_mode: table, STDLOG: 2 UPD 1
E + checked_mode: table, STDLOG: 2UPD 1
E - checked_mode: table, STDLOG: 2 UPD 2
E + checked_mode: table, STDLOG: 2UPD 2
E - checked_mode: table, STDLOG: 1 UPD 2
E + checked_mode: table, STDLOG: 1UPD 2
E - checked_mode: table, STDLOG: 2 UPD 3
E + checked_mode: table, STDLOG: 2UPD 3
E - checked_mode: table, STDLOG: 1 UPD 3
E + checked_mode: table, STDLOG: 1UPD 3
E - checked_mode: table, STDLOG: 2 UPD 4
E + checked_mode: table, STDLOG: 2UPD 4
E - checked_mode: table, STDLOG: 1 UPD 4
E + checked_mode: table, STDLOG: 1UPD 4
E - checked_mode: table, STDLOG: -3 UPD 4
E + checked_mode: table, STDLOG: -3UPD 4
E - checked_mode: table, STDLOG: -4 UPD 4
E + checked_mode: table, STDLOG: -4UPD 4
E checked_mode: table, STDLOG: Records affected: 9
tests/functional/transactions/test_read_consist_sttm_restart_on_merge_04.py:447: AssertionError
|