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-01 06:05:04.576
2025-07-01 06:05:04.586 act = <firebird.qa.plugin.Action object at [hex]>
2025-07-01 06:05:04.598 fn_worker_sql = PosixPath('/var/tmp/qa_2024/test_12483/tmp_worker.sql')
2025-07-01 06:05:04.615 fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12483/tmp_worker.log')
2025-07-01 06:05:04.623 fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12483/tmp_worker.err')
2025-07-01 06:05:04.631 capsys = <_pytest.capture.CaptureFixture object at [hex]>
2025-07-01 06:05:04.639
2025-07-01 06:05:04.648 @pytest.mark.trace
2025-07-01 06:05:04.660 @pytest.mark.version('>=4.0')
2025-07-01 06:05:04.670 def test_1(act: Action, fn_worker_sql: Path, fn_worker_log: Path, fn_worker_err: Path, capsys):
2025-07-01 06:05:04.679 sql_init = (act.files_dir / 'read-consist-sttm-restart-DDL.sql').read_text()
2025-07-01 06:05:04.687
2025-07-01 06:05:04.696 for checked_mode in('table', 'view'):
2025-07-01 06:05:04.709 target_obj = 'test' if checked_mode == 'table' else 'v_test'
2025-07-01 06:05:04.722
2025-07-01 06:05:04.737 SQL_TO_BE_RESTARTED = f"""
2025-07-01 06:05:04.747 merge /* {SQL_TAG_THAT_WE_WAITING_FOR} */ into {target_obj} t
2025-07-01 06:05:04.758 using (select * from {target_obj} where id <=2 order by id DESC rows 4) s on s.id=t.id
2025-07-01 06:05:04.766 when matched then
2025-07-01 06:05:04.773 update set t.id = -t.id
2025-07-01 06:05:04.780 when not matched then
2025-07-01 06:05:04.788 insert(id,x) values(1000 + s.id, 1000 + s.x)
2025-07-01 06:05:04.795 """
2025-07-01 06:05:04.802
2025-07-01 06:05:04.813 sql_addi = f'''
2025-07-01 06:05:04.822 set term ^;
2025-07-01 06:05:04.830 execute block as
2025-07-01 06:05:04.838 begin
2025-07-01 06:05:04.847 rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
2025-07-01 06:05:04.856 end
2025-07-01 06:05:04.863 ^
2025-07-01 06:05:04.870 set term ;^
2025-07-01 06:05:04.881 insert into {target_obj}(id, x)
2025-07-01 06:05:04.892 select row_number()over(),row_number()over()
2025-07-01 06:05:04.903 from rdb$types rows 5;
2025-07-01 06:05:04.914 commit;
2025-07-01 06:05:04.928 '''
2025-07-01 06:05:04.939
2025-07-01 06:05:04.949 act.isql(switches=['-q'], input = ''.join( (sql_init, sql_addi) ) )
2025-07-01 06:05:04.962 # ::: NOTE ::: We have to immediately quit if any error raised in prepare phase.
2025-07-01 06:05:04.973 # See also letter from dimitr, 01-feb-2022 14:46
2025-07-01 06:05:04.981 assert act.stderr == ''
2025-07-01 06:05:04.988 act.reset()
2025-07-01 06:05:04.995
2025-07-01 06:05:05.005 trace_cfg_items = [
2025-07-01 06:05:05.021 'time_threshold = 0',
2025-07-01 06:05:05.031 'log_errors = true',
2025-07-01 06:05:05.039 'log_statement_start = true',
2025-07-01 06:05:05.048 'log_statement_finish = true',
2025-07-01 06:05:05.057 ]
2025-07-01 06:05:05.064
2025-07-01 06:05:05.072 with act.trace(db_events = trace_cfg_items, encoding=locale.getpreferredencoding()):
2025-07-01 06:05:05.078
2025-07-01 06:05:05.088 with act.db.connect() as con_lock_1, act.db.connect() as con_lock_2, act.db.connect() as con_monitoring:
2025-07-01 06:05:05.094
2025-07-01 06:05:05.109 tpb_monitoring = tpb(isolation=Isolation.READ_COMMITTED_RECORD_VERSION, lock_timeout=0)
2025-07-01 06:05:05.122 tx_monitoring = con_monitoring.transaction_manager(tpb_monitoring)
2025-07-01 06:05:05.135 cur_monitoring = tx_monitoring.cursor()
2025-07-01 06:05:05.146
2025-07-01 06:05:05.161 for i,c in enumerate((con_lock_1,con_lock_2)):
2025-07-01 06:05:05.173 sttm = f"execute block as begin rdb$set_context('USER_SESSION', 'WHO', 'LOCKER #{i+1}'); end"
2025-07-01 06:05:05.180 c.execute_immediate(sttm)
2025-07-01 06:05:05.187
2025-07-01 06:05:05.193 #########################
2025-07-01 06:05:05.198 ### L O C K E R - 1 ###
2025-07-01 06:05:05.203 #########################
2025-07-01 06:05:05.210
2025-07-01 06:05:05.218 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id=1' )
2025-07-01 06:05:05.224
2025-07-01 06:05:05.232 worker_sql = f'''
2025-07-01 06:05:05.238 set list on;
2025-07-01 06:05:05.245 set autoddl off;
2025-07-01 06:05:05.256 set term ^;
2025-07-01 06:05:05.264 execute block returns (whoami varchar(30)) as
2025-07-01 06:05:05.272 begin
2025-07-01 06:05:05.279 whoami = 'WORKER'; -- , ATT#' || current_connection;
2025-07-01 06:05:05.288 rdb$set_context('USER_SESSION','WHO', whoami);
2025-07-01 06:05:05.301 -- suspend;
2025-07-01 06:05:05.312 end
2025-07-01 06:05:05.320 ^
2025-07-01 06:05:05.328 set term ;^
2025-07-01 06:05:05.335 commit;
2025-07-01 06:05:05.350 SET KEEP_TRAN_PARAMS ON;
2025-07-01 06:05:05.359 set transaction read committed read consistency;
2025-07-01 06:05:05.366 set list off;
2025-07-01 06:05:05.374 set wng off;
2025-07-01 06:05:05.383 set count on;
2025-07-01 06:05:05.391
2025-07-01 06:05:05.398 -- this must hang because of locker-1:
2025-07-01 06:05:05.404 {SQL_TO_BE_RESTARTED};
2025-07-01 06:05:05.412
2025-07-01 06:05:05.423 -- check results:
2025-07-01 06:05:05.431 -- ###############
2025-07-01 06:05:05.438 select id from {target_obj} order by id; -- one record must remain, with ID = -5
2025-07-01 06:05:05.445
2025-07-01 06:05:05.452 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-01 06:05:05.457 from v_worker_log v
2025-07-01 06:05:05.463 where v.op = 'upd';
2025-07-01 06:05:05.467
2025-07-01 06:05:05.472 --set width who 10;
2025-07-01 06:05:05.477 -- DO NOT check this! Values can differ here from one run to another!
2025-07-01 06:05:05.482 -- select id, trn, who, old_id, new_id, op, rec_vers, global_cn, snap_no from tlog_done order by id;
2025-07-01 06:05:05.490 rollback;
2025-07-01 06:05:05.498
2025-07-01 06:05:05.506 '''
2025-07-01 06:05:05.511
2025-07-01 06:05:05.517 fn_worker_sql.write_text(worker_sql)
2025-07-01 06:05:05.527
2025-07-01 06:05:05.535 with fn_worker_log.open(mode='w') as hang_out, fn_worker_err.open(mode='w') as hang_err:
2025-07-01 06:05:05.548
2025-07-01 06:05:05.558 ############################################################################
2025-07-01 06:05:05.566 ### 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-01 06:05:05.573 ############################################################################
2025-07-01 06:05:05.585 p_worker = subprocess.Popen([act.vars['isql'], '-i', str(fn_worker_sql),
2025-07-01 06:05:05.594 '-user', act.db.user,
2025-07-01 06:05:05.605 '-password', act.db.password,
2025-07-01 06:05:05.614 '-pag', '999999',
2025-07-01 06:05:05.626 act.db.dsn
2025-07-01 06:05:05.638 ],
2025-07-01 06:05:05.647 stdout = hang_out,
2025-07-01 06:05:05.654 stderr = hang_err
2025-07-01 06:05:05.660 )
2025-07-01 06:05:05.666 # NB: when ISQL will establish attach, first record that it must lock is ID = 2 -- see above SQL_TO_BE_RESTARTED
2025-07-01 06:05:05.673 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-01 06:05:05.685 #
2025-07-01 06:05:05.694 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-01 06:05:05.700
2025-07-01 06:05:05.707
2025-07-01 06:05:05.715 #########################
2025-07-01 06:05:05.726 ### L O C K E R - 2 ###
2025-07-01 06:05:05.736 #########################
2025-07-01 06:05:05.744
2025-07-01 06:05:05.752 # Change ID so that it **will* be included in the set of rows that must be affected by session-worker:
2025-07-01 06:05:05.759 con_lock_2.execute_immediate( f'update {target_obj} set id = -5 where abs(id) = 5;' )
2025-07-01 06:05:05.764 con_lock_2.commit()
2025-07-01 06:05:05.771 con_lock_2.execute_immediate( f'update {target_obj} set id = id where abs(id) = 5;' )
2025-07-01 06:05:05.779 con_lock_1.commit() # releases record with ID=1 ==> now it can be locked by worker.
2025-07-01 06:05:05.791
2025-07-01 06:05:05.806 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 1.
2025-07-01 06:05:05.817 #
2025-07-01 06:05:05.827 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-01 06:05:05.837
2025-07-01 06:05:05.848 # If we come here then it means that record with ID = 1 for sure is locked by WORKER.
2025-07-01 06:05:05.858
2025-07-01 06:05:05.871 # Change ID so that it **will* be included in the set of rows that must be affected by session-worker:
2025-07-01 06:05:05.884 con_lock_1.execute_immediate( f'update {target_obj} set id = -4 where abs(id) = 4;' )
2025-07-01 06:05:05.896 con_lock_1.commit()
2025-07-01 06:05:05.907 con_lock_1.execute_immediate( f'update {target_obj} set id = id where abs(id) = 4;' )
2025-07-01 06:05:05.915
2025-07-01 06:05:05.927 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-01 06:05:05.938
2025-07-01 06:05:05.946 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -5:
2025-07-01 06:05:05.956 #
2025-07-01 06:05:05.966 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-01 06:05:05.974
2025-07-01 06:05:05.983 # If we come here then it means that record with ID = -5 for sure is locked by WORKER.
2025-07-01 06:05:05.994
2025-07-01 06:05:06.005 con_lock_2.execute_immediate( f'update {target_obj} set id = -3 where abs(id) = 3;' )
2025-07-01 06:05:06.017 con_lock_2.commit()
2025-07-01 06:05:06.027 con_lock_2.execute_immediate( f'update {target_obj} set id = id where abs(id) = 3;' )
2025-07-01 06:05:06.038
2025-07-01 06:05:06.050 con_lock_1.commit() # This releases row with ID=-4 but session-worker is waiting for ID = - 3 (changed by locker-2).
2025-07-01 06:05:06.060
2025-07-01 06:05:06.068
2025-07-01 06:05:06.076 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -4:
2025-07-01 06:05:06.083 #
2025-07-01 06:05:06.091 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-01 06:05:06.096
2025-07-01 06:05:06.105 # If we come here then it means that record with ID = -4 for sure is locked by WORKER.
2025-07-01 06:05:06.116
2025-07-01 06:05:06.124 con_lock_2.commit() # This releases row with ID=-3. No more locked rows so session-worker can finish its mission.
2025-07-01 06:05:06.129
2025-07-01 06:05:06.135 # Here we wait for ISQL complete its mission:
2025-07-01 06:05:06.140 p_worker.wait()
2025-07-01 06:05:06.153 # < with act.db.connect
2025-07-01 06:05:06.162
2025-07-01 06:05:06.170 for g in (fn_worker_log, fn_worker_err):
2025-07-01 06:05:06.179 with g.open() as f:
2025-07-01 06:05:06.187 for line in f:
2025-07-01 06:05:06.194 if line.split():
2025-07-01 06:05:06.198 if g == fn_worker_log:
2025-07-01 06:05:06.203 print(f'checked_mode: {checked_mode}, STDLOG: {line}')
2025-07-01 06:05:06.207 else:
2025-07-01 06:05:06.214 print(f'UNEXPECTED STDERR {line}')
2025-07-01 06:05:06.219
2025-07-01 06:05:06.226 expected_stdout_worker = f"""
2025-07-01 06:05:06.237 checked_mode: {checked_mode}, STDLOG: Records affected: 4
2025-07-01 06:05:06.246
2025-07-01 06:05:06.254 checked_mode: {checked_mode}, STDLOG: ID
2025-07-01 06:05:06.264 checked_mode: {checked_mode}, STDLOG: =======
2025-07-01 06:05:06.275 checked_mode: {checked_mode}, STDLOG: -5
2025-07-01 06:05:06.286 checked_mode: {checked_mode}, STDLOG: -2
2025-07-01 06:05:06.295 checked_mode: {checked_mode}, STDLOG: -1
2025-07-01 06:05:06.301 checked_mode: {checked_mode}, STDLOG: 3
2025-07-01 06:05:06.316 checked_mode: {checked_mode}, STDLOG: 4
2025-07-01 06:05:06.329 checked_mode: {checked_mode}, STDLOG: Records affected: 5
2025-07-01 06:05:06.342
2025-07-01 06:05:06.349 checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-01 06:05:06.358 checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
2025-07-01 06:05:06.366 checked_mode: {checked_mode}, STDLOG: 2 UPD 1
2025-07-01 06:05:06.371 checked_mode: {checked_mode}, STDLOG: 2 UPD 2
2025-07-01 06:05:06.378 checked_mode: {checked_mode}, STDLOG: 1 UPD 2
2025-07-01 06:05:06.384 checked_mode: {checked_mode}, STDLOG: 2 UPD 3
2025-07-01 06:05:06.390 checked_mode: {checked_mode}, STDLOG: 1 UPD 3
2025-07-01 06:05:06.397 checked_mode: {checked_mode}, STDLOG: 2 UPD 4
2025-07-01 06:05:06.403 checked_mode: {checked_mode}, STDLOG: 1 UPD 4
2025-07-01 06:05:06.409 checked_mode: {checked_mode}, STDLOG: -3 UPD 4
2025-07-01 06:05:06.416 checked_mode: {checked_mode}, STDLOG: -4 UPD 4
2025-07-01 06:05:06.422 checked_mode: {checked_mode}, STDLOG: Records affected: 9
2025-07-01 06:05:06.427 """
2025-07-01 06:05:06.433
2025-07-01 06:05:06.438 act.expected_stdout = expected_stdout_worker
2025-07-01 06:05:06.444 act.stdout = capsys.readouterr().out
2025-07-01 06:05:06.450 > assert act.clean_stdout == act.clean_expected_stdout
2025-07-01 06:05:06.460 E assert
2025-07-01 06:05:06.470 E checked_mode: table, STDLOG: Records affected: 4
2025-07-01 06:05:06.480 E checked_mode: table, STDLOG: ID
2025-07-01 06:05:06.488 E checked_mode: table, STDLOG:
2025-07-01 06:05:06.495 E checked_mode: table, STDLOG: -5
2025-07-01 06:05:06.502 E checked_mode: table, STDLOG: -2
2025-07-01 06:05:06.513 E checked_mode: table, STDLOG: -1
2025-07-01 06:05:06.523 E checked_mode: table, STDLOG: 3
2025-07-01 06:05:06.531 E checked_mode: table, STDLOG: 4
2025-07-01 06:05:06.538 E checked_mode: table, STDLOG: Records affected: 5
2025-07-01 06:05:06.549 E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-01 06:05:06.557 E checked_mode: table, STDLOG:
2025-07-01 06:05:06.568 E - checked_mode: table, STDLOG: 2 UPD 1
2025-07-01 06:05:06.589 E + checked_mode: table, STDLOG: 2UPD 1
2025-07-01 06:05:06.600 E - checked_mode: table, STDLOG: 2 UPD 2
2025-07-01 06:05:06.624 E + checked_mode: table, STDLOG: 2UPD 2
2025-07-01 06:05:06.632 E - checked_mode: table, STDLOG: 1 UPD 2
2025-07-01 06:05:06.656 E + checked_mode: table, STDLOG: 1UPD 2
2025-07-01 06:05:06.668 E - checked_mode: table, STDLOG: 2 UPD 3
2025-07-01 06:05:06.691 E + checked_mode: table, STDLOG: 2UPD 3
2025-07-01 06:05:06.700 E - checked_mode: table, STDLOG: 1 UPD 3
2025-07-01 06:05:06.723 E + checked_mode: table, STDLOG: 1UPD 3
2025-07-01 06:05:06.733 E - checked_mode: table, STDLOG: 2 UPD 4
2025-07-01 06:05:06.751 E + checked_mode: table, STDLOG: 2UPD 4
2025-07-01 06:05:06.757 E - checked_mode: table, STDLOG: 1 UPD 4
2025-07-01 06:05:06.769 E + checked_mode: table, STDLOG: 1UPD 4
2025-07-01 06:05:06.775 E - checked_mode: table, STDLOG: -3 UPD 4
2025-07-01 06:05:06.791 E + checked_mode: table, STDLOG: -3UPD 4
2025-07-01 06:05:06.799 E - checked_mode: table, STDLOG: -4 UPD 4
2025-07-01 06:05:06.812 E + checked_mode: table, STDLOG: -4UPD 4
2025-07-01 06:05:06.819 E checked_mode: table, STDLOG: Records affected: 9
2025-07-01 06:05:06.828
2025-07-01 06:05:06.837 tests/functional/transactions/test_read_consist_sttm_restart_on_merge_04.py:447: AssertionError
2025-07-01 06:05:06.849 ---------------------------- Captured stdout setup -----------------------------
2025-07-01 06:05:06.857 Creating db: localhost:/var/tmp/qa_2024/test_12483/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_12483/tmp_worker.sql')
fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12483/tmp_worker.log')
fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12483/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
|