Commit 8f392cb
committed
PXB-3747 : Report uncompressed_backup_size for --compress backups
https://perconadev.atlassian.net/browse/PXB-3747
Problem
-------
For --compress backups, backup_size is the compressed size (it comes
from the leaf). Operators also need the logical, pre-compression size
to answer "how much real data did this backup represent?" and to derive
the effective compression ratio from a single xtrabackup_info record.
Design
------
Why two data pipelines exist
xtrabackup maintains two top-level data pipelines on the backup side
because not every file benefits from compression:
* ds_data -- normal InnoDB tablespaces, redo, metadata.
Compressed when --compress is on.
* ds_uncompressed_data -- server-encrypted InnoDB tablespaces
("do not compress encrypted tablespaces",
xtrabackup.cc) and RocksDB SST files
(already compressed internally). Bypasses
the compress wrapper because ciphertext and
pre-compressed content are incompressible,
so the CPU cost buys nothing.
Both pipelines share their encrypt / xbstream / leaf tail as an
init-time ctxt-sharing optimization:
ds_data --> compress --> encrypt --> xbstream --> leaf
^
|
ds_uncompressed_data -----------------> encrypt --> xbstream ----+
Why the counter cannot live on any ctxt
That shared tail makes "attach a counter to the ctxt" broken no matter
which ctxt is picked:
* Leaf ctxt: in xbstream mode ds_data, ds_redo, ds_meta, and
ds_uncompressed_data all terminate at the same leaf. A leaf-ctxt
counter would sum bytes from every pipeline, and for the
compressed pipeline those bytes are post-compression -- neither
the logical total nor the on-disk total.
* Encrypt / xbstream / buffer ctxts: ds_data and ds_uncompressed_data
share these too. Counting there mixes post-compression bytes
(from ds_data) with raw bytes (from ds_uncompressed_data); the
sum is meaningless.
The counter must attach where a single logical write unambiguously
enters exactly one pipeline -- on the per-file handle returned by the
top-level ds_open(). Each top-level open creates a fresh ds_file_t,
the caller decides whether that file's bytes count, and
ds_write / ds_write_sparse bump the counter with the length supplied
at the entry, before any wrapper transforms it:
xtrabackup top-level open
| ds_tracked_open(..., xb_get_metrics())
| |
| +-- nullptr when !--compress (no cost)
v
ds_file_t { metrics -> xb_backup_metrics }
| ds_write(len) / ds_write_sparse(packed_len)
| if (file->metrics) metrics->add_uncomp_size(len)
v
[ compress / encrypt / buffer / xbstream wrappers ]
|
v
leaf (already counted as backup_size by the previous commit)
xb_backup_metrics.get_uncomp_size()
|
v
uncompressed_backup_size (xtrabackup_info + error log)
Because arming is opt-in and scoped to the top-level opens on
ds_data / ds_redo / ds_meta / ds_uncompressed_data, the hot-path cost
is one atomic add per write on --compress runs; non-compress runs skip
even that. The same xb_backup_metrics aggregates both pipelines, so
server-encrypted IBDs and RocksDB SSTs are counted exactly once, at
their logical size.
Arming is driven by xb_get_metrics(), which returns a real counter
only when --compress is active, so non-compress runs emit neither the
field nor the log line.
Tests
-----
t/backup_size_compress.sh covers --compress target-dir, --compress
xbstream, --compress + --encrypt, incremental chains, RocksDB,
server-encrypted InnoDB, redo-log encryption, and sparse files. Every
scenario asserts backup_size matches the compressed on-disk size and,
after decompression, uncompressed_backup_size matches the decompressed
tree size byte-for-byte.1 parent 70a001d commit 8f392cb
24 files changed
Lines changed: 712 additions & 189 deletions
File tree
- storage/innobase/xtrabackup
- src
- test/t
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
380 | | - | |
| 381 | + | |
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
| |||
576 | 577 | | |
577 | 578 | | |
578 | 579 | | |
579 | | - | |
| 580 | + | |
| 581 | + | |
580 | 582 | | |
581 | 583 | | |
582 | 584 | | |
| |||
1594 | 1596 | | |
1595 | 1597 | | |
1596 | 1598 | | |
1597 | | - | |
1598 | | - | |
1599 | | - | |
1600 | | - | |
1601 | 1599 | | |
1602 | 1600 | | |
1603 | 1601 | | |
| |||
1671 | 1669 | | |
1672 | 1670 | | |
1673 | 1671 | | |
1674 | | - | |
1675 | | - | |
| 1672 | + | |
| 1673 | + | |
1676 | 1674 | | |
1677 | 1675 | | |
1678 | 1676 | | |
1679 | 1677 | | |
1680 | 1678 | | |
1681 | 1679 | | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
1682 | 1702 | | |
1683 | 1703 | | |
1684 | 1704 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
630 | | - | |
631 | 630 | | |
632 | 631 | | |
633 | 632 | | |
| |||
1849 | 1848 | | |
1850 | 1849 | | |
1851 | 1850 | | |
1852 | | - | |
1853 | | - | |
1854 | | - | |
1855 | | - | |
1856 | | - | |
1857 | | - | |
| 1851 | + | |
1858 | 1852 | | |
1859 | 1853 | | |
1860 | 1854 | | |
| |||
1910 | 1904 | | |
1911 | 1905 | | |
1912 | 1906 | | |
1913 | | - | |
| 1907 | + | |
1914 | 1908 | | |
1915 | 1909 | | |
1916 | 1910 | | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
1917 | 1927 | | |
1918 | 1928 | | |
1919 | 1929 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
40 | | - | |
41 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
42 | 54 | | |
43 | 55 | | |
44 | 56 | | |
| |||
95 | 107 | | |
96 | 108 | | |
97 | 109 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 110 | + | |
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
| |||
110 | 116 | | |
111 | 117 | | |
112 | 118 | | |
113 | | - | |
114 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
115 | 129 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
122 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
123 | 147 | | |
124 | 148 | | |
125 | 149 | | |
126 | | - | |
127 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
128 | 155 | | |
129 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
130 | 160 | | |
131 | 161 | | |
132 | 162 | | |
133 | | - | |
134 | | - | |
135 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
136 | 166 | | |
137 | 167 | | |
138 | 168 | | |
139 | 169 | | |
140 | 170 | | |
141 | 171 | | |
142 | 172 | | |
143 | | - | |
144 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
145 | 183 | | |
146 | 184 | | |
147 | 185 | | |
148 | 186 | | |
149 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
150 | 196 | | |
151 | 197 | | |
152 | 198 | | |
153 | 199 | | |
154 | 200 | | |
155 | 201 | | |
156 | | - | |
157 | | - | |
158 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
159 | 205 | | |
160 | 206 | | |
161 | | - | |
162 | | - | |
| 207 | + | |
| 208 | + | |
163 | 209 | | |
164 | 210 | | |
165 | | - | |
166 | | - | |
167 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
168 | 214 | | |
169 | 215 | | |
170 | 216 | | |
| |||
0 commit comments