Skip to content

Commit 3c77143

Browse files
author
Jan Lindström
committed
Write size was not correctly alligned to SECT_SIZE. This lead to situation
where trim corrupted the database. Fixed the issue and added temporal guards against unalligned write/trim.
1 parent 24bc031 commit 3c77143

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

storage/innobase/fil/fil0pagecompress.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,13 @@ fil_compress_page(
188188
#endif /* UNIV_DEBUG */
189189

190190
write_size+=header_len;
191+
192+
#define SECT_SIZE 512
193+
191194
/* Actual write needs to be alligned on block size */
192-
if (write_size % OS_FILE_LOG_BLOCK_SIZE) {
193-
write_size = (write_size + (OS_FILE_LOG_BLOCK_SIZE - (write_size % OS_FILE_LOG_BLOCK_SIZE)));
195+
if (write_size % SECT_SIZE) {
196+
write_size = (write_size + SECT_SIZE-1) & ~(SECT_SIZE-1);
197+
ut_a((write_size % SECT_SIZE) == 0);
194198
}
195199

196200
#ifdef UNIV_DEBUG
@@ -199,7 +203,6 @@ fil_compress_page(
199203
space_id, fil_space_name(space), len, write_size);
200204
#endif
201205

202-
#define SECT_SIZE 512
203206

204207
srv_stats.page_compression_saved.add((len - write_size));
205208
if ((len - write_size) > 0) {

storage/innobase/os/os0file.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6151,9 +6151,10 @@ os_file_trim(
61516151

61526152
#define SECT_SIZE 512
61536153
size_t trim_len = UNIV_PAGE_SIZE - len;
6154-
// len here should be alligned to sector size
6155-
ut_a(trim_len == ((trim_len + SECT_SIZE-1) & ~(SECT_SIZE-1)));
61566154
os_offset_t off = slot->offset + len;
6155+
// len here should be alligned to sector size
6156+
ut_a((trim_len % SECT_SIZE) == 0);
6157+
ut_a((len % SECT_SIZE) == 0);
61576158

61586159
// Nothing to do if trim length is zero or if actual write
61596160
// size is initialized and it is smaller than current write size.

storage/xtradb/fil/fil0pagecompress.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,13 @@ fil_compress_page(
184184
#endif /* UNIV_DEBUG */
185185

186186
write_size+=header_len;
187+
188+
#define SECT_SIZE 512
189+
187190
/* Actual write needs to be alligned on block size */
188-
if (write_size % OS_FILE_LOG_BLOCK_SIZE) {
189-
write_size = (write_size + (OS_FILE_LOG_BLOCK_SIZE - (write_size % OS_FILE_LOG_BLOCK_SIZE)));
191+
if (write_size % SECT_SIZE) {
192+
write_size = (write_size + SECT_SIZE-1) & ~(SECT_SIZE-1);
193+
ut_a((write_size % SECT_SIZE) == 0);
190194
}
191195

192196
#ifdef UNIV_DEBUG
@@ -195,7 +199,6 @@ fil_compress_page(
195199
space_id, fil_space_name(space), len, write_size);
196200
#endif /* UNIV_DEBUG */
197201

198-
#define SECT_SIZE 512
199202

200203
srv_stats.page_compression_saved.add((len - write_size));
201204
if ((len - write_size) > 0) {

storage/xtradb/os/os0file.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6206,9 +6206,10 @@ os_file_trim(
62066206

62076207
#define SECT_SIZE 512
62086208
size_t trim_len = UNIV_PAGE_SIZE - len;
6209-
// len here should be alligned to sector size
6210-
ut_a(trim_len == ((trim_len + SECT_SIZE-1) & ~(SECT_SIZE-1)));
62116209
os_offset_t off = slot->offset + len;
6210+
// len here should be alligned to sector size
6211+
ut_a((trim_len % SECT_SIZE) == 0);
6212+
ut_a((len % SECT_SIZE) == 0);
62126213

62136214
// Nothing to do if trim length is zero or if actual write
62146215
// size is initialized and it is smaller than current write size.

0 commit comments

Comments
 (0)