2 @message |
assert
checked_mode: table, STDLOG: Records affected: 8
checked_mode: table, STDLOG: ID
checked_mode: table, STDLOG:
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: 11
checked_mode: table, STDLOG: 12
checked_mode: table, STDLOG: 13
checked_mode: table, STDLOG: Records affected: 8
checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: table, STDLOG:
- checked_mode: table, STDLOG: 1 UPD 1
+ checked_mode: table, STDLOG: 1UPD 1
- checked_mode: table, STDLOG: 2 UPD 1
+ checked_mode: table, STDLOG: 2UPD 1
- checked_mode: table, STDLOG: 3 UPD 1
+ checked_mode: table, STDLOG: 3UPD 1
- checked_mode: table, STDLOG: 4 UPD 1
+ checked_mode: table, STDLOG: 4UPD 1
- 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: 1 UPD 2
+ checked_mode: table, STDLOG: 1UPD 2
- checked_mode: table, STDLOG: 2 UPD 2
+ checked_mode: table, STDLOG: 2UPD 2
- checked_mode: table, STDLOG: 3 UPD 2
+ checked_mode: table, STDLOG: 3UPD 2
- checked_mode: table, STDLOG: 4 UPD 2
+ checked_mode: table, STDLOG: 4UPD 2
- checked_mode: table, STDLOG: 5 UPD 2
+ checked_mode: table, STDLOG: 5UPD 2
checked_mode: table, STDLOG: Records affected: 12
LOG DETAILS:
2025-07-02 06:07:53.318
2025-07-02 06:07:53.324 act = <firebird.qa.plugin.Action object at [hex]>
2025-07-02 06:07:53.331 fn_worker_sql = PosixPath('/var/tmp/qa_2024/test_12485/tmp_worker.sql')
2025-07-02 06:07:53.339 fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12485/tmp_worker.log')
2025-07-02 06:07:53.350 fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12485/tmp_worker.err')
2025-07-02 06:07:53.364 capsys = <_pytest.capture.CaptureFixture object at [hex]>
2025-07-02 06:07:53.378
2025-07-02 06:07:53.390 @pytest.mark.trace
2025-07-02 06:07:53.402 @pytest.mark.version('>=4.0.2')
2025-07-02 06:07:53.413 def test_1(act: Action, fn_worker_sql: Path, fn_worker_log: Path, fn_worker_err: Path, capsys):
2025-07-02 06:07:53.422 sql_init = (act.files_dir / 'read-consist-sttm-restart-DDL.sql').read_text()
2025-07-02 06:07:53.434
2025-07-02 06:07:53.447 for checked_mode in('table', 'view'):
2025-07-02 06:07:53.459 target_obj = 'test' if checked_mode == 'table' else 'v_test'
2025-07-02 06:07:53.467
2025-07-02 06:07:53.477 SQL_TO_BE_RESTARTED = f"update /* {SQL_TAG_THAT_WE_WAITING_FOR} */ {target_obj} set id = -id order by id"
2025-07-02 06:07:53.484
2025-07-02 06:07:53.491 # add rows with ID = 1, 2, ..., 5:
2025-07-02 06:07:53.500 sql_addi = f'''
2025-07-02 06:07:53.512 set term ^;
2025-07-02 06:07:53.521 execute block as
2025-07-02 06:07:53.528 begin
2025-07-02 06:07:53.535 rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
2025-07-02 06:07:53.547 end
2025-07-02 06:07:53.555 ^
2025-07-02 06:07:53.563 set term ;^
2025-07-02 06:07:53.570 insert into {target_obj}(id, x)
2025-07-02 06:07:53.579 select row_number()over(),row_number()over()
2025-07-02 06:07:53.591 from rdb$types rows 5;
2025-07-02 06:07:53.597 commit;
2025-07-02 06:07:53.602 '''
2025-07-02 06:07:53.608
2025-07-02 06:07:53.614 act.isql(switches=['-q'], input = ''.join( (sql_init, sql_addi) ) )
2025-07-02 06:07:53.621 # ::: NOTE ::: We have to immediately quit if any error raised in prepare phase.
2025-07-02 06:07:53.628 # See also letter from dimitr, 01-feb-2022 14:46
2025-07-02 06:07:53.634 assert act.stderr == ''
2025-07-02 06:07:53.640 act.reset()
2025-07-02 06:07:53.646
2025-07-02 06:07:53.652 trace_cfg_items = [
2025-07-02 06:07:53.662 'time_threshold = 0',
2025-07-02 06:07:53.669 'log_errors = true',
2025-07-02 06:07:53.675 'log_statement_start = true',
2025-07-02 06:07:53.680 'log_statement_finish = true',
2025-07-02 06:07:53.686 ]
2025-07-02 06:07:53.691
2025-07-02 06:07:53.697 with act.trace(db_events = trace_cfg_items, encoding=locale.getpreferredencoding()):
2025-07-02 06:07:53.708
2025-07-02 06:07:53.721 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:53.729
2025-07-02 06:07:53.742 tpb_monitoring = tpb(isolation=Isolation.READ_COMMITTED_RECORD_VERSION, lock_timeout=0)
2025-07-02 06:07:53.753 tx_monitoring = con_monitoring.transaction_manager(tpb_monitoring)
2025-07-02 06:07:53.762 cur_monitoring = tx_monitoring.cursor()
2025-07-02 06:07:53.773
2025-07-02 06:07:53.782 for i,c in enumerate((con_lock_1,con_lock_2)):
2025-07-02 06:07:53.791 sttm = f"execute block as begin rdb$set_context('USER_SESSION', 'WHO', 'LOCKER #{i+1}'); end"
2025-07-02 06:07:53.804 c.execute_immediate(sttm)
2025-07-02 06:07:53.813
2025-07-02 06:07:53.821 #########################
2025-07-02 06:07:53.833 ### L O C K E R - 1 ###
2025-07-02 06:07:53.845 #########################
2025-07-02 06:07:53.856
2025-07-02 06:07:53.870 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id = 5' )
2025-07-02 06:07:53.883
2025-07-02 06:07:53.897 worker_sql = f'''
2025-07-02 06:07:53.909 set list on;
2025-07-02 06:07:53.918 set autoddl off;
2025-07-02 06:07:53.929 set term ^;
2025-07-02 06:07:53.939 execute block returns (whoami varchar(30)) as
2025-07-02 06:07:53.949 begin
2025-07-02 06:07:53.960 whoami = 'WORKER'; -- , ATT#' || current_connection;
2025-07-02 06:07:53.968 rdb$set_context('USER_SESSION','WHO', whoami);
2025-07-02 06:07:53.976 -- suspend;
2025-07-02 06:07:53.983 end
2025-07-02 06:07:53.994 ^
2025-07-02 06:07:54.002 set term ;^
2025-07-02 06:07:54.009 commit;
2025-07-02 06:07:54.015
2025-07-02 06:07:54.020 SET KEEP_TRAN_PARAMS ON;
2025-07-02 06:07:54.031 set transaction read committed read consistency;
2025-07-02 06:07:54.041 set list off;
2025-07-02 06:07:54.050 set wng off;
2025-07-02 06:07:54.058 set count on;
2025-07-02 06:07:54.067
2025-07-02 06:07:54.076 -- THIS MUST BE LOCKED:
2025-07-02 06:07:54.083 {SQL_TO_BE_RESTARTED};
2025-07-02 06:07:54.090
2025-07-02 06:07:54.096 -- check results:
2025-07-02 06:07:54.101 -- ###############
2025-07-02 06:07:54.112 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:54.123
2025-07-02 06:07:54.131 select v.old_id, v.op, v.snap_no_rank
2025-07-02 06:07:54.139 from v_worker_log v
2025-07-02 06:07:54.145 where v.op = 'upd';
2025-07-02 06:07:54.151
2025-07-02 06:07:54.157 set width who 10;
2025-07-02 06:07:54.163 -- DO NOT check this! Values can differ here from one run to another!
2025-07-02 06:07:54.169 -- 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:54.175
2025-07-02 06:07:54.188 rollback;
2025-07-02 06:07:54.198
2025-07-02 06:07:54.208 '''
2025-07-02 06:07:54.214
2025-07-02 06:07:54.223 fn_worker_sql.write_text(worker_sql)
2025-07-02 06:07:54.233
2025-07-02 06:07:54.243 with fn_worker_log.open(mode='w') as hang_out, fn_worker_err.open(mode='w') as hang_err:
2025-07-02 06:07:54.253
2025-07-02 06:07:54.261 ############################################################################
2025-07-02 06:07:54.268 ### 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:54.275 ############################################################################
2025-07-02 06:07:54.283 p_worker = subprocess.Popen([act.vars['isql'], '-i', str(fn_worker_sql),
2025-07-02 06:07:54.294 '-user', act.db.user,
2025-07-02 06:07:54.305 '-password', act.db.password,
2025-07-02 06:07:54.313 '-pag', '999999',
2025-07-02 06:07:54.320 act.db.dsn
2025-07-02 06:07:54.327 ],
2025-07-02 06:07:54.333 stdout = hang_out,
2025-07-02 06:07:54.339 stderr = hang_err
2025-07-02 06:07:54.346 )
2025-07-02 06:07:54.352
2025-07-02 06:07:54.359 # NB: when ISQL will establish attach, first record that it must lock is ID = 1 -- see above SQL_TO_BE_RESTARTED
2025-07-02 06:07:54.366 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:07:54.372 #
2025-07-02 06:07:54.380 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:54.387
2025-07-02 06:07:54.399
2025-07-02 06:07:54.410 #########################
2025-07-02 06:07:54.418 ### L O C K E R - 2 ###
2025-07-02 06:07:54.424 #########################
2025-07-02 06:07:54.430
2025-07-02 06:07:54.443 # Add record with such ID that it **will* be included in the set of rows that must be affected by session-worker:
2025-07-02 06:07:54.454 con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(-11)')
2025-07-02 06:07:54.466 con_lock_2.commit()
2025-07-02 06:07:54.478 con_lock_2.execute_immediate( f'update {target_obj} set id=id where id = -11')
2025-07-02 06:07:54.486
2025-07-02 06:07:54.495 #########################
2025-07-02 06:07:54.507 ### L O C K E R - 1 ###
2025-07-02 06:07:54.517 #########################
2025-07-02 06:07:54.525 con_lock_1.commit() # releases record with ID = 5 ==> now it can be locked by worker.
2025-07-02 06:07:54.532
2025-07-02 06:07:54.539 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 5.
2025-07-02 06:07:54.547 #
2025-07-02 06:07:54.558 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:54.570 # If we come here then it means that record with ID = 5 for sure is locked by WORKER.
2025-07-02 06:07:54.582
2025-07-02 06:07:54.590 con_lock_1.execute_immediate( f'insert into {target_obj}(id) values(-12)' )
2025-07-02 06:07:54.603 con_lock_1.commit()
2025-07-02 06:07:54.613 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id = -12' )
2025-07-02 06:07:54.625
2025-07-02 06:07:54.636
2025-07-02 06:07:54.647 #########################
2025-07-02 06:07:54.655 ### L O C K E R - 2 ###
2025-07-02 06:07:54.662 #########################
2025-07-02 06:07:54.667 con_lock_2.commit() # releases record with ID = -11 ==> now it can be locked by worker.
2025-07-02 06:07:54.672
2025-07-02 06:07:54.677 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -11:
2025-07-02 06:07:54.682 #
2025-07-02 06:07:54.688 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:54.694 # If we come here then it means that record with ID = -11 for sure is locked by WORKER.
2025-07-02 06:07:54.699
2025-07-02 06:07:54.712
2025-07-02 06:07:54.721 con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(-13)' )
2025-07-02 06:07:54.729 con_lock_2.commit()
2025-07-02 06:07:54.737 con_lock_2.execute_immediate( f'update {target_obj} set id=id where id = -13' )
2025-07-02 06:07:54.743
2025-07-02 06:07:54.753 #########################
2025-07-02 06:07:54.764 ### L O C K E R - 1 ###
2025-07-02 06:07:54.773 #########################
2025-07-02 06:07:54.781 con_lock_1.commit() # releases record with ID = -12 ==> now it can be locked by worker.
2025-07-02 06:07:54.788
2025-07-02 06:07:54.794 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -12:
2025-07-02 06:07:54.800 #
2025-07-02 06:07:54.807 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:54.814 # If we come here then it means that record with ID = -12 for sure is locked by WORKER.
2025-07-02 06:07:54.819
2025-07-02 06:07:54.825 #########################
2025-07-02 06:07:54.839 ### L O C K E R - 2 ###
2025-07-02 06:07:54.849 #########################
2025-07-02 06:07:54.862 con_lock_2.commit() # WORKER will complete his job after this
2025-07-02 06:07:54.872
2025-07-02 06:07:54.882
2025-07-02 06:07:54.890 # Here we wait for ISQL complete its mission:
2025-07-02 06:07:54.897 p_worker.wait()
2025-07-02 06:07:54.904
2025-07-02 06:07:54.911 #< with act.db.connect()
2025-07-02 06:07:54.917
2025-07-02 06:07:54.924 for g in (fn_worker_log, fn_worker_err):
2025-07-02 06:07:54.930 with g.open() as f:
2025-07-02 06:07:54.935 for line in f:
2025-07-02 06:07:54.942 if line.split():
2025-07-02 06:07:54.948 if g == fn_worker_log:
2025-07-02 06:07:54.955 print(f'checked_mode: {checked_mode}, STDLOG: {line}')
2025-07-02 06:07:54.961 else:
2025-07-02 06:07:54.968 print(f'UNEXPECTED STDERR {line}')
2025-07-02 06:07:54.976
2025-07-02 06:07:54.982 expected_stdout_worker = f"""
2025-07-02 06:07:54.989 checked_mode: {checked_mode}, STDLOG: Records affected: 8
2025-07-02 06:07:54.995
2025-07-02 06:07:55.001 checked_mode: {checked_mode}, STDLOG: ID
2025-07-02 06:07:55.008 checked_mode: {checked_mode}, STDLOG: =======
2025-07-02 06:07:55.014 checked_mode: {checked_mode}, STDLOG: -5
2025-07-02 06:07:55.021 checked_mode: {checked_mode}, STDLOG: -4
2025-07-02 06:07:55.033 checked_mode: {checked_mode}, STDLOG: -3
2025-07-02 06:07:55.043 checked_mode: {checked_mode}, STDLOG: -2
2025-07-02 06:07:55.053 checked_mode: {checked_mode}, STDLOG: -1
2025-07-02 06:07:55.065 checked_mode: {checked_mode}, STDLOG: 11
2025-07-02 06:07:55.078 checked_mode: {checked_mode}, STDLOG: 12
2025-07-02 06:07:55.086 checked_mode: {checked_mode}, STDLOG: 13
2025-07-02 06:07:55.097 checked_mode: {checked_mode}, STDLOG: Records affected: 8
2025-07-02 06:07:55.108
2025-07-02 06:07:55.117 checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:07:55.128 checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
2025-07-02 06:07:55.139 checked_mode: {checked_mode}, STDLOG: 1 UPD 1
2025-07-02 06:07:55.148 checked_mode: {checked_mode}, STDLOG: 2 UPD 1
2025-07-02 06:07:55.157 checked_mode: {checked_mode}, STDLOG: 3 UPD 1
2025-07-02 06:07:55.171 checked_mode: {checked_mode}, STDLOG: 4 UPD 1
2025-07-02 06:07:55.182 checked_mode: {checked_mode}, STDLOG: -13 UPD 2
2025-07-02 06:07:55.191 checked_mode: {checked_mode}, STDLOG: -12 UPD 2
2025-07-02 06:07:55.198 checked_mode: {checked_mode}, STDLOG: -11 UPD 2
2025-07-02 06:07:55.206 checked_mode: {checked_mode}, STDLOG: 1 UPD 2
2025-07-02 06:07:55.212 checked_mode: {checked_mode}, STDLOG: 2 UPD 2
2025-07-02 06:07:55.218 checked_mode: {checked_mode}, STDLOG: 3 UPD 2
2025-07-02 06:07:55.225 checked_mode: {checked_mode}, STDLOG: 4 UPD 2
2025-07-02 06:07:55.232 checked_mode: {checked_mode}, STDLOG: 5 UPD 2
2025-07-02 06:07:55.239 checked_mode: {checked_mode}, STDLOG: Records affected: 12
2025-07-02 06:07:55.246 """
2025-07-02 06:07:55.254
2025-07-02 06:07:55.265 act.expected_stdout = expected_stdout_worker
2025-07-02 06:07:55.275 act.stdout = capsys.readouterr().out
2025-07-02 06:07:55.283 > assert act.clean_stdout == act.clean_expected_stdout
2025-07-02 06:07:55.289 E assert
2025-07-02 06:07:55.294 E checked_mode: table, STDLOG: Records affected: 8
2025-07-02 06:07:55.300 E checked_mode: table, STDLOG: ID
2025-07-02 06:07:55.307 E checked_mode: table, STDLOG:
2025-07-02 06:07:55.314 E checked_mode: table, STDLOG: -5
2025-07-02 06:07:55.322 E checked_mode: table, STDLOG: -4
2025-07-02 06:07:55.330 E checked_mode: table, STDLOG: -3
2025-07-02 06:07:55.338 E checked_mode: table, STDLOG: -2
2025-07-02 06:07:55.346 E checked_mode: table, STDLOG: -1
2025-07-02 06:07:55.353 E checked_mode: table, STDLOG: 11
2025-07-02 06:07:55.360 E checked_mode: table, STDLOG: 12
2025-07-02 06:07:55.368 E checked_mode: table, STDLOG: 13
2025-07-02 06:07:55.376 E checked_mode: table, STDLOG: Records affected: 8
2025-07-02 06:07:55.383 E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:07:55.391 E checked_mode: table, STDLOG:
2025-07-02 06:07:55.399 E - checked_mode: table, STDLOG: 1 UPD 1
2025-07-02 06:07:55.414 E + checked_mode: table, STDLOG: 1UPD 1
2025-07-02 06:07:55.423 E - checked_mode: table, STDLOG: 2 UPD 1
2025-07-02 06:07:55.442 E + checked_mode: table, STDLOG: 2UPD 1
2025-07-02 06:07:55.449 E - checked_mode: table, STDLOG: 3 UPD 1
2025-07-02 06:07:55.462 E + checked_mode: table, STDLOG: 3UPD 1
2025-07-02 06:07:55.470 E - checked_mode: table, STDLOG: 4 UPD 1
2025-07-02 06:07:55.485 E + checked_mode: table, STDLOG: 4UPD 1
2025-07-02 06:07:55.492 E - checked_mode: table, STDLOG: -13 UPD 2
2025-07-02 06:07:55.508 E + checked_mode: table, STDLOG: -13UPD 2
2025-07-02 06:07:55.516 E - checked_mode: table, STDLOG: -12 UPD 2
2025-07-02 06:07:55.531 E + checked_mode: table, STDLOG: -12UPD 2
2025-07-02 06:07:55.539 E - checked_mode: table, STDLOG: -11 UPD 2
2025-07-02 06:07:55.554 E + checked_mode: table, STDLOG: -11UPD 2
2025-07-02 06:07:55.561 E - checked_mode: table, STDLOG: 1 UPD 2
2025-07-02 06:07:55.582 E + checked_mode: table, STDLOG: 1UPD 2
2025-07-02 06:07:55.589 E - checked_mode: table, STDLOG: 2 UPD 2
2025-07-02 06:07:55.607 E + checked_mode: table, STDLOG: 2UPD 2
2025-07-02 06:07:55.614 E - checked_mode: table, STDLOG: 3 UPD 2
2025-07-02 06:07:55.633 E + checked_mode: table, STDLOG: 3UPD 2
2025-07-02 06:07:55.642 E - checked_mode: table, STDLOG: 4 UPD 2
2025-07-02 06:07:55.656 E + checked_mode: table, STDLOG: 4UPD 2
2025-07-02 06:07:55.661 E - checked_mode: table, STDLOG: 5 UPD 2
2025-07-02 06:07:55.672 E + checked_mode: table, STDLOG: 5UPD 2
2025-07-02 06:07:55.678 E checked_mode: table, STDLOG: Records affected: 12
2025-07-02 06:07:55.690
2025-07-02 06:07:55.700 tests/functional/transactions/test_read_consist_sttm_restart_on_update_01.py:440: AssertionError
2025-07-02 06:07:55.708 ---------------------------- Captured stdout setup -----------------------------
2025-07-02 06:07:55.715 Creating db: localhost:/var/tmp/qa_2024/test_12485/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_12485/tmp_worker.sql')
fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12485/tmp_worker.log')
fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12485/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"update /* {SQL_TAG_THAT_WE_WAITING_FOR} */ {target_obj} set id = -id order by id"
# 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 = 5' )
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 = 1 -- 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=1', SQL_TAG_THAT_WE_WAITING_FOR)
#########################
### L O C K E R - 2 ###
#########################
# Add record with such ID that it **will* be included in the set of rows that must be affected by session-worker:
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 = 5 ==> now it can be locked by worker.
# 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_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.
#########################
### L O C K E R - 2 ###
#########################
con_lock_2.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: 8
checked_mode: {checked_mode}, STDLOG: ID
checked_mode: {checked_mode}, STDLOG: =======
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: 11
checked_mode: {checked_mode}, STDLOG: 12
checked_mode: {checked_mode}, STDLOG: 13
checked_mode: {checked_mode}, STDLOG: Records affected: 8
checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
checked_mode: {checked_mode}, STDLOG: 1 UPD 1
checked_mode: {checked_mode}, STDLOG: 2 UPD 1
checked_mode: {checked_mode}, STDLOG: 3 UPD 1
checked_mode: {checked_mode}, STDLOG: 4 UPD 1
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: 1 UPD 2
checked_mode: {checked_mode}, STDLOG: 2 UPD 2
checked_mode: {checked_mode}, STDLOG: 3 UPD 2
checked_mode: {checked_mode}, STDLOG: 4 UPD 2
checked_mode: {checked_mode}, STDLOG: 5 UPD 2
checked_mode: {checked_mode}, STDLOG: Records affected: 12
"""
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: 8
E checked_mode: table, STDLOG: ID
E checked_mode: table, STDLOG:
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: 11
E checked_mode: table, STDLOG: 12
E checked_mode: table, STDLOG: 13
E checked_mode: table, STDLOG: Records affected: 8
E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
E checked_mode: table, STDLOG:
E - checked_mode: table, STDLOG: 1 UPD 1
E + checked_mode: table, STDLOG: 1UPD 1
E - checked_mode: table, STDLOG: 2 UPD 1
E + checked_mode: table, STDLOG: 2UPD 1
E - checked_mode: table, STDLOG: 3 UPD 1
E + checked_mode: table, STDLOG: 3UPD 1
E - checked_mode: table, STDLOG: 4 UPD 1
E + checked_mode: table, STDLOG: 4UPD 1
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: 1 UPD 2
E + checked_mode: table, STDLOG: 1UPD 2
E - checked_mode: table, STDLOG: 2 UPD 2
E + checked_mode: table, STDLOG: 2UPD 2
E - checked_mode: table, STDLOG: 3 UPD 2
E + checked_mode: table, STDLOG: 3UPD 2
E - checked_mode: table, STDLOG: 4 UPD 2
E + checked_mode: table, STDLOG: 4UPD 2
E - checked_mode: table, STDLOG: 5 UPD 2
E + checked_mode: table, STDLOG: 5UPD 2
E checked_mode: table, STDLOG: Records affected: 12
tests/functional/transactions/test_read_consist_sttm_restart_on_update_01.py:440: AssertionError
|