2 @message |
assert
checked_mode: table, STDLOG: Records affected: 6
checked_mode: table, STDLOG: ID
checked_mode: table, STDLOG:
checked_mode: table, STDLOG: 1
checked_mode: table, STDLOG: 2
checked_mode: table, STDLOG: Records affected: 2
checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: table, STDLOG:
- checked_mode: table, STDLOG: 3 DEL 1
+ checked_mode: table, STDLOG: 3DEL 1
- checked_mode: table, STDLOG: 4 DEL 1
+ checked_mode: table, STDLOG: 4DEL 1
- checked_mode: table, STDLOG: -3 DEL 2
+ checked_mode: table, STDLOG: -3DEL 2
- checked_mode: table, STDLOG: -2 DEL 2
+ checked_mode: table, STDLOG: -2DEL 2
- checked_mode: table, STDLOG: -1 DEL 2
+ checked_mode: table, STDLOG: -1DEL 2
- checked_mode: table, STDLOG: 3 DEL 2
+ checked_mode: table, STDLOG: 3DEL 2
- checked_mode: table, STDLOG: 4 DEL 2
+ checked_mode: table, STDLOG: 4DEL 2
- checked_mode: table, STDLOG: 5 DEL 2
+ checked_mode: table, STDLOG: 5DEL 2
checked_mode: table, STDLOG: Records affected: 8
LOG DETAILS:
2025-07-01 06:05:00.939
2025-07-01 06:05:00.945 act = <firebird.qa.plugin.Action object at [hex]>
2025-07-01 06:05:00.951 fn_worker_sql = PosixPath('/var/tmp/qa_2024/test_12481/tmp_worker.sql')
2025-07-01 06:05:00.958 fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12481/tmp_worker.log')
2025-07-01 06:05:00.965 fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12481/tmp_worker.err')
2025-07-01 06:05:00.977 capsys = <_pytest.capture.CaptureFixture object at [hex]>
2025-07-01 06:05:00.986
2025-07-01 06:05:00.993 @pytest.mark.trace
2025-07-01 06:05:00.999 @pytest.mark.version('>=4.0.2')
2025-07-01 06:05:01.005 def test_1(act: Action, fn_worker_sql: Path, fn_worker_log: Path, fn_worker_err: Path, capsys):
2025-07-01 06:05:01.013 sql_init = (act.files_dir / 'read-consist-sttm-restart-DDL.sql').read_text()
2025-07-01 06:05:01.019
2025-07-01 06:05:01.026 for checked_mode in('table', 'view'):
2025-07-01 06:05:01.035 target_obj = 'test' if checked_mode == 'table' else 'v_test'
2025-07-01 06:05:01.047
2025-07-01 06:05:01.057 SQL_TO_BE_RESTARTED = f"""
2025-07-01 06:05:01.067 merge /* {SQL_TAG_THAT_WE_WAITING_FOR} */ into {target_obj} t
2025-07-01 06:05:01.074 using(select * from {target_obj} where id < 0 or id >= 3 order by id) s on t.id = s.id
2025-07-01 06:05:01.080 when matched then
2025-07-01 06:05:01.086 DELETE
2025-07-01 06:05:01.094 """
2025-07-01 06:05:01.106 # add rows with ID = 1,2,3,4,5:
2025-07-01 06:05:01.113 sql_addi = f'''
2025-07-01 06:05:01.120 set term ^;
2025-07-01 06:05:01.126 execute block as
2025-07-01 06:05:01.133 begin
2025-07-01 06:05:01.140 rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
2025-07-01 06:05:01.147 end
2025-07-01 06:05:01.154 ^
2025-07-01 06:05:01.165 set term ;^
2025-07-01 06:05:01.174 insert into {target_obj}(id, x)
2025-07-01 06:05:01.180 select row_number()over(),row_number()over()
2025-07-01 06:05:01.186 from rdb$types rows 5;
2025-07-01 06:05:01.193 commit;
2025-07-01 06:05:01.199 '''
2025-07-01 06:05:01.205
2025-07-01 06:05:01.211 act.isql(switches=['-q'], input = ''.join( (sql_init, sql_addi) ) )
2025-07-01 06:05:01.217 # ::: NOTE ::: We have to immediately quit if any error raised in prepare phase.
2025-07-01 06:05:01.223 # See also letter from dimitr, 01-feb-2022 14:46
2025-07-01 06:05:01.229 assert act.stderr == ''
2025-07-01 06:05:01.235 act.reset()
2025-07-01 06:05:01.241
2025-07-01 06:05:01.247 trace_cfg_items = [
2025-07-01 06:05:01.253 'time_threshold = 0',
2025-07-01 06:05:01.258 'log_errors = true',
2025-07-01 06:05:01.265 'log_statement_start = true',
2025-07-01 06:05:01.271 'log_statement_finish = true',
2025-07-01 06:05:01.277 ]
2025-07-01 06:05:01.283
2025-07-01 06:05:01.289 with act.trace(db_events = trace_cfg_items, encoding=locale.getpreferredencoding()):
2025-07-01 06:05:01.299
2025-07-01 06:05:01.311 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:01.318
2025-07-01 06:05:01.325 tpb_monitoring = tpb(isolation=Isolation.READ_COMMITTED_RECORD_VERSION, lock_timeout=0)
2025-07-01 06:05:01.332 tx_monitoring = con_monitoring.transaction_manager(tpb_monitoring)
2025-07-01 06:05:01.340 cur_monitoring = tx_monitoring.cursor()
2025-07-01 06:05:01.347
2025-07-01 06:05:01.361 for i,c in enumerate((con_lock_1,con_lock_2)):
2025-07-01 06:05:01.369 sttm = f"execute block as begin rdb$set_context('USER_SESSION', 'WHO', 'LOCKER #{i+1}'); end"
2025-07-01 06:05:01.376 c.execute_immediate(sttm)
2025-07-01 06:05:01.384
2025-07-01 06:05:01.391 #########################
2025-07-01 06:05:01.398 ### L O C K E R - 1 ###
2025-07-01 06:05:01.404 #########################
2025-07-01 06:05:01.412
2025-07-01 06:05:01.418 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id = 5' )
2025-07-01 06:05:01.425
2025-07-01 06:05:01.431 worker_sql = f'''
2025-07-01 06:05:01.437 set list on;
2025-07-01 06:05:01.444 set autoddl off;
2025-07-01 06:05:01.452 set term ^;
2025-07-01 06:05:01.461 execute block returns (whoami varchar(30)) as
2025-07-01 06:05:01.468 begin
2025-07-01 06:05:01.474 whoami = 'WORKER'; -- , ATT#' || current_connection;
2025-07-01 06:05:01.480 rdb$set_context('USER_SESSION','WHO', whoami);
2025-07-01 06:05:01.486 -- suspend;
2025-07-01 06:05:01.492 end
2025-07-01 06:05:01.499 ^
2025-07-01 06:05:01.506 set term ;^
2025-07-01 06:05:01.516 commit;
2025-07-01 06:05:01.523 --set echo on;
2025-07-01 06:05:01.529 SET KEEP_TRAN_PARAMS ON;
2025-07-01 06:05:01.535 set transaction read committed read consistency;
2025-07-01 06:05:01.540 set list off;
2025-07-01 06:05:01.547 set wng off;
2025-07-01 06:05:01.553 set count on;
2025-07-01 06:05:01.560
2025-07-01 06:05:01.567 -- MUST HANG:
2025-07-01 06:05:01.574 {SQL_TO_BE_RESTARTED};
2025-07-01 06:05:01.579
2025-07-01 06:05:01.585 -- check results:
2025-07-01 06:05:01.591 -- ###############
2025-07-01 06:05:01.596 select id from {target_obj} order by id; -- this will produce output only after all lockers do their commit/rollback
2025-07-01 06:05:01.601
2025-07-01 06:05:01.606 select v.old_id, v.op, v.snap_no_rank
2025-07-01 06:05:01.611 from v_worker_log v
2025-07-01 06:05:01.616 where v.op = 'del';
2025-07-01 06:05:01.622
2025-07-01 06:05:01.627 set width who 10;
2025-07-01 06:05:01.632 -- DO NOT check this! Values can differ here from one run to another!
2025-07-01 06:05:01.638 -- 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:01.644
2025-07-01 06:05:01.650 rollback;
2025-07-01 06:05:01.664
2025-07-01 06:05:01.675 '''
2025-07-01 06:05:01.684
2025-07-01 06:05:01.691 fn_worker_sql.write_text(worker_sql)
2025-07-01 06:05:01.697
2025-07-01 06:05:01.704 with fn_worker_log.open(mode='w') as hang_out, fn_worker_err.open(mode='w') as hang_err:
2025-07-01 06:05:01.709
2025-07-01 06:05:01.714 ############################################################################
2025-07-01 06:05:01.720 ### 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:01.726 ############################################################################
2025-07-01 06:05:01.732 p_worker = subprocess.Popen([act.vars['isql'], '-i', str(fn_worker_sql),
2025-07-01 06:05:01.738 '-user', act.db.user,
2025-07-01 06:05:01.744 '-password', act.db.password,
2025-07-01 06:05:01.751 '-pag', '9999999',
2025-07-01 06:05:01.756 act.db.dsn
2025-07-01 06:05:01.761 ],
2025-07-01 06:05:01.766 stdout = hang_out,
2025-07-01 06:05:01.770 stderr = hang_err
2025-07-01 06:05:01.775 )
2025-07-01 06:05:01.781 # NB: when ISQL will establish attach, first record that it must lock is ID = 3 -- see above SQL_TO_BE_RESTARTED
2025-07-01 06:05:01.788 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-01 06:05:01.794 #
2025-07-01 06:05:01.801 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-01 06:05:01.809
2025-07-01 06:05:01.816
2025-07-01 06:05:01.822 #########################
2025-07-01 06:05:01.835 ### L O C K E R - 2 ###
2025-07-01 06:05:01.846 #########################
2025-07-01 06:05:01.855 # Insert ID value that is less than previous min(id).
2025-07-01 06:05:01.869 # Session-worker is executing its statement using PLAN ORDER,
2025-07-01 06:05:01.878 # and it should see this new value and restart its statement:
2025-07-01 06:05:01.884 con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(-1)' )
2025-07-01 06:05:01.890 con_lock_2.commit()
2025-07-01 06:05:01.897 con_lock_2.execute_immediate( f'update {target_obj} set id=id where id = -1' )
2025-07-01 06:05:01.904
2025-07-01 06:05:01.911 #########################
2025-07-01 06:05:01.918 ### L O C K E R - 1 ###
2025-07-01 06:05:01.929 #########################
2025-07-01 06:05:01.939 con_lock_1.commit() # releases record with ID = 5 ==> now it can be locked by worker.
2025-07-01 06:05:01.946
2025-07-01 06:05:01.953 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 5.
2025-07-01 06:05:01.959 #
2025-07-01 06:05:01.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:01.972 # If we come here then it means that record with ID = 5 for sure is locked by WORKER.
2025-07-01 06:05:01.984
2025-07-01 06:05:01.992 con_lock_1.execute_immediate( f'insert into {target_obj}(id) values(-2)' )
2025-07-01 06:05:01.999 con_lock_1.commit()
2025-07-01 06:05:02.006 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id = -2' )
2025-07-01 06:05:02.014
2025-07-01 06:05:02.021
2025-07-01 06:05:02.028 #########################
2025-07-01 06:05:02.033 ### L O C K E R - 2 ###
2025-07-01 06:05:02.038 #########################
2025-07-01 06:05:02.043 # Insert ID value that is less than previous min(id).
2025-07-01 06:05:02.048 # Session-worker is executing its statement using PLAN ORDER,
2025-07-01 06:05:02.053 # and it should see this new value and restart its statement:
2025-07-01 06:05:02.058 con_lock_2.commit() # releases record with ID = -1 ==> now it can be locked by worker.
2025-07-01 06:05:02.062
2025-07-01 06:05:02.067 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -1.
2025-07-01 06:05:02.071 #
2025-07-01 06:05:02.076 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:02.083 # If we come here then it means that record with ID = -1 for sure is locked by WORKER.
2025-07-01 06:05:02.089
2025-07-01 06:05:02.095 con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(-3)' )
2025-07-01 06:05:02.101 con_lock_2.commit()
2025-07-01 06:05:02.107 con_lock_2.execute_immediate( f'update {target_obj} set id=id where id = -3' )
2025-07-01 06:05:02.113
2025-07-01 06:05:02.118 #########################
2025-07-01 06:05:02.124 ### L O C K E R - 1 ###
2025-07-01 06:05:02.130 #########################
2025-07-01 06:05:02.135 con_lock_1.commit() # releases record with ID = -2 ==> now it can be locked by worker.
2025-07-01 06:05:02.140
2025-07-01 06:05:02.146 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -2.
2025-07-01 06:05:02.152 #
2025-07-01 06:05:02.158 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:02.164 # If we come here then it means that record with ID = -2 for sure is locked by WORKER.
2025-07-01 06:05:02.169
2025-07-01 06:05:02.175 con_lock_2.commit()
2025-07-01 06:05:02.180
2025-07-01 06:05:02.189 # Here we wait for ISQL complete its mission:
2025-07-01 06:05:02.196 p_worker.wait()
2025-07-01 06:05:02.202
2025-07-01 06:05:02.212 #< with act.db.connect()
2025-07-01 06:05:02.223
2025-07-01 06:05:02.234 for g in (fn_worker_log, fn_worker_err):
2025-07-01 06:05:02.241 with g.open() as f:
2025-07-01 06:05:02.247 for line in f:
2025-07-01 06:05:02.253 if line.split():
2025-07-01 06:05:02.259 if g == fn_worker_log:
2025-07-01 06:05:02.265 print(f'checked_mode: {checked_mode}, STDLOG: {line}')
2025-07-01 06:05:02.270 else:
2025-07-01 06:05:02.277 print(f'UNEXPECTED STDERR {line}')
2025-07-01 06:05:02.283
2025-07-01 06:05:02.289 expected_stdout_worker = f"""
2025-07-01 06:05:02.295 checked_mode: {checked_mode}, STDLOG: Records affected: 6
2025-07-01 06:05:02.300
2025-07-01 06:05:02.307 checked_mode: {checked_mode}, STDLOG: ID
2025-07-01 06:05:02.314 checked_mode: {checked_mode}, STDLOG: =======
2025-07-01 06:05:02.324 checked_mode: {checked_mode}, STDLOG: 1
2025-07-01 06:05:02.335 checked_mode: {checked_mode}, STDLOG: 2
2025-07-01 06:05:02.343 checked_mode: {checked_mode}, STDLOG: Records affected: 2
2025-07-01 06:05:02.350
2025-07-01 06:05:02.356 checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-01 06:05:02.362 checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
2025-07-01 06:05:02.370 checked_mode: {checked_mode}, STDLOG: 3 DEL 1
2025-07-01 06:05:02.376 checked_mode: {checked_mode}, STDLOG: 4 DEL 1
2025-07-01 06:05:02.383 checked_mode: {checked_mode}, STDLOG: -3 DEL 2
2025-07-01 06:05:02.392 checked_mode: {checked_mode}, STDLOG: -2 DEL 2
2025-07-01 06:05:02.399 checked_mode: {checked_mode}, STDLOG: -1 DEL 2
2025-07-01 06:05:02.405 checked_mode: {checked_mode}, STDLOG: 3 DEL 2
2025-07-01 06:05:02.411 checked_mode: {checked_mode}, STDLOG: 4 DEL 2
2025-07-01 06:05:02.417 checked_mode: {checked_mode}, STDLOG: 5 DEL 2
2025-07-01 06:05:02.423 checked_mode: {checked_mode}, STDLOG: Records affected: 8
2025-07-01 06:05:02.429 """
2025-07-01 06:05:02.435
2025-07-01 06:05:02.441 act.expected_stdout = expected_stdout_worker
2025-07-01 06:05:02.447 act.stdout = capsys.readouterr().out
2025-07-01 06:05:02.453 > assert act.clean_stdout == act.clean_expected_stdout
2025-07-01 06:05:02.459 E assert
2025-07-01 06:05:02.468 E checked_mode: table, STDLOG: Records affected: 6
2025-07-01 06:05:02.474 E checked_mode: table, STDLOG: ID
2025-07-01 06:05:02.480 E checked_mode: table, STDLOG:
2025-07-01 06:05:02.485 E checked_mode: table, STDLOG: 1
2025-07-01 06:05:02.491 E checked_mode: table, STDLOG: 2
2025-07-01 06:05:02.497 E checked_mode: table, STDLOG: Records affected: 2
2025-07-01 06:05:02.509 E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-01 06:05:02.523 E checked_mode: table, STDLOG:
2025-07-01 06:05:02.533 E - checked_mode: table, STDLOG: 3 DEL 1
2025-07-01 06:05:02.559 E + checked_mode: table, STDLOG: 3DEL 1
2025-07-01 06:05:02.571 E - checked_mode: table, STDLOG: 4 DEL 1
2025-07-01 06:05:02.593 E + checked_mode: table, STDLOG: 4DEL 1
2025-07-01 06:05:02.603 E - checked_mode: table, STDLOG: -3 DEL 2
2025-07-01 06:05:02.617 E + checked_mode: table, STDLOG: -3DEL 2
2025-07-01 06:05:02.623 E - checked_mode: table, STDLOG: -2 DEL 2
2025-07-01 06:05:02.634 E + checked_mode: table, STDLOG: -2DEL 2
2025-07-01 06:05:02.641 E - checked_mode: table, STDLOG: -1 DEL 2
2025-07-01 06:05:02.653 E + checked_mode: table, STDLOG: -1DEL 2
2025-07-01 06:05:02.659 E - checked_mode: table, STDLOG: 3 DEL 2
2025-07-01 06:05:02.672 E + checked_mode: table, STDLOG: 3DEL 2
2025-07-01 06:05:02.678 E - checked_mode: table, STDLOG: 4 DEL 2
2025-07-01 06:05:02.690 E + checked_mode: table, STDLOG: 4DEL 2
2025-07-01 06:05:02.699 E - checked_mode: table, STDLOG: 5 DEL 2
2025-07-01 06:05:02.718 E + checked_mode: table, STDLOG: 5DEL 2
2025-07-01 06:05:02.725 E checked_mode: table, STDLOG: Records affected: 8
2025-07-01 06:05:02.731
2025-07-01 06:05:02.737 tests/functional/transactions/test_read_consist_sttm_restart_on_merge_02.py:486: AssertionError
2025-07-01 06:05:02.743 ---------------------------- Captured stdout setup -----------------------------
2025-07-01 06:05:02.749 Creating db: localhost:/var/tmp/qa_2024/test_12481/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_12481/tmp_worker.sql')
fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12481/tmp_worker.log')
fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12481/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 * from {target_obj} where id < 0 or id >= 3 order by id) s on t.id = s.id
when matched then
DELETE
"""
# add rows with ID = 1,2,3,4,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 echo on;
SET KEEP_TRAN_PARAMS ON;
set transaction read committed read consistency;
set list off;
set wng off;
set count on;
-- MUST HANG:
{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 = 'del';
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', '9999999',
act.db.dsn
],
stdout = hang_out,
stderr = hang_err
)
# NB: when ISQL will establish attach, first record that it must lock is ID = 3 -- 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=3', SQL_TAG_THAT_WE_WAITING_FOR)
#########################
### L O C K E R - 2 ###
#########################
# Insert ID value that is less than previous min(id).
# Session-worker is executing its statement using PLAN ORDER,
# and it should see this new value and restart its statement:
con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(-1)' )
con_lock_2.commit()
con_lock_2.execute_immediate( f'update {target_obj} set id=id where id = -1' )
#########################
### 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(-2)' )
con_lock_1.commit()
con_lock_1.execute_immediate( f'update {target_obj} set id=id where id = -2' )
#########################
### L O C K E R - 2 ###
#########################
# Insert ID value that is less than previous min(id).
# Session-worker is executing its statement using PLAN ORDER,
# and it should see this new value and restart its statement:
con_lock_2.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_2.execute_immediate( f'insert into {target_obj}(id) values(-3)' )
con_lock_2.commit()
con_lock_2.execute_immediate( f'update {target_obj} set id=id where id = -3' )
#########################
### L O C K E R - 1 ###
#########################
con_lock_1.commit() # releases record with ID = -2 ==> now it can be locked by worker.
# We have to WAIT HERE until worker will actually 'catch' just released record with ID = -2.
#
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)
# If we come here then it means that record with ID = -2 for sure is locked by WORKER.
con_lock_2.commit()
# 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: 6
checked_mode: {checked_mode}, STDLOG: ID
checked_mode: {checked_mode}, STDLOG: =======
checked_mode: {checked_mode}, STDLOG: 1
checked_mode: {checked_mode}, STDLOG: 2
checked_mode: {checked_mode}, STDLOG: Records affected: 2
checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
checked_mode: {checked_mode}, STDLOG: 3 DEL 1
checked_mode: {checked_mode}, STDLOG: 4 DEL 1
checked_mode: {checked_mode}, STDLOG: -3 DEL 2
checked_mode: {checked_mode}, STDLOG: -2 DEL 2
checked_mode: {checked_mode}, STDLOG: -1 DEL 2
checked_mode: {checked_mode}, STDLOG: 3 DEL 2
checked_mode: {checked_mode}, STDLOG: 4 DEL 2
checked_mode: {checked_mode}, STDLOG: 5 DEL 2
checked_mode: {checked_mode}, STDLOG: Records affected: 8
"""
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: 6
E checked_mode: table, STDLOG: ID
E checked_mode: table, STDLOG:
E checked_mode: table, STDLOG: 1
E checked_mode: table, STDLOG: 2
E checked_mode: table, STDLOG: Records affected: 2
E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
E checked_mode: table, STDLOG:
E - checked_mode: table, STDLOG: 3 DEL 1
E + checked_mode: table, STDLOG: 3DEL 1
E - checked_mode: table, STDLOG: 4 DEL 1
E + checked_mode: table, STDLOG: 4DEL 1
E - checked_mode: table, STDLOG: -3 DEL 2
E + checked_mode: table, STDLOG: -3DEL 2
E - checked_mode: table, STDLOG: -2 DEL 2
E + checked_mode: table, STDLOG: -2DEL 2
E - checked_mode: table, STDLOG: -1 DEL 2
E + checked_mode: table, STDLOG: -1DEL 2
E - checked_mode: table, STDLOG: 3 DEL 2
E + checked_mode: table, STDLOG: 3DEL 2
E - checked_mode: table, STDLOG: 4 DEL 2
E + checked_mode: table, STDLOG: 4DEL 2
E - checked_mode: table, STDLOG: 5 DEL 2
E + checked_mode: table, STDLOG: 5DEL 2
E checked_mode: table, STDLOG: Records affected: 8
tests/functional/transactions/test_read_consist_sttm_restart_on_merge_02.py:486: AssertionError
|