2 @message |
assert
checked_mode: table, STDLOG: Records affected: 2
checked_mode: table, STDLOG: ID X
checked_mode: table, STDLOG:
checked_mode: table, STDLOG: -5 5
checked_mode: table, STDLOG: -4 4
checked_mode: table, STDLOG: -3 3
checked_mode: table, STDLOG: -2 2
checked_mode: table, STDLOG: -1 1
checked_mode: table, STDLOG: 0 0
checked_mode: table, STDLOG: 1 1
checked_mode: table, STDLOG: Records affected: 7
checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: table, STDLOG:
- checked_mode: table, STDLOG: 0 UPD 1
+ checked_mode: table, STDLOG: 0UPD 1
- checked_mode: table, STDLOG: 1 UPD 1
+ checked_mode: table, STDLOG: 1UPD 1
- checked_mode: table, STDLOG: 0 UPD 2
+ checked_mode: table, STDLOG: 0UPD 2
- checked_mode: table, STDLOG: 1 UPD 2
+ checked_mode: table, STDLOG: 1UPD 2
- checked_mode: table, STDLOG: 0 UPD 3
+ checked_mode: table, STDLOG: 0UPD 3
- checked_mode: table, STDLOG: 1 UPD 3
+ checked_mode: table, STDLOG: 1UPD 3
- checked_mode: table, STDLOG: 0 UPD 4
+ checked_mode: table, STDLOG: 0UPD 4
- checked_mode: table, STDLOG: 1 UPD 4
+ checked_mode: table, STDLOG: 1UPD 4
- checked_mode: table, STDLOG: 0 UPD 5
+ checked_mode: table, STDLOG: 0UPD 5
- checked_mode: table, STDLOG: 1 UPD 5
+ checked_mode: table, STDLOG: 1UPD 5
checked_mode: table, STDLOG: Records affected: 10
checked_mode: table, STDERR: Statement failed, SQLSTATE 21000
checked_mode: table, STDERR: Multiple source records cannot match the same target during MERGE
checked_mode: table, STDERR:
LOG DETAILS:
2025-07-02 06:41:24.287
2025-07-02 06:41:24.287 act = <firebird.qa.plugin.Action object at [hex]>
2025-07-02 06:41:24.287 fn_worker_sql = WindowsPath('H:/QA/temp/qa2024.tmp/fbqa/test_12497/tmp_worker.sql')
2025-07-02 06:41:24.287 fn_worker_log = WindowsPath('H:/QA/temp/qa2024.tmp/fbqa/test_12497/tmp_worker.log')
2025-07-02 06:41:24.287 fn_worker_err = WindowsPath('H:/QA/temp/qa2024.tmp/fbqa/test_12497/tmp_worker.err')
2025-07-02 06:41:24.287 capsys = <_pytest.capture.CaptureFixture object at [hex]>
2025-07-02 06:41:24.287
2025-07-02 06:41:24.287 @pytest.mark.trace
2025-07-02 06:41:24.287 @pytest.mark.version('>=4.0.2')
2025-07-02 06:41:24.287 def test_1(act: Action, fn_worker_sql: Path, fn_worker_log: Path, fn_worker_err: Path, capsys):
2025-07-02 06:41:24.288 sql_init = (act.files_dir / 'read-consist-sttm-restart-DDL.sql').read_text()
2025-07-02 06:41:24.288
2025-07-02 06:41:24.288 for checked_mode in('table', 'view'):
2025-07-02 06:41:24.288 target_obj = 'test' if checked_mode == 'table' else 'v_test'
2025-07-02 06:41:24.288
2025-07-02 06:41:24.288 SQL_TO_BE_RESTARTED = f"""
2025-07-02 06:41:24.288 merge /* {SQL_TAG_THAT_WE_WAITING_FOR} */ into {target_obj} t
2025-07-02 06:41:24.288 using (
2025-07-02 06:41:24.288 select s.id, s.x from {target_obj} as s
2025-07-02 06:41:24.288 where s.id <= 1
2025-07-02 06:41:24.288 order by s.id DESC -- added only 05-jun-2024; thanks to Vlad.
2025-07-02 06:41:24.288 ) s
2025-07-02 06:41:24.288 on abs(t.id) = abs(s.id)
2025-07-02 06:41:24.288 when matched then
2025-07-02 06:41:24.288 update set t.x = s.id * 100
2025-07-02 06:41:24.288 """
2025-07-02 06:41:24.288
2025-07-02 06:41:24.288 sql_addi = f'''
2025-07-02 06:41:24.288 set term ^;
2025-07-02 06:41:24.289 execute block as
2025-07-02 06:41:24.289 begin
2025-07-02 06:41:24.289 rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
2025-07-02 06:41:24.289 end
2025-07-02 06:41:24.289 ^
2025-07-02 06:41:24.289 set term ;^
2025-07-02 06:41:24.289
2025-07-02 06:41:24.289 -- INITIAL DATA: add rows with ID = 0...6
2025-07-02 06:41:24.289 -- #############
2025-07-02 06:41:24.289 insert into {target_obj}(id, x)
2025-07-02 06:41:24.289 select row_number()over()-1, row_number()over()-1
2025-07-02 06:41:24.289 from rdb$types rows 6;
2025-07-02 06:41:24.289
2025-07-02 06:41:24.289 commit;
2025-07-02 06:41:24.289 '''
2025-07-02 06:41:24.289
2025-07-02 06:41:24.289 act.isql(switches=['-q'], input = ''.join( (sql_init, sql_addi) ) )
2025-07-02 06:41:24.289 # ::: NOTE ::: We have to immediately quit if any error raised in prepare phase.
2025-07-02 06:41:24.289 # See also letter from dimitr, 01-feb-2022 14:46
2025-07-02 06:41:24.289 assert act.stderr == ''
2025-07-02 06:41:24.290 act.reset()
2025-07-02 06:41:24.290
2025-07-02 06:41:24.290 trace_cfg_items = [
2025-07-02 06:41:24.290 'time_threshold = 0',
2025-07-02 06:41:24.290 'log_errors = true',
2025-07-02 06:41:24.290 'log_statement_start = true',
2025-07-02 06:41:24.290 'log_statement_finish = true',
2025-07-02 06:41:24.290 ]
2025-07-02 06:41:24.290
2025-07-02 06:41:24.290 with act.trace(db_events = trace_cfg_items, encoding=locale.getpreferredencoding()):
2025-07-02 06:41:24.290
2025-07-02 06:41:24.290 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:41:24.290
2025-07-02 06:41:24.290 tpb_monitoring = tpb(isolation=Isolation.READ_COMMITTED_RECORD_VERSION, lock_timeout=0)
2025-07-02 06:41:24.290 tx_monitoring = con_monitoring.transaction_manager(tpb_monitoring)
2025-07-02 06:41:24.290 cur_monitoring = tx_monitoring.cursor()
2025-07-02 06:41:24.290
2025-07-02 06:41:24.290 cur_lock_1 = con_lock_1.cursor()
2025-07-02 06:41:24.290 cur_lock_2 = con_lock_2.cursor()
2025-07-02 06:41:24.291
2025-07-02 06:41:24.291 for i,c in enumerate((con_lock_1,con_lock_2)):
2025-07-02 06:41:24.291 sttm = f"execute block as begin rdb$set_context('USER_SESSION', 'WHO', 'LOCKER #{i+1}'); end"
2025-07-02 06:41:24.291 c.execute_immediate(sttm)
2025-07-02 06:41:24.291
2025-07-02 06:41:24.291
2025-07-02 06:41:24.291 #########################
2025-07-02 06:41:24.291 ### L O C K E R - 1 ###
2025-07-02 06:41:24.291 #########################
2025-07-02 06:41:24.291
2025-07-02 06:41:24.291 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id = 0' )
2025-07-02 06:41:24.291
2025-07-02 06:41:24.291 worker_sql = f'''
2025-07-02 06:41:24.291 set list on;
2025-07-02 06:41:24.291 set autoddl off;
2025-07-02 06:41:24.291 set term ^;
2025-07-02 06:41:24.291 execute block as
2025-07-02 06:41:24.291 begin
2025-07-02 06:41:24.291 rdb$set_context('USER_SESSION','WHO', 'WORKER');
2025-07-02 06:41:24.291 end
2025-07-02 06:41:24.291 ^
2025-07-02 06:41:24.292 set term ;^
2025-07-02 06:41:24.292 commit;
2025-07-02 06:41:24.292 SET KEEP_TRAN_PARAMS ON;
2025-07-02 06:41:24.292 set transaction read committed read consistency;
2025-07-02 06:41:24.292 set list off;
2025-07-02 06:41:24.292 set wng off;
2025-07-02 06:41:24.292
2025-07-02 06:41:24.292 set count on;
2025-07-02 06:41:24.292 -- THIS MUST HANG:
2025-07-02 06:41:24.292 {SQL_TO_BE_RESTARTED};
2025-07-02 06:41:24.292
2025-07-02 06:41:24.292 -- check results:
2025-07-02 06:41:24.292 -- ###############
2025-07-02 06:41:24.292 select id,x from {target_obj} order by id;
2025-07-02 06:41:24.292
2025-07-02 06:41:24.292 select v.old_id, v.op, v.snap_no_rank
2025-07-02 06:41:24.292 from v_worker_log v
2025-07-02 06:41:24.292 where v.op = 'upd';
2025-07-02 06:41:24.292
2025-07-02 06:41:24.292
2025-07-02 06:41:24.293 --set width who 10;
2025-07-02 06:41:24.293 -- DO NOT check this! Values can differ here from one run to another!
2025-07-02 06:41:24.293 -- 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:41:24.293 rollback;
2025-07-02 06:41:24.293
2025-07-02 06:41:24.293 '''
2025-07-02 06:41:24.293
2025-07-02 06:41:24.293 fn_worker_sql.write_text(worker_sql)
2025-07-02 06:41:24.293
2025-07-02 06:41:24.293 with fn_worker_log.open(mode='w') as hang_out, fn_worker_err.open(mode='w') as hang_err:
2025-07-02 06:41:24.293
2025-07-02 06:41:24.293 ############################################################################
2025-07-02 06:41:24.293 ### 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:41:24.293 ############################################################################
2025-07-02 06:41:24.293 p_worker = subprocess.Popen([act.vars['isql'], '-i', str(fn_worker_sql),
2025-07-02 06:41:24.293 '-user', act.db.user,
2025-07-02 06:41:24.293 '-password', act.db.password,
2025-07-02 06:41:24.293 '-pag', '999999',
2025-07-02 06:41:24.293 act.db.dsn
2025-07-02 06:41:24.293 ],
2025-07-02 06:41:24.294 stdout = hang_out,
2025-07-02 06:41:24.294 stderr = hang_err
2025-07-02 06:41:24.294 )
2025-07-02 06:41:24.294
2025-07-02 06:41:24.294 # NB: when ISQL will establish attach, first record that it must lock is ID = 0 -- see above SQL_TO_BE_RESTARTED
2025-07-02 06:41:24.294 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:41:24.294 #
2025-07-02 06:41:24.294 #wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id = 0', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:41:24.294
2025-07-02 06:41:24.294 sttm = f'update {target_obj} set id = ? where abs( id ) = ?'
2025-07-02 06:41:24.294
2025-07-02 06:41:24.294 #########################
2025-07-02 06:41:24.294 ### L O C K E R - 2 ###
2025-07-02 06:41:24.294 #########################
2025-07-02 06:41:24.294 cur_lock_2.execute( sttm, ( -5, 5, ) )
2025-07-02 06:41:24.294 con_lock_2.commit()
2025-07-02 06:41:24.294 cur_lock_2.execute( sttm, ( -5, 5, ) )
2025-07-02 06:41:24.294
2025-07-02 06:41:24.295 #########################
2025-07-02 06:41:24.295 ### L O C K E R - 1 ###
2025-07-02 06:41:24.295 #########################
2025-07-02 06:41:24.295 con_lock_1.commit() # releases record with ID = 0 ==> now it can be locked by worker.
2025-07-02 06:41:24.295 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:41:24.295 #
2025-07-02 06:41:24.295 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=0', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:41:24.295
2025-07-02 06:41:24.295
2025-07-02 06:41:24.295 cur_lock_1.execute( sttm, ( -4, 4, ) )
2025-07-02 06:41:24.295 con_lock_1.commit()
2025-07-02 06:41:24.295 cur_lock_1.execute( sttm, ( -4, 4, ) )
2025-07-02 06:41:24.295
2025-07-02 06:41:24.295 #########################
2025-07-02 06:41:24.295 ### L O C K E R - 2 ###
2025-07-02 06:41:24.295 #########################
2025-07-02 06:41:24.295 con_lock_2.commit() # releases record with ID = -5 ==> now it can be locked by worker.
2025-07-02 06:41:24.295 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:41:24.295 #
2025-07-02 06:41:24.296 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:41:24.296
2025-07-02 06:41:24.296 cur_lock_2.execute( sttm, ( -3, 3, ) )
2025-07-02 06:41:24.296 con_lock_2.commit()
2025-07-02 06:41:24.296 cur_lock_2.execute( sttm, ( -3, 3, ) )
2025-07-02 06:41:24.296
2025-07-02 06:41:24.296 #########################
2025-07-02 06:41:24.296 ### L O C K E R - 1 ###
2025-07-02 06:41:24.296 #########################
2025-07-02 06:41:24.296 con_lock_1.commit()
2025-07-02 06:41:24.296 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:41:24.296 #
2025-07-02 06:41:24.296 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:41:24.296
2025-07-02 06:41:24.296 cur_lock_1.execute( sttm, ( -2, 2, ) )
2025-07-02 06:41:24.296 con_lock_1.commit()
2025-07-02 06:41:24.296 cur_lock_1.execute( sttm, ( -2, 2, ) )
2025-07-02 06:41:24.296
2025-07-02 06:41:24.297 #########################
2025-07-02 06:41:24.297 ### L O C K E R - 2 ###
2025-07-02 06:41:24.297 #########################
2025-07-02 06:41:24.297 con_lock_2.commit()
2025-07-02 06:41:24.297 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:41:24.297 #
2025-07-02 06:41:24.297 wait_for_record_become_locked(tx_monitoring, cur_monitoring, f'update {target_obj} set id=id where id=-3', SQL_TAG_THAT_WE_WAITING_FOR)
2025-07-02 06:41:24.297
2025-07-02 06:41:24.297
2025-07-02 06:41:24.297 cur_lock_2.execute( f'insert into {target_obj}(id,x) values(?, ?)', ( -1, 1, ) )
2025-07-02 06:41:24.297 con_lock_2.commit()
2025-07-02 06:41:24.297 cur_lock_2.execute( f'update {target_obj} set id = id where id = ?', ( -1, ) )
2025-07-02 06:41:24.297
2025-07-02 06:41:24.297 #########################
2025-07-02 06:41:24.297 ### L O C K E R - 1 ###
2025-07-02 06:41:24.297 #########################
2025-07-02 06:41:24.297 con_lock_1.commit()
2025-07-02 06:41:24.297 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:41:24.297 #
2025-07-02 06:41:24.298 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:41:24.298
2025-07-02 06:41:24.298 #########################
2025-07-02 06:41:24.298 ### L O C K E R - 2 ###
2025-07-02 06:41:24.298 #########################
2025-07-02 06:41:24.298 con_lock_2.commit() # At this point merge can complete its job but it must FAIL because of multiple matches for abs(t.id) = abs(s.id), i.e. when ID = -1 and 1
2025-07-02 06:41:24.298
2025-07-02 06:41:24.298 # Here we wait for ISQL complete its mission:
2025-07-02 06:41:24.298 p_worker.wait()
2025-07-02 06:41:24.298
2025-07-02 06:41:24.298 # < with act.db.connect
2025-07-02 06:41:24.298
2025-07-02 06:41:24.298 for g in (fn_worker_log, fn_worker_err):
2025-07-02 06:41:24.298 with g.open() as f:
2025-07-02 06:41:24.298 for line in f:
2025-07-02 06:41:24.298 if line.strip():
2025-07-02 06:41:24.298 print(f'checked_mode: {checked_mode}, {"STDLOG" if g == fn_worker_log else "STDERR"}: {line}')
2025-07-02 06:41:24.298
2025-07-02 06:41:24.298 expected_stdout_worker = f"""
2025-07-02 06:41:24.298 checked_mode: {checked_mode}, STDLOG: Records affected: 2
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: ID X
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: ======= =======
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: -5 5
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: -4 4
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: -3 3
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: -2 2
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: -1 1
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 0 0
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 1 1
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: Records affected: 7
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 0 UPD 1
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 1 UPD 1
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 0 UPD 2
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 1 UPD 2
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 0 UPD 3
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 1 UPD 3
2025-07-02 06:41:24.299 checked_mode: {checked_mode}, STDLOG: 0 UPD 4
2025-07-02 06:41:24.300 checked_mode: {checked_mode}, STDLOG: 1 UPD 4
2025-07-02 06:41:24.300 checked_mode: {checked_mode}, STDLOG: 0 UPD 5
2025-07-02 06:41:24.300 checked_mode: {checked_mode}, STDLOG: 1 UPD 5
2025-07-02 06:41:24.300 checked_mode: {checked_mode}, STDLOG: Records affected: 10
2025-07-02 06:41:24.300 checked_mode: {checked_mode}, STDERR: Statement failed, SQLSTATE = 21000
2025-07-02 06:41:24.300 checked_mode: {checked_mode}, STDERR: Multiple source records cannot match the same target during MERGE
2025-07-02 06:41:24.300 checked_mode: {checked_mode}, STDERR:
2025-07-02 06:41:24.300 """
2025-07-02 06:41:24.300
2025-07-02 06:41:24.300 act.expected_stdout = expected_stdout_worker
2025-07-02 06:41:24.300 act.stdout = capsys.readouterr().out
2025-07-02 06:41:24.300 > assert act.clean_stdout == act.clean_expected_stdout
2025-07-02 06:41:24.300 E assert
2025-07-02 06:41:24.300 E checked_mode: table, STDLOG: Records affected: 2
2025-07-02 06:41:24.300 E checked_mode: table, STDLOG: ID X
2025-07-02 06:41:24.300 E checked_mode: table, STDLOG:
2025-07-02 06:41:24.300 E checked_mode: table, STDLOG: -5 5
2025-07-02 06:41:24.300 E checked_mode: table, STDLOG: -4 4
2025-07-02 06:41:24.300 E checked_mode: table, STDLOG: -3 3
2025-07-02 06:41:24.300 E checked_mode: table, STDLOG: -2 2
2025-07-02 06:41:24.301 E checked_mode: table, STDLOG: -1 1
2025-07-02 06:41:24.301 E checked_mode: table, STDLOG: 0 0
2025-07-02 06:41:24.301 E checked_mode: table, STDLOG: 1 1
2025-07-02 06:41:24.301 E checked_mode: table, STDLOG: Records affected: 7
2025-07-02 06:41:24.301 E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:41:24.301 E checked_mode: table, STDLOG:
2025-07-02 06:41:24.301 E - checked_mode: table, STDLOG: 0 UPD 1
2025-07-02 06:41:24.301 E + checked_mode: table, STDLOG: 0UPD 1
2025-07-02 06:41:24.301 E - checked_mode: table, STDLOG: 1 UPD 1
2025-07-02 06:41:24.301 E + checked_mode: table, STDLOG: 1UPD 1
2025-07-02 06:41:24.301 E - checked_mode: table, STDLOG: 0 UPD 2
2025-07-02 06:41:24.301 E + checked_mode: table, STDLOG: 0UPD 2
2025-07-02 06:41:24.301 E - checked_mode: table, STDLOG: 1 UPD 2
2025-07-02 06:41:24.301 E + checked_mode: table, STDLOG: 1UPD 2
2025-07-02 06:41:24.301 E - checked_mode: table, STDLOG: 0 UPD 3
2025-07-02 06:41:24.302 E + checked_mode: table, STDLOG: 0UPD 3
2025-07-02 06:41:24.302 E - checked_mode: table, STDLOG: 1 UPD 3
2025-07-02 06:41:24.302 E + checked_mode: table, STDLOG: 1UPD 3
2025-07-02 06:41:24.302 E - checked_mode: table, STDLOG: 0 UPD 4
2025-07-02 06:41:24.302 E + checked_mode: table, STDLOG: 0UPD 4
2025-07-02 06:41:24.302 E - checked_mode: table, STDLOG: 1 UPD 4
2025-07-02 06:41:24.302 E + checked_mode: table, STDLOG: 1UPD 4
2025-07-02 06:41:24.302 E - checked_mode: table, STDLOG: 0 UPD 5
2025-07-02 06:41:24.302 E + checked_mode: table, STDLOG: 0UPD 5
2025-07-02 06:41:24.302 E - checked_mode: table, STDLOG: 1 UPD 5
2025-07-02 06:41:24.302 E + checked_mode: table, STDLOG: 1UPD 5
2025-07-02 06:41:24.302 E checked_mode: table, STDLOG: Records affected: 10
2025-07-02 06:41:24.302 E checked_mode: table, STDERR: Statement failed, SQLSTATE 21000
2025-07-02 06:41:24.302 E checked_mode: table, STDERR: Multiple source records cannot match the same target during MERGE
2025-07-02 06:41:24.302 E checked_mode: table, STDERR:
2025-07-02 06:41:24.303
2025-07-02 06:41:24.303 tests\functional\transactions\test_read_consist_sttm_merge_deny_multiple_matches.py:421: AssertionError
2025-07-02 06:41:24.303 ---------------------------- Captured stdout setup ----------------------------
2025-07-02 06:41:24.303 Creating db: localhost:H:\QA\temp\qa2024.tmp\fbqa\test_12497\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 = WindowsPath('H:/QA/temp/qa2024.tmp/fbqa/test_12497/tmp_worker.sql')
fn_worker_log = WindowsPath('H:/QA/temp/qa2024.tmp/fbqa/test_12497/tmp_worker.log')
fn_worker_err = WindowsPath('H:/QA/temp/qa2024.tmp/fbqa/test_12497/tmp_worker.err')
capsys = <_pytest.capture.CaptureFixture pytest object at [hex]>
@pytest.mark.trace
@pytest.mark.version('>=4.0.2')
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 s.id, s.x from {target_obj} as s
where s.id <= 1
order by s.id DESC -- added only 05-jun-2024; thanks to Vlad.
) s
on abs(t.id) = abs(s.id)
when matched then
update set t.x = s.id * 100
"""
sql_addi = f'''
set term ^;
execute block as
begin
rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
end
^
set term ;^
-- INITIAL DATA: add rows with ID = 0...6
-- #############
insert into {target_obj}(id, x)
select row_number()over()-1, row_number()over()-1
from rdb$types rows 6;
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()
cur_lock_1 = con_lock_1.cursor()
cur_lock_2 = con_lock_2.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 = 0' )
worker_sql = f'''
set list on;
set autoddl off;
set term ^;
execute block as
begin
rdb$set_context('USER_SESSION','WHO', 'WORKER');
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:
{SQL_TO_BE_RESTARTED};
-- check results:
-- ###############
select id,x from {target_obj} order by id;
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 = 0 -- 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 = 0', SQL_TAG_THAT_WE_WAITING_FOR)
sttm = f'update {target_obj} set id = ? where abs( id ) = ?'
#########################
### L O C K E R - 2 ###
#########################
cur_lock_2.execute( sttm, ( -5, 5, ) )
con_lock_2.commit()
cur_lock_2.execute( sttm, ( -5, 5, ) )
#########################
### L O C K E R - 1 ###
#########################
con_lock_1.commit() # releases record with ID = 0 ==> now it can be locked by worker.
# 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=0', SQL_TAG_THAT_WE_WAITING_FOR)
cur_lock_1.execute( sttm, ( -4, 4, ) )
con_lock_1.commit()
cur_lock_1.execute( sttm, ( -4, 4, ) )
#########################
### L O C K E R - 2 ###
#########################
con_lock_2.commit() # releases record with ID = -5 ==> now it can be locked by worker.
# 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)
cur_lock_2.execute( sttm, ( -3, 3, ) )
con_lock_2.commit()
cur_lock_2.execute( sttm, ( -3, 3, ) )
#########################
### L O C K E R - 1 ###
#########################
con_lock_1.commit()
# 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=-4', SQL_TAG_THAT_WE_WAITING_FOR)
cur_lock_1.execute( sttm, ( -2, 2, ) )
con_lock_1.commit()
cur_lock_1.execute( sttm, ( -2, 2, ) )
#########################
### L O C K E R - 2 ###
#########################
con_lock_2.commit()
# 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=-3', SQL_TAG_THAT_WE_WAITING_FOR)
cur_lock_2.execute( f'insert into {target_obj}(id,x) values(?, ?)', ( -1, 1, ) )
con_lock_2.commit()
cur_lock_2.execute( f'update {target_obj} set id = id where id = ?', ( -1, ) )
#########################
### L O C K E R - 1 ###
#########################
con_lock_1.commit()
# 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 ###
#########################
con_lock_2.commit() # At this point merge can complete its job but it must FAIL because of multiple matches for abs(t.id) = abs(s.id), i.e. when ID = -1 and 1
# 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.strip():
print(f'checked_mode: {checked_mode}, {"STDLOG" if g == fn_worker_log else "STDERR"}: {line}')
expected_stdout_worker = f"""
checked_mode: {checked_mode}, STDLOG: Records affected: 2
checked_mode: {checked_mode}, STDLOG: ID X
checked_mode: {checked_mode}, STDLOG: ======= =======
checked_mode: {checked_mode}, STDLOG: -5 5
checked_mode: {checked_mode}, STDLOG: -4 4
checked_mode: {checked_mode}, STDLOG: -3 3
checked_mode: {checked_mode}, STDLOG: -2 2
checked_mode: {checked_mode}, STDLOG: -1 1
checked_mode: {checked_mode}, STDLOG: 0 0
checked_mode: {checked_mode}, STDLOG: 1 1
checked_mode: {checked_mode}, STDLOG: Records affected: 7
checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
checked_mode: {checked_mode}, STDLOG: 0 UPD 1
checked_mode: {checked_mode}, STDLOG: 1 UPD 1
checked_mode: {checked_mode}, STDLOG: 0 UPD 2
checked_mode: {checked_mode}, STDLOG: 1 UPD 2
checked_mode: {checked_mode}, STDLOG: 0 UPD 3
checked_mode: {checked_mode}, STDLOG: 1 UPD 3
checked_mode: {checked_mode}, STDLOG: 0 UPD 4
checked_mode: {checked_mode}, STDLOG: 1 UPD 4
checked_mode: {checked_mode}, STDLOG: 0 UPD 5
checked_mode: {checked_mode}, STDLOG: 1 UPD 5
checked_mode: {checked_mode}, STDLOG: Records affected: 10
checked_mode: {checked_mode}, STDERR: Statement failed, SQLSTATE = 21000
checked_mode: {checked_mode}, STDERR: Multiple source records cannot match the same target during MERGE
checked_mode: {checked_mode}, STDERR:
"""
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: 2
E checked_mode: table, STDLOG: ID X
E checked_mode: table, STDLOG:
E checked_mode: table, STDLOG: -5 5
E checked_mode: table, STDLOG: -4 4
E checked_mode: table, STDLOG: -3 3
E checked_mode: table, STDLOG: -2 2
E checked_mode: table, STDLOG: -1 1
E checked_mode: table, STDLOG: 0 0
E checked_mode: table, STDLOG: 1 1
E checked_mode: table, STDLOG: Records affected: 7
E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
E checked_mode: table, STDLOG:
E - checked_mode: table, STDLOG: 0 UPD 1
E + checked_mode: table, STDLOG: 0UPD 1
E - checked_mode: table, STDLOG: 1 UPD 1
E + checked_mode: table, STDLOG: 1UPD 1
E - checked_mode: table, STDLOG: 0 UPD 2
E + checked_mode: table, STDLOG: 0UPD 2
E - checked_mode: table, STDLOG: 1 UPD 2
E + checked_mode: table, STDLOG: 1UPD 2
E - checked_mode: table, STDLOG: 0 UPD 3
E + checked_mode: table, STDLOG: 0UPD 3
E - checked_mode: table, STDLOG: 1 UPD 3
E + checked_mode: table, STDLOG: 1UPD 3
E - checked_mode: table, STDLOG: 0 UPD 4
E + checked_mode: table, STDLOG: 0UPD 4
E - checked_mode: table, STDLOG: 1 UPD 4
E + checked_mode: table, STDLOG: 1UPD 4
E - checked_mode: table, STDLOG: 0 UPD 5
E + checked_mode: table, STDLOG: 0UPD 5
E - checked_mode: table, STDLOG: 1 UPD 5
E + checked_mode: table, STDLOG: 1UPD 5
E checked_mode: table, STDLOG: Records affected: 10
E checked_mode: table, STDERR: Statement failed, SQLSTATE 21000
E checked_mode: table, STDERR: Multiple source records cannot match the same target during MERGE
E checked_mode: table, STDERR:
tests\functional\transactions\test_read_consist_sttm_merge_deny_multiple_matches.py:421: AssertionError
|