2 @message |
assert
checked_mode: table, STDLOG: Records affected: 9
checked_mode: table, STDLOG: ID
checked_mode: table, STDLOG:
checked_mode: table, STDLOG: -14
checked_mode: table, STDLOG: -13
checked_mode: table, STDLOG: -12
checked_mode: table, STDLOG: -11
checked_mode: table, STDLOG: -5
checked_mode: table, STDLOG: -4
checked_mode: table, STDLOG: -3
checked_mode: table, STDLOG: -2
checked_mode: table, STDLOG: -1
checked_mode: table, STDLOG: Records affected: 9
checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: table, STDLOG:
- checked_mode: table, STDLOG: 5 UPD 1
+ checked_mode: table, STDLOG: 5UPD 1
- checked_mode: table, STDLOG: 4 UPD 1
+ checked_mode: table, STDLOG: 4UPD 1
- checked_mode: table, STDLOG: 3 UPD 1
+ checked_mode: table, STDLOG: 3UPD 1
- checked_mode: table, STDLOG: 2 UPD 1
+ checked_mode: table, STDLOG: 2UPD 1
- checked_mode: table, STDLOG: 14 UPD 2
+ checked_mode: table, STDLOG: 14UPD 2
- checked_mode: table, STDLOG: 13 UPD 2
+ checked_mode: table, STDLOG: 13UPD 2
- checked_mode: table, STDLOG: 12 UPD 2
+ checked_mode: table, STDLOG: 12UPD 2
- checked_mode: table, STDLOG: 11 UPD 2
+ checked_mode: table, STDLOG: 11UPD 2
- checked_mode: table, STDLOG: 5 UPD 2
+ checked_mode: table, STDLOG: 5UPD 2
- checked_mode: table, STDLOG: 4 UPD 2
+ checked_mode: table, STDLOG: 4UPD 2
- checked_mode: table, STDLOG: 3 UPD 2
+ checked_mode: table, STDLOG: 3UPD 2
- 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: Records affected: 13
LOG DETAILS:
2025-07-02 06:07:55.728
2025-07-02 06:07:55.734 act = <firebird.qa.plugin.Action object at [hex]>
2025-07-02 06:07:55.740 fn_worker_sql = PosixPath('/var/tmp/qa_2024/test_12486/tmp_worker.sql')
2025-07-02 06:07:55.746 fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12486/tmp_worker.log')
2025-07-02 06:07:55.753 fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12486/tmp_worker.err')
2025-07-02 06:07:55.760 capsys = <_pytest.capture.CaptureFixture object at [hex]>
2025-07-02 06:07:55.767
2025-07-02 06:07:55.774 @pytest.mark.trace
2025-07-02 06:07:55.781 @pytest.mark.version('>=4.0')
2025-07-02 06:07:55.789 def test_1(act: Action, fn_worker_sql: Path, fn_worker_log: Path, fn_worker_err: Path, capsys):
2025-07-02 06:07:55.797 sql_init = (act.files_dir / 'read-consist-sttm-restart-DDL.sql').read_text()
2025-07-02 06:07:55.804
2025-07-02 06:07:55.811 for checked_mode in('table', 'view'):
2025-07-02 06:07:55.819 target_obj = 'test' if checked_mode == 'table' else 'v_test'
2025-07-02 06:07:55.826
2025-07-02 06:07:55.834 # SQL_TO_BE_RESTARTED = f"update /* {SQL_TAG_THAT_WE_WAITING_FOR} */ {target_obj} set id = -id order by id DESC"
2025-07-02 06:07:55.843 SQL_TO_BE_RESTARTED = f"update /* {SQL_TAG_THAT_WE_WAITING_FOR} */ {target_obj} set id = -id where exists(select * from {target_obj} where id > 0) order by id DESC"
2025-07-02 06:07:55.850
2025-07-02 06:07:55.858 # add rows with ID = 1, 2, ..., 5:
2025-07-02 06:07:55.866 sql_addi = f'''
2025-07-02 06:07:55.873 set term ^;
2025-07-02 06:07:55.883 execute block as
2025-07-02 06:07:55.894 begin
2025-07-02 06:07:55.906 rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
2025-07-02 06:07:55.914 end
2025-07-02 06:07:55.921 ^
2025-07-02 06:07:55.927 set term ;^
2025-07-02 06:07:55.932 insert into {target_obj}(id, x) select row_number()over(),row_number()over() from rdb$types rows 5;
2025-07-02 06:07:55.937 commit;
2025-07-02 06:07:55.942 '''
2025-07-02 06:07:55.948
2025-07-02 06:07:55.953 act.isql(switches=['-q'], input = ''.join( (sql_init, sql_addi) ) )
2025-07-02 06:07:55.958 # ::: NOTE ::: We have to immediately quit if any error raised in prepare phase.
2025-07-02 06:07:55.964 # See also letter from dimitr, 01-feb-2022 14:46
2025-07-02 06:07:55.969 assert act.stderr == ''
2025-07-02 06:07:55.974 act.reset()
2025-07-02 06:07:55.978
2025-07-02 06:07:55.983 trace_cfg_items = [
2025-07-02 06:07:55.988 'time_threshold = 0',
2025-07-02 06:07:55.993 'log_errors = true',
2025-07-02 06:07:56.002 'log_statement_start = true',
2025-07-02 06:07:56.014 'log_statement_finish = true',
2025-07-02 06:07:56.022 ]
2025-07-02 06:07:56.029
2025-07-02 06:07:56.036 with act.trace(db_events = trace_cfg_items, encoding=locale.getpreferredencoding()):
2025-07-02 06:07:56.043
2025-07-02 06:07:56.049 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:56.056
2025-07-02 06:07:56.063 tpb_monitoring = tpb(isolation=Isolation.READ_COMMITTED_RECORD_VERSION, lock_timeout=0)
2025-07-02 06:07:56.069 tx_monitoring = con_monitoring.transaction_manager(tpb_monitoring)
2025-07-02 06:07:56.076 cur_monitoring = tx_monitoring.cursor()
2025-07-02 06:07:56.082
2025-07-02 06:07:56.088 for i,c in enumerate((con_lock_1,con_lock_2)):
2025-07-02 06:07:56.095 sttm = f"execute block as begin rdb$set_context('USER_SESSION', 'WHO', 'LOCKER #{i+1}'); end"
2025-07-02 06:07:56.101 c.execute_immediate(sttm)
2025-07-02 06:07:56.107
2025-07-02 06:07:56.115 #########################
2025-07-02 06:07:56.126 ### L O C K E R - 1 ###
2025-07-02 06:07:56.135 #########################
2025-07-02 06:07:56.143
2025-07-02 06:07:56.150 con_lock_1.execute_immediate( f'update {target_obj} set id = id where id = 1' )
2025-07-02 06:07:56.156
2025-07-02 06:07:56.163 worker_sql = f'''
2025-07-02 06:07:56.169 set list on;
2025-07-02 06:07:56.176 set autoddl off;
2025-07-02 06:07:56.182 set term ^;
2025-07-02 06:07:56.188 execute block returns (whoami varchar(30)) as
2025-07-02 06:07:56.194 begin
2025-07-02 06:07:56.200 whoami = 'WORKER'; -- , ATT#' || current_connection;
2025-07-02 06:07:56.207 rdb$set_context('USER_SESSION','WHO', whoami);
2025-07-02 06:07:56.213 -- suspend;
2025-07-02 06:07:56.219 end
2025-07-02 06:07:56.227 ^
2025-07-02 06:07:56.238 set term ;^
2025-07-02 06:07:56.248 commit;
2025-07-02 06:07:56.256
2025-07-02 06:07:56.264 SET KEEP_TRAN_PARAMS ON;
2025-07-02 06:07:56.271 set transaction read committed read consistency;
2025-07-02 06:07:56.278 set list off;
2025-07-02 06:07:56.285 set wng off;
2025-07-02 06:07:56.291 set count on;
2025-07-02 06:07:56.298
2025-07-02 06:07:56.304 -- THIS MUST BE LOCKED
2025-07-02 06:07:56.310 {SQL_TO_BE_RESTARTED};
2025-07-02 06:07:56.317
2025-07-02 06:07:56.323 -- check results:
2025-07-02 06:07:56.336 -- ###############
2025-07-02 06:07:56.348 select id from {target_obj} order by id; -- this will produce output only after all lockers do their commit/rollback
2025-07-02 06:07:56.357
2025-07-02 06:07:56.365 select v.old_id, v.op, v.snap_no_rank from v_worker_log v where v.op = 'upd';
2025-07-02 06:07:56.371
2025-07-02 06:07:56.378 set width who 10;
2025-07-02 06:07:56.383 -- DO NOT check this! Values can differ here from one run to another!
2025-07-02 06:07:56.389 -- 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:56.396
2025-07-02 06:07:56.409 rollback;
2025-07-02 06:07:56.423
2025-07-02 06:07:56.435 '''
2025-07-02 06:07:56.443
2025-07-02 06:07:56.451 fn_worker_sql.write_text(worker_sql)
2025-07-02 06:07:56.458
2025-07-02 06:07:56.468 with fn_worker_log.open(mode='w') as hang_out, fn_worker_err.open(mode='w') as hang_err:
2025-07-02 06:07:56.479
2025-07-02 06:07:56.488 ############################################################################
2025-07-02 06:07:56.495 ### 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:56.502 ############################################################################
2025-07-02 06:07:56.510 p_worker = subprocess.Popen([act.vars['isql'], '-i', str(fn_worker_sql),
2025-07-02 06:07:56.517 '-user', act.db.user,
2025-07-02 06:07:56.525 '-password', act.db.password,
2025-07-02 06:07:56.531 '-pag', '999999',
2025-07-02 06:07:56.542 act.db.dsn
2025-07-02 06:07:56.555 ],
2025-07-02 06:07:56.564 stdout = hang_out,
2025-07-02 06:07:56.572 stderr = hang_err
2025-07-02 06:07:56.579 )
2025-07-02 06:07:56.586 # NB: when ISQL will establish attach, first record that it must lock is ID = 5 -- see above SQL_TO_BE_RESTARTED
2025-07-02 06:07:56.592 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:07:56.604 #
2025-07-02 06:07:56.618 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:56.629
2025-07-02 06:07:56.639 #########################
2025-07-02 06:07:56.651 ### L O C K E R - 2 ###
2025-07-02 06:07:56.660 #########################
2025-07-02 06:07:56.670 con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(11)' )
2025-07-02 06:07:56.680 con_lock_2.commit()
2025-07-02 06:07:56.691 con_lock_2.execute_immediate( f'update {target_obj} set id = id where id = 11' )
2025-07-02 06:07:56.700
2025-07-02 06:07:56.711 #########################
2025-07-02 06:07:56.721 ### L O C K E R - 1 ###
2025-07-02 06:07:56.730 #########################
2025-07-02 06:07:56.739 con_lock_1.commit() # releases record with ID = 1 ==> now it can be locked by worker.
2025-07-02 06:07:56.745
2025-07-02 06:07:56.751
2025-07-02 06:07:56.758 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 1.
2025-07-02 06:07:56.764 #
2025-07-02 06:07:56.770 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:56.777 # If we come here then it means that record with ID = 1 for sure is locked by WORKER.
2025-07-02 06:07:56.783
2025-07-02 06:07:56.788
2025-07-02 06:07:56.794 con_lock_1.execute_immediate( f'insert into {target_obj}(id) values(12)' )
2025-07-02 06:07:56.808 con_lock_1.commit()
2025-07-02 06:07:56.818 con_lock_1.execute_immediate( f'update {target_obj} set id = id where id = 12' )
2025-07-02 06:07:56.825
2025-07-02 06:07:56.837
2025-07-02 06:07:56.847 #########################
2025-07-02 06:07:56.855 ### L O C K E R - 2 ###
2025-07-02 06:07:56.862 #########################
2025-07-02 06:07:56.872 con_lock_2.commit() # releases record with ID = 11 ==> now it can be locked by worker.
2025-07-02 06:07:56.883
2025-07-02 06:07:56.896 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 11.
2025-07-02 06:07:56.909 #
2025-07-02 06:07:56.922 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=11', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:07:56.930 # If we come here then it means that record with ID = 11 for sure is locked by WORKER.
2025-07-02 06:07:56.936
2025-07-02 06:07:56.942
2025-07-02 06:07:56.950 con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(13)' )
2025-07-02 06:07:56.957 con_lock_2.commit()
2025-07-02 06:07:56.966 con_lock_2.execute_immediate( f'update {target_obj} set id = id where id = 13' )
2025-07-02 06:07:56.974
2025-07-02 06:07:56.981 #########################
2025-07-02 06:07:56.987 ### L O C K E R - 1 ###
2025-07-02 06:07:56.993 #########################
2025-07-02 06:07:57.000 con_lock_1.commit() # releases record with ID = 12 ==> now it can be locked by worker.
2025-07-02 06:07:57.006
2025-07-02 06:07:57.020 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 12.
2025-07-02 06:07:57.031 #
2025-07-02 06:07:57.040 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=12', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:07:57.050 # If we come here then it means that record with ID = 12 for sure is locked by WORKER.
2025-07-02 06:07:57.060
2025-07-02 06:07:57.068 con_lock_1.execute_immediate( f'insert into {target_obj}(id) values(14)' )
2025-07-02 06:07:57.075 con_lock_1.commit()
2025-07-02 06:07:57.084 con_lock_1.execute_immediate( f'update {target_obj} set id = id where id = 14' )
2025-07-02 06:07:57.095
2025-07-02 06:07:57.104 #########################
2025-07-02 06:07:57.113 ### L O C K E R - 2 ###
2025-07-02 06:07:57.124 #########################
2025-07-02 06:07:57.134 con_lock_2.commit()
2025-07-02 06:07:57.144
2025-07-02 06:07:57.153 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 13.
2025-07-02 06:07:57.163 #
2025-07-02 06:07:57.177 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=13', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:07:57.190 # If we come here then it means that record with ID = 13 for sure is locked by WORKER.
2025-07-02 06:07:57.202
2025-07-02 06:07:57.213 #########################
2025-07-02 06:07:57.226 ### L O C K E R - 1 ###
2025-07-02 06:07:57.237 #########################
2025-07-02 06:07:57.246 con_lock_1.commit() # WORKER will complete his job after this
2025-07-02 06:07:57.255
2025-07-02 06:07:57.267
2025-07-02 06:07:57.276 # Here we wait for ISQL complete its mission:
2025-07-02 06:07:57.283 p_worker.wait()
2025-07-02 06:07:57.291
2025-07-02 06:07:57.299 #< with act.db.connect()
2025-07-02 06:07:57.307
2025-07-02 06:07:57.315 for g in (fn_worker_log, fn_worker_err):
2025-07-02 06:07:57.323 with g.open() as f:
2025-07-02 06:07:57.330 for line in f:
2025-07-02 06:07:57.336 if line.split():
2025-07-02 06:07:57.341 if g == fn_worker_log:
2025-07-02 06:07:57.347 print(f'checked_mode: {checked_mode}, STDLOG: {line}')
2025-07-02 06:07:57.355 else:
2025-07-02 06:07:57.368 print(f'UNEXPECTED STDERR {line}')
2025-07-02 06:07:57.377
2025-07-02 06:07:57.391 expected_stdout_worker = f"""
2025-07-02 06:07:57.403 checked_mode: {checked_mode}, STDLOG: Records affected: 9
2025-07-02 06:07:57.414
2025-07-02 06:07:57.423 checked_mode: {checked_mode}, STDLOG: ID
2025-07-02 06:07:57.431 checked_mode: {checked_mode}, STDLOG: =======
2025-07-02 06:07:57.437 checked_mode: {checked_mode}, STDLOG: -14
2025-07-02 06:07:57.444 checked_mode: {checked_mode}, STDLOG: -13
2025-07-02 06:07:57.450 checked_mode: {checked_mode}, STDLOG: -12
2025-07-02 06:07:57.461 checked_mode: {checked_mode}, STDLOG: -11
2025-07-02 06:07:57.471 checked_mode: {checked_mode}, STDLOG: -5
2025-07-02 06:07:57.478 checked_mode: {checked_mode}, STDLOG: -4
2025-07-02 06:07:57.486 checked_mode: {checked_mode}, STDLOG: -3
2025-07-02 06:07:57.496 checked_mode: {checked_mode}, STDLOG: -2
2025-07-02 06:07:57.506 checked_mode: {checked_mode}, STDLOG: -1
2025-07-02 06:07:57.517 checked_mode: {checked_mode}, STDLOG: Records affected: 9
2025-07-02 06:07:57.531
2025-07-02 06:07:57.543 checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:07:57.550 checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
2025-07-02 06:07:57.557 checked_mode: {checked_mode}, STDLOG: 5 UPD 1
2025-07-02 06:07:57.563 checked_mode: {checked_mode}, STDLOG: 4 UPD 1
2025-07-02 06:07:57.570 checked_mode: {checked_mode}, STDLOG: 3 UPD 1
2025-07-02 06:07:57.579 checked_mode: {checked_mode}, STDLOG: 2 UPD 1
2025-07-02 06:07:57.593 checked_mode: {checked_mode}, STDLOG: 14 UPD 2
2025-07-02 06:07:57.602 checked_mode: {checked_mode}, STDLOG: 13 UPD 2
2025-07-02 06:07:57.610 checked_mode: {checked_mode}, STDLOG: 12 UPD 2
2025-07-02 06:07:57.615 checked_mode: {checked_mode}, STDLOG: 11 UPD 2
2025-07-02 06:07:57.621 checked_mode: {checked_mode}, STDLOG: 5 UPD 2
2025-07-02 06:07:57.629 checked_mode: {checked_mode}, STDLOG: 4 UPD 2
2025-07-02 06:07:57.637 checked_mode: {checked_mode}, STDLOG: 3 UPD 2
2025-07-02 06:07:57.644 checked_mode: {checked_mode}, STDLOG: 2 UPD 2
2025-07-02 06:07:57.652 checked_mode: {checked_mode}, STDLOG: 1 UPD 2
2025-07-02 06:07:57.659
2025-07-02 06:07:57.667 checked_mode: {checked_mode}, STDLOG: Records affected: 13
2025-07-02 06:07:57.674 """
2025-07-02 06:07:57.682
2025-07-02 06:07:57.689 act.expected_stdout = expected_stdout_worker
2025-07-02 06:07:57.697 act.stdout = capsys.readouterr().out
2025-07-02 06:07:57.704 > assert act.clean_stdout == act.clean_expected_stdout
2025-07-02 06:07:57.712 E assert
2025-07-02 06:07:57.723 E checked_mode: table, STDLOG: Records affected: 9
2025-07-02 06:07:57.735 E checked_mode: table, STDLOG: ID
2025-07-02 06:07:57.743 E checked_mode: table, STDLOG:
2025-07-02 06:07:57.751 E checked_mode: table, STDLOG: -14
2025-07-02 06:07:57.757 E checked_mode: table, STDLOG: -13
2025-07-02 06:07:57.764 E checked_mode: table, STDLOG: -12
2025-07-02 06:07:57.770 E checked_mode: table, STDLOG: -11
2025-07-02 06:07:57.779 E checked_mode: table, STDLOG: -5
2025-07-02 06:07:57.792 E checked_mode: table, STDLOG: -4
2025-07-02 06:07:57.801 E checked_mode: table, STDLOG: -3
2025-07-02 06:07:57.809 E checked_mode: table, STDLOG: -2
2025-07-02 06:07:57.816 E checked_mode: table, STDLOG: -1
2025-07-02 06:07:57.823 E checked_mode: table, STDLOG: Records affected: 9
2025-07-02 06:07:57.831 E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:07:57.839 E checked_mode: table, STDLOG:
2025-07-02 06:07:57.847 E - checked_mode: table, STDLOG: 5 UPD 1
2025-07-02 06:07:57.863 E + checked_mode: table, STDLOG: 5UPD 1
2025-07-02 06:07:57.871 E - checked_mode: table, STDLOG: 4 UPD 1
2025-07-02 06:07:57.887 E + checked_mode: table, STDLOG: 4UPD 1
2025-07-02 06:07:57.894 E - checked_mode: table, STDLOG: 3 UPD 1
2025-07-02 06:07:57.915 E + checked_mode: table, STDLOG: 3UPD 1
2025-07-02 06:07:57.923 E - checked_mode: table, STDLOG: 2 UPD 1
2025-07-02 06:07:57.936 E + checked_mode: table, STDLOG: 2UPD 1
2025-07-02 06:07:57.942 E - checked_mode: table, STDLOG: 14 UPD 2
2025-07-02 06:07:57.954 E + checked_mode: table, STDLOG: 14UPD 2
2025-07-02 06:07:57.960 E - checked_mode: table, STDLOG: 13 UPD 2
2025-07-02 06:07:57.971 E + checked_mode: table, STDLOG: 13UPD 2
2025-07-02 06:07:57.977 E - checked_mode: table, STDLOG: 12 UPD 2
2025-07-02 06:07:57.999 E + checked_mode: table, STDLOG: 12UPD 2
2025-07-02 06:07:58.008 E - checked_mode: table, STDLOG: 11 UPD 2
2025-07-02 06:07:58.032 E + checked_mode: table, STDLOG: 11UPD 2
2025-07-02 06:07:58.041 E - checked_mode: table, STDLOG: 5 UPD 2
2025-07-02 06:07:58.063 E + checked_mode: table, STDLOG: 5UPD 2
2025-07-02 06:07:58.073 E - checked_mode: table, STDLOG: 4 UPD 2
2025-07-02 06:07:58.087 E + checked_mode: table, STDLOG: 4UPD 2
2025-07-02 06:07:58.093 E - checked_mode: table, STDLOG: 3 UPD 2
2025-07-02 06:07:58.108 E + checked_mode: table, STDLOG: 3UPD 2
2025-07-02 06:07:58.115 E - checked_mode: table, STDLOG: 2 UPD 2
2025-07-02 06:07:58.128 E + checked_mode: table, STDLOG: 2UPD 2
2025-07-02 06:07:58.135 E - checked_mode: table, STDLOG: 1 UPD 2
2025-07-02 06:07:58.151 E + checked_mode: table, STDLOG: 1UPD 2
2025-07-02 06:07:58.159 E checked_mode: table, STDLOG: Records affected: 13
2025-07-02 06:07:58.166
2025-07-02 06:07:58.174 tests/functional/transactions/test_read_consist_sttm_restart_on_update_02.py:457: AssertionError
2025-07-02 06:07:58.183 ---------------------------- Captured stdout setup -----------------------------
2025-07-02 06:07:58.192 Creating db: localhost:/var/tmp/qa_2024/test_12486/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_12486/tmp_worker.sql')
fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12486/tmp_worker.log')
fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12486/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"update /* {SQL_TAG_THAT_WE_WAITING_FOR} */ {target_obj} set id = -id order by id DESC"
SQL_TO_BE_RESTARTED = f"update /* {SQL_TAG_THAT_WE_WAITING_FOR} */ {target_obj} set id = -id where exists(select * from {target_obj} where id > 0) order by id DESC"
# add rows with ID = 1, 2, ..., 5:
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 BE LOCKED
{SQL_TO_BE_RESTARTED};
-- check results:
-- ###############
select id from {target_obj} order by id; -- this will produce output only after all lockers do their commit/rollback
select v.old_id, v.op, v.snap_no_rank 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 = 5 -- 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=5', SQL_TAG_THAT_WE_WAITING_FOR)
#########################
### L O C K E R - 2 ###
#########################
con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(11)' )
con_lock_2.commit()
con_lock_2.execute_immediate( f'update {target_obj} set id = id where id = 11' )
#########################
### L O C K E R - 1 ###
#########################
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.
con_lock_1.execute_immediate( f'insert into {target_obj}(id) values(12)' )
con_lock_1.commit()
con_lock_1.execute_immediate( f'update {target_obj} set id = id where id = 12' )
#########################
### L O C K E R - 2 ###
#########################
con_lock_2.commit() # releases record with ID = 11 ==> now it can be locked by worker.
# We have to WAIT HERE until worker will actually 'catch' just released record with ID = 11.
#
wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=11', SQL_TAG_THAT_WE_WAITING_FOR)
# If we come here then it means that record with ID = 11 for sure is locked by WORKER.
con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(13)' )
con_lock_2.commit()
con_lock_2.execute_immediate( f'update {target_obj} set id = id where id = 13' )
#########################
### L O C K E R - 1 ###
#########################
con_lock_1.commit() # releases record with ID = 12 ==> now it can be locked by worker.
# We have to WAIT HERE until worker will actually 'catch' just released record with ID = 12.
#
wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=12', SQL_TAG_THAT_WE_WAITING_FOR)
# If we come here then it means that record with ID = 12 for sure is locked by WORKER.
con_lock_1.execute_immediate( f'insert into {target_obj}(id) values(14)' )
con_lock_1.commit()
con_lock_1.execute_immediate( f'update {target_obj} set id = id where id = 14' )
#########################
### L O C K E R - 2 ###
#########################
con_lock_2.commit()
# We have to WAIT HERE until worker will actually 'catch' just released record with ID = 13.
#
wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=13', SQL_TAG_THAT_WE_WAITING_FOR)
# If we come here then it means that record with ID = 13 for sure is locked by WORKER.
#########################
### L O C K E R - 1 ###
#########################
con_lock_1.commit() # WORKER will complete his job after this
# 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: 9
checked_mode: {checked_mode}, STDLOG: ID
checked_mode: {checked_mode}, STDLOG: =======
checked_mode: {checked_mode}, STDLOG: -14
checked_mode: {checked_mode}, STDLOG: -13
checked_mode: {checked_mode}, STDLOG: -12
checked_mode: {checked_mode}, STDLOG: -11
checked_mode: {checked_mode}, STDLOG: -5
checked_mode: {checked_mode}, STDLOG: -4
checked_mode: {checked_mode}, STDLOG: -3
checked_mode: {checked_mode}, STDLOG: -2
checked_mode: {checked_mode}, STDLOG: -1
checked_mode: {checked_mode}, STDLOG: Records affected: 9
checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
checked_mode: {checked_mode}, STDLOG: 5 UPD 1
checked_mode: {checked_mode}, STDLOG: 4 UPD 1
checked_mode: {checked_mode}, STDLOG: 3 UPD 1
checked_mode: {checked_mode}, STDLOG: 2 UPD 1
checked_mode: {checked_mode}, STDLOG: 14 UPD 2
checked_mode: {checked_mode}, STDLOG: 13 UPD 2
checked_mode: {checked_mode}, STDLOG: 12 UPD 2
checked_mode: {checked_mode}, STDLOG: 11 UPD 2
checked_mode: {checked_mode}, STDLOG: 5 UPD 2
checked_mode: {checked_mode}, STDLOG: 4 UPD 2
checked_mode: {checked_mode}, STDLOG: 3 UPD 2
checked_mode: {checked_mode}, STDLOG: 2 UPD 2
checked_mode: {checked_mode}, STDLOG: 1 UPD 2
checked_mode: {checked_mode}, STDLOG: Records affected: 13
"""
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: 9
E checked_mode: table, STDLOG: ID
E checked_mode: table, STDLOG:
E checked_mode: table, STDLOG: -14
E checked_mode: table, STDLOG: -13
E checked_mode: table, STDLOG: -12
E checked_mode: table, STDLOG: -11
E checked_mode: table, STDLOG: -5
E checked_mode: table, STDLOG: -4
E checked_mode: table, STDLOG: -3
E checked_mode: table, STDLOG: -2
E checked_mode: table, STDLOG: -1
E checked_mode: table, STDLOG: Records affected: 9
E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
E checked_mode: table, STDLOG:
E - checked_mode: table, STDLOG: 5 UPD 1
E + checked_mode: table, STDLOG: 5UPD 1
E - checked_mode: table, STDLOG: 4 UPD 1
E + checked_mode: table, STDLOG: 4UPD 1
E - checked_mode: table, STDLOG: 3 UPD 1
E + checked_mode: table, STDLOG: 3UPD 1
E - checked_mode: table, STDLOG: 2 UPD 1
E + checked_mode: table, STDLOG: 2UPD 1
E - checked_mode: table, STDLOG: 14 UPD 2
E + checked_mode: table, STDLOG: 14UPD 2
E - checked_mode: table, STDLOG: 13 UPD 2
E + checked_mode: table, STDLOG: 13UPD 2
E - checked_mode: table, STDLOG: 12 UPD 2
E + checked_mode: table, STDLOG: 12UPD 2
E - checked_mode: table, STDLOG: 11 UPD 2
E + checked_mode: table, STDLOG: 11UPD 2
E - checked_mode: table, STDLOG: 5 UPD 2
E + checked_mode: table, STDLOG: 5UPD 2
E - checked_mode: table, STDLOG: 4 UPD 2
E + checked_mode: table, STDLOG: 4UPD 2
E - checked_mode: table, STDLOG: 3 UPD 2
E + checked_mode: table, STDLOG: 3UPD 2
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: Records affected: 13
tests/functional/transactions/test_read_consist_sttm_restart_on_update_02.py:457: AssertionError
|