|
| 1 | +#coding:utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +ID: issue-7627 |
| 5 | +ISSUE: https://github.com/FirebirdSQL/firebird/issues/7627 |
| 6 | +TITLE: The size of the database with big records becomes bigger after backup/restore |
| 7 | +DESCRIPTION: |
| 8 | + Test creates table with 'very width' column, adds data to it (padded GUID strings) and makes b/r. |
| 9 | + New size of database (after restore) must not exceed initial one. |
| 10 | +NOTES: |
| 11 | + [26.08.2023] pzotov |
| 12 | + Column size must be VERY CLOSE to maximal allowed by implementation. |
| 13 | + On 5.0.0.1070 (date of build 14-jun-2023) bug can be reproduced when |
| 14 | + column size is 32760, but on size = 32000 this is not so: DB size remains the same. |
| 15 | +
|
| 16 | + Confirmed bug on 5.0.0.1070. |
| 17 | + Checked on 5.0.0.1170, 4.0.4.2979 |
| 18 | +""" |
| 19 | + |
| 20 | +from io import BytesIO |
| 21 | +from pathlib import Path |
| 22 | + |
| 23 | +import pytest |
| 24 | +from firebird.qa import * |
| 25 | +from firebird.driver import SrvRestoreFlag |
| 26 | + |
| 27 | +substitutions_1 = [('[ \t]+', ' ')] |
| 28 | + |
| 29 | +PG_SIZE = 8192 |
| 30 | +init_script = """ |
| 31 | + create table test(s varchar(32765)); |
| 32 | + insert into test select lpad('', 32765, uuid_to_char(gen_uuid())) from rdb$types; |
| 33 | + commit; |
| 34 | +""" |
| 35 | + |
| 36 | +tmp_fbk = temp_file( filename = 'tmp_gh_6709.fbk') |
| 37 | +db = db_factory(init = init_script, charset = 'win1251', page_size = PG_SIZE) |
| 38 | + |
| 39 | +act = python_act('db') |
| 40 | + |
| 41 | +expected_stdout = "DB size did not increase after restore." |
| 42 | + |
| 43 | +@pytest.mark.version('>=4.0.3') |
| 44 | +def test_1(act: Action, tmp_fbk: Path, capsys): |
| 45 | + |
| 46 | + db_init_size = Path(act.db.db_path).stat().st_size |
| 47 | + |
| 48 | + # backup + restore without creating .fbk: |
| 49 | + # |
| 50 | + bkp_data = BytesIO() |
| 51 | + with act.connect_server() as srv: |
| 52 | + srv.database.local_backup(database = act.db.db_path, backup_stream = bkp_data) |
| 53 | + bkp_data.seek(0) |
| 54 | + srv.database.local_restore(backup_stream = bkp_data, database = act.db.db_path, flags = SrvRestoreFlag.REPLACE) |
| 55 | + |
| 56 | + db_curr_size = Path(act.db.db_path).stat().st_size |
| 57 | + if db_init_size - db_curr_size >= 0: |
| 58 | + print(expected_stdout) |
| 59 | + else: |
| 60 | + print(f'DB size increased after restore for {db_curr_size - db_init_size} bytes, from {db_init_size} to {db_curr_size}') |
| 61 | + |
| 62 | + act.expected_stdout = expected_stdout |
| 63 | + act.stdout = capsys.readouterr().out |
| 64 | + assert act.clean_stdout == act.clean_expected_stdout |
| 65 | + act.reset() |
0 commit comments