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-02 06:07:39.072
2025-07-02 06:07:39.078 act = <firebird.qa.plugin.Action object at [hex]>
2025-07-02 06:07:39.084 fn_worker_sql = PosixPath('/var/tmp/qa_2024/test_12478/tmp_worker.sql')
2025-07-02 06:07:39.090 fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12478/tmp_worker.log')
2025-07-02 06:07:39.095 fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12478/tmp_worker.err')
2025-07-02 06:07:39.100 capsys = <_pytest.capture.CaptureFixture object at [hex]>
2025-07-02 06:07:39.105
2025-07-02 06:07:39.111 @pytest.mark.trace
2025-07-02 06:07:39.116 @pytest.mark.version('>=4.0.2')
2025-07-02 06:07:39.125 def test_1(act: Action, fn_worker_sql: Path, fn_worker_log: Path, fn_worker_err: Path, capsys):
2025-07-02 06:07:39.136 sql_init = (act.files_dir / 'read-consist-sttm-restart-DDL.sql').read_text()
2025-07-02 06:07:39.144
2025-07-02 06:07:39.151 for checked_mode in('table', 'view'):
2025-07-02 06:07:39.159 target_obj = 'test' if checked_mode == 'table' else 'v_test'
2025-07-02 06:07:39.168 SQL_TO_BE_RESTARTED = f'delete /* {SQL_TAG_THAT_WE_WAITING_FOR} */ from {target_obj} where id < 0 or id >= 3 order by id'
2025-07-02 06:07:39.176
2025-07-02 06:07:39.184 # add rows with ID = 1,2,3,4,5:
2025-07-02 06:07:39.192 sql_addi = f'''
2025-07-02 06:07:39.200 set term ^;
2025-07-02 06:07:39.208 execute block as
2025-07-02 06:07:39.216 begin
2025-07-02 06:07:39.225 rdb$set_context('USER_SESSION', 'WHO', 'INIT_DATA');
2025-07-02 06:07:39.232 end
2025-07-02 06:07:39.240 ^
2025-07-02 06:07:39.248 set term ;^
2025-07-02 06:07:39.256 insert into {target_obj}(id, x)
2025-07-02 06:07:39.264 select row_number()over(),row_number()over()
2025-07-02 06:07:39.270 from rdb$types rows 5;
2025-07-02 06:07:39.277 commit;
2025-07-02 06:07:39.282 '''
2025-07-02 06:07:39.288
2025-07-02 06:07:39.295 act.isql(switches=['-q'], input = ''.join( (sql_init, sql_addi) ) )
2025-07-02 06:07:39.301 # ::: NOTE ::: We have to immediately quit if any error raised in prepare phase.
2025-07-02 06:07:39.307 # See also letter from dimitr, 01-feb-2022 14:46
2025-07-02 06:07:39.314 assert act.stderr == ''
2025-07-02 06:07:39.320 act.reset()
2025-07-02 06:07:39.326
2025-07-02 06:07:39.332 trace_cfg_items = [
2025-07-02 06:07:39.338 'time_threshold = 0',
2025-07-02 06:07:39.344 'log_errors = true',
2025-07-02 06:07:39.351 'log_statement_start = true',
2025-07-02 06:07:39.357 'log_statement_finish = true',
2025-07-02 06:07:39.364 ]
2025-07-02 06:07:39.377
2025-07-02 06:07:39.388 with act.trace(db_events = trace_cfg_items, encoding=locale.getpreferredencoding()):
2025-07-02 06:07:39.402
2025-07-02 06:07:39.412 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:39.419
2025-07-02 06:07:39.427 tpb_monitoring = tpb(isolation=Isolation.READ_COMMITTED_RECORD_VERSION, lock_timeout=0)
2025-07-02 06:07:39.438 tx_monitoring = con_monitoring.transaction_manager(tpb_monitoring)
2025-07-02 06:07:39.464 cur_monitoring = tx_monitoring.cursor()
2025-07-02 06:07:39.471
2025-07-02 06:07:39.478 for i,c in enumerate((con_lock_1,con_lock_2)):
2025-07-02 06:07:39.485 sttm = f"execute block as begin rdb$set_context('USER_SESSION', 'WHO', 'LOCKER #{i+1}'); end"
2025-07-02 06:07:39.497 c.execute_immediate(sttm)
2025-07-02 06:07:39.506
2025-07-02 06:07:39.514 #########################
2025-07-02 06:07:39.522 ### L O C K E R - 1 ###
2025-07-02 06:07:39.530 #########################
2025-07-02 06:07:39.541 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id = 5' )
2025-07-02 06:07:39.552
2025-07-02 06:07:39.560 worker_sql = f'''
2025-07-02 06:07:39.572 set list on;
2025-07-02 06:07:39.580 set autoddl off;
2025-07-02 06:07:39.585 set term ^;
2025-07-02 06:07:39.590 execute block returns (whoami varchar(30)) as
2025-07-02 06:07:39.594 begin
2025-07-02 06:07:39.599 whoami = 'WORKER'; -- , ATT#' || current_connection;
2025-07-02 06:07:39.603 rdb$set_context('USER_SESSION','WHO', whoami);
2025-07-02 06:07:39.608 -- suspend;
2025-07-02 06:07:39.613 end
2025-07-02 06:07:39.619 ^
2025-07-02 06:07:39.623 set term ;^
2025-07-02 06:07:39.629 commit;
2025-07-02 06:07:39.635 --set echo on;
2025-07-02 06:07:39.640 SET KEEP_TRAN_PARAMS ON;
2025-07-02 06:07:39.646 set transaction read committed read consistency;
2025-07-02 06:07:39.652 --select current_connection, current_transaction from rdb$database;
2025-07-02 06:07:39.658 set list off;
2025-07-02 06:07:39.664 set wng off;
2025-07-02 06:07:39.668 --set plan on;
2025-07-02 06:07:39.675 set count on;
2025-07-02 06:07:39.687
2025-07-02 06:07:39.696 -- delete from {target_obj} where id < 0 or id >= 3 order by id; -- THIS MUST BE LOCKED
2025-07-02 06:07:39.705 {SQL_TO_BE_RESTARTED};
2025-07-02 06:07:39.712
2025-07-02 06:07:39.719 -- check results:
2025-07-02 06:07:39.724 -- ###############
2025-07-02 06:07:39.731 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:39.739
2025-07-02 06:07:39.753 select v.old_id, v.op, v.snap_no_rank
2025-07-02 06:07:39.766 from v_worker_log v
2025-07-02 06:07:39.776 where v.op = 'del';
2025-07-02 06:07:39.785
2025-07-02 06:07:39.792 set width who 10;
2025-07-02 06:07:39.798 -- DO NOT check this! Values can differ here from one run to another!
2025-07-02 06:07:39.808 -- 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:39.822
2025-07-02 06:07:39.833 rollback;
2025-07-02 06:07:39.841
2025-07-02 06:07:39.847 '''
2025-07-02 06:07:39.855
2025-07-02 06:07:39.865 fn_worker_sql.write_text(worker_sql)
2025-07-02 06:07:39.873
2025-07-02 06:07:39.886 with fn_worker_log.open(mode='w') as hang_out, fn_worker_err.open(mode='w') as hang_err:
2025-07-02 06:07:39.902
2025-07-02 06:07:39.912 ############################################################################
2025-07-02 06:07:39.921 ### 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:39.931 ############################################################################
2025-07-02 06:07:39.944 p_worker = subprocess.Popen([act.vars['isql'], '-i', str(fn_worker_sql),
2025-07-02 06:07:39.956 '-user', act.db.user,
2025-07-02 06:07:39.965 '-password', act.db.password,
2025-07-02 06:07:39.972 act.db.dsn
2025-07-02 06:07:39.979 ],
2025-07-02 06:07:39.985 stdout = hang_out,
2025-07-02 06:07:39.997 stderr = hang_err
2025-07-02 06:07:40.008 )
2025-07-02 06:07:40.022 # NB: when ISQL will establish attach, first record that it must lock is ID = 3 -- see above SQL_TO_BE_RESTARTED
2025-07-02 06:07:40.033 # We must to ensure that this (worker) attachment has been really created and LOCKS this record:
2025-07-02 06:07:40.041 #
2025-07-02 06:07:40.051 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:07:40.063
2025-07-02 06:07:40.073
2025-07-02 06:07:40.083 #########################
2025-07-02 06:07:40.093 ### L O C K E R - 2 ###
2025-07-02 06:07:40.101 #########################
2025-07-02 06:07:40.109 # Insert ID value that is less than previous min(id).
2025-07-02 06:07:40.116 # Session-worker is executing its statement using PLAN ORDER,
2025-07-02 06:07:40.122 # and it should see this new value and restart its statement:
2025-07-02 06:07:40.129 con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(-1)' )
2025-07-02 06:07:40.135 con_lock_2.commit()
2025-07-02 06:07:40.141 con_lock_2.execute_immediate( f'update {target_obj} set id=id where id = -1' )
2025-07-02 06:07:40.148
2025-07-02 06:07:40.160 #########################
2025-07-02 06:07:40.173 ### L O C K E R - 1 ###
2025-07-02 06:07:40.185 #########################
2025-07-02 06:07:40.195 con_lock_1.commit() # releases record with ID = 5 ==> now it can be locked by worker.
2025-07-02 06:07:40.202
2025-07-02 06:07:40.210 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = 5.
2025-07-02 06:07:40.217 #
2025-07-02 06:07:40.224 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:40.231 # If we come here then it means that record with ID = 5 for sure is locked by WORKER.
2025-07-02 06:07:40.238
2025-07-02 06:07:40.244 con_lock_1.execute_immediate( f'insert into {target_obj}(id) values(-2)' )
2025-07-02 06:07:40.250 con_lock_1.commit()
2025-07-02 06:07:40.256 con_lock_1.execute_immediate( f'update {target_obj} set id=id where id = -2' )
2025-07-02 06:07:40.261
2025-07-02 06:07:40.268
2025-07-02 06:07:40.280 #########################
2025-07-02 06:07:40.291 ### L O C K E R - 2 ###
2025-07-02 06:07:40.300 #########################
2025-07-02 06:07:40.307 # Insert ID value that is less than previous min(id).
2025-07-02 06:07:40.315 # Session-worker is executing its statement using PLAN ORDER,
2025-07-02 06:07:40.321 # and it should see this new value and restart its statement:
2025-07-02 06:07:40.327 con_lock_2.commit()
2025-07-02 06:07:40.337
2025-07-02 06:07:40.348 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -1.
2025-07-02 06:07:40.356 #
2025-07-02 06:07:40.362 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:40.367 # If we come here then it means that record with ID = -1 for sure is locked by WORKER.
2025-07-02 06:07:40.372
2025-07-02 06:07:40.376 con_lock_2.execute_immediate( f'insert into {target_obj}(id) values(-3)' )
2025-07-02 06:07:40.381 con_lock_2.commit()
2025-07-02 06:07:40.386 con_lock_2.execute_immediate( f'update {target_obj} set id=id where id = -3' )
2025-07-02 06:07:40.391
2025-07-02 06:07:40.397 #########################
2025-07-02 06:07:40.407 ### L O C K E R - 1 ###
2025-07-02 06:07:40.415 #########################
2025-07-02 06:07:40.427 con_lock_1.commit()
2025-07-02 06:07:40.436
2025-07-02 06:07:40.443 # We have to WAIT HERE until worker will actually 'catch' just released record with ID = -2.
2025-07-02 06:07:40.450 #
2025-07-02 06:07:40.458 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:07:40.470 # If we come here then it means that record with ID = -2 for sure is locked by WORKER.
2025-07-02 06:07:40.482
2025-07-02 06:07:40.489
2025-07-02 06:07:40.495 con_lock_2.commit() # WORKER will complete his job after this
2025-07-02 06:07:40.502
2025-07-02 06:07:40.508 # Here we wait for ISQL complete its mission:
2025-07-02 06:07:40.514 p_worker.wait()
2025-07-02 06:07:40.518
2025-07-02 06:07:40.523 #< with act.db.connect()
2025-07-02 06:07:40.528
2025-07-02 06:07:40.539
2025-07-02 06:07:40.549 for g in (fn_worker_log, fn_worker_err):
2025-07-02 06:07:40.557 with g.open() as f:
2025-07-02 06:07:40.564 for line in f:
2025-07-02 06:07:40.577 if line.split():
2025-07-02 06:07:40.588 if g == fn_worker_log:
2025-07-02 06:07:40.596 print(f'checked_mode: {checked_mode}, STDLOG: {line}')
2025-07-02 06:07:40.605 else:
2025-07-02 06:07:40.618 print(f'UNEXPECTED STDERR {line}')
2025-07-02 06:07:40.625
2025-07-02 06:07:40.639 expected_stdout_worker = f"""
2025-07-02 06:07:40.649 checked_mode: {checked_mode}, STDLOG: Records affected: 6
2025-07-02 06:07:40.655
2025-07-02 06:07:40.663 checked_mode: {checked_mode}, STDLOG: ID
2025-07-02 06:07:40.671 checked_mode: {checked_mode}, STDLOG: =======
2025-07-02 06:07:40.678 checked_mode: {checked_mode}, STDLOG: 1
2025-07-02 06:07:40.687 checked_mode: {checked_mode}, STDLOG: 2
2025-07-02 06:07:40.700 checked_mode: {checked_mode}, STDLOG: Records affected: 2
2025-07-02 06:07:40.709
2025-07-02 06:07:40.716 checked_mode: {checked_mode}, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:07:40.722 checked_mode: {checked_mode}, STDLOG: ======= ====== =====================
2025-07-02 06:07:40.729 checked_mode: {checked_mode}, STDLOG: 3 DEL 1
2025-07-02 06:07:40.736 checked_mode: {checked_mode}, STDLOG: 4 DEL 1
2025-07-02 06:07:40.750 checked_mode: {checked_mode}, STDLOG: -3 DEL 2
2025-07-02 06:07:40.764 checked_mode: {checked_mode}, STDLOG: -2 DEL 2
2025-07-02 06:07:40.777 checked_mode: {checked_mode}, STDLOG: -1 DEL 2
2025-07-02 06:07:40.791 checked_mode: {checked_mode}, STDLOG: 3 DEL 2
2025-07-02 06:07:40.799 checked_mode: {checked_mode}, STDLOG: 4 DEL 2
2025-07-02 06:07:40.808 checked_mode: {checked_mode}, STDLOG: 5 DEL 2
2025-07-02 06:07:40.816 checked_mode: {checked_mode}, STDLOG: Records affected: 8
2025-07-02 06:07:40.823 """
2025-07-02 06:07:40.829
2025-07-02 06:07:40.835 act.expected_stdout = expected_stdout_worker
2025-07-02 06:07:40.840 act.stdout = capsys.readouterr().out
2025-07-02 06:07:40.847 > assert act.clean_stdout == act.clean_expected_stdout
2025-07-02 06:07:40.853 E assert
2025-07-02 06:07:40.858 E checked_mode: table, STDLOG: Records affected: 6
2025-07-02 06:07:40.865 E checked_mode: table, STDLOG: ID
2025-07-02 06:07:40.872 E checked_mode: table, STDLOG:
2025-07-02 06:07:40.879 E checked_mode: table, STDLOG: 1
2025-07-02 06:07:40.887 E checked_mode: table, STDLOG: 2
2025-07-02 06:07:40.895 E checked_mode: table, STDLOG: Records affected: 2
2025-07-02 06:07:40.901 E checked_mode: table, STDLOG: OLD_ID OP SNAP_NO_RANK
2025-07-02 06:07:40.907 E checked_mode: table, STDLOG:
2025-07-02 06:07:40.914 E - checked_mode: table, STDLOG: 3 DEL 1
2025-07-02 06:07:40.932 E + checked_mode: table, STDLOG: 3DEL 1
2025-07-02 06:07:40.938 E - checked_mode: table, STDLOG: 4 DEL 1
2025-07-02 06:07:40.951 E + checked_mode: table, STDLOG: 4DEL 1
2025-07-02 06:07:40.959 E - checked_mode: table, STDLOG: -3 DEL 2
2025-07-02 06:07:40.971 E + checked_mode: table, STDLOG: -3DEL 2
2025-07-02 06:07:40.976 E - checked_mode: table, STDLOG: -2 DEL 2
2025-07-02 06:07:40.988 E + checked_mode: table, STDLOG: -2DEL 2
2025-07-02 06:07:40.994 E - checked_mode: table, STDLOG: -1 DEL 2
2025-07-02 06:07:41.013 E + checked_mode: table, STDLOG: -1DEL 2
2025-07-02 06:07:41.022 E - checked_mode: table, STDLOG: 3 DEL 2
2025-07-02 06:07:41.042 E + checked_mode: table, STDLOG: 3DEL 2
2025-07-02 06:07:41.050 E - checked_mode: table, STDLOG: 4 DEL 2
2025-07-02 06:07:41.062 E + checked_mode: table, STDLOG: 4DEL 2
2025-07-02 06:07:41.068 E - checked_mode: table, STDLOG: 5 DEL 2
2025-07-02 06:07:41.080 E + checked_mode: table, STDLOG: 5DEL 2
2025-07-02 06:07:41.087 E checked_mode: table, STDLOG: Records affected: 8
2025-07-02 06:07:41.093
2025-07-02 06:07:41.100 tests/functional/transactions/test_read_consist_sttm_restart_on_delete_02.py:437: AssertionError
2025-07-02 06:07:41.106 ---------------------------- Captured stdout setup -----------------------------
2025-07-02 06:07:41.114 Creating db: localhost:/var/tmp/qa_2024/test_12478/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_12478/tmp_worker.sql')
fn_worker_log = PosixPath('/var/tmp/qa_2024/test_12478/tmp_worker.log')
fn_worker_err = PosixPath('/var/tmp/qa_2024/test_12478/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'delete /* {SQL_TAG_THAT_WE_WAITING_FOR} */ from {target_obj} where id < 0 or id >= 3 order by id'
# 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;
--select current_connection, current_transaction from rdb$database;
set list off;
set wng off;
--set plan on;
set count on;
-- delete from {target_obj} where id < 0 or id >= 3 order by id; -- 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 = '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,
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()
# 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()
# 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() # 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: 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_delete_02.py:437: AssertionError
|