@@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30
30
#include < trx0sys.h>
31
31
32
32
#include " fil_cur.h"
33
+ #include " fil0crypt.h"
33
34
#include " common.h"
34
35
#include " read_filt.h"
35
36
#include " xtrabackup.h"
@@ -231,7 +232,7 @@ xb_fil_cur_open(
231
232
232
233
posix_fadvise (cursor->file , 0 , 0 , POSIX_FADV_SEQUENTIAL);
233
234
234
- const page_size_t page_size (cursor-> node ->space ->flags );
235
+ const page_size_t page_size (node->space ->flags );
235
236
cursor->page_size = page_size;
236
237
237
238
/* Allocate read buffer */
@@ -247,6 +248,19 @@ xb_fil_cur_open(
247
248
cursor->buf_page_no = 0 ;
248
249
cursor->thread_n = thread_n;
249
250
251
+ if (!node->space ->crypt_data
252
+ && os_file_read (IORequestRead,
253
+ node->handle , cursor->buf , 0 ,
254
+ page_size.physical ())) {
255
+ mutex_enter (&fil_system->mutex );
256
+ if (!node->space ->crypt_data ) {
257
+ node->space ->crypt_data
258
+ = fil_space_read_crypt_data (page_size,
259
+ cursor->buf );
260
+ }
261
+ mutex_exit (&fil_system->mutex );
262
+ }
263
+
250
264
cursor->space_size = (ulint)(cursor->statinfo .st_size
251
265
/ page_size.physical ());
252
266
@@ -268,14 +282,15 @@ xb_fil_cur_read(
268
282
/* ============*/
269
283
xb_fil_cur_t * cursor) /* !< in/out: source file cursor */
270
284
{
271
- ibool success;
272
285
byte* page;
273
286
ulint i;
274
287
ulint npages;
275
288
ulint retry_count;
276
289
xb_fil_cur_result_t ret;
277
290
ib_int64_t offset;
278
291
ib_int64_t to_read;
292
+ byte tmp_frame[UNIV_PAGE_SIZE_MAX];
293
+ byte tmp_page[UNIV_PAGE_SIZE_MAX];
279
294
const ulint page_size = cursor->page_size .physical ();
280
295
xb_ad (!cursor->is_system () || page_size == UNIV_PAGE_SIZE);
281
296
@@ -318,6 +333,12 @@ xb_fil_cur_read(
318
333
retry_count = 10 ;
319
334
ret = XB_FIL_CUR_SUCCESS;
320
335
336
+ fil_space_t *space = fil_space_acquire_for_io (cursor->space_id );
337
+
338
+ if (!space) {
339
+ return XB_FIL_CUR_ERROR;
340
+ }
341
+
321
342
read_retry:
322
343
xtrabackup_io_throttling ();
323
344
@@ -326,19 +347,11 @@ xb_fil_cur_read(
326
347
cursor->buf_offset = offset;
327
348
cursor->buf_page_no = (ulint)(offset / cursor->page_size .physical ());
328
349
329
- FilSpace space (cursor->space_id );
330
-
331
- if (!space ()) {
332
- return (XB_FIL_CUR_ERROR);
333
- }
334
-
335
- success = os_file_read (IORequestRead,
336
- cursor->file , cursor->buf , offset,
337
- (ulint) to_read);
338
- if (!success) {
339
- return (XB_FIL_CUR_ERROR);
350
+ if (!os_file_read (IORequestRead, cursor->file , cursor->buf , offset,
351
+ (ulint) to_read)) {
352
+ ret = XB_FIL_CUR_ERROR;
353
+ goto func_exit;
340
354
}
341
-
342
355
/* check pages for corruption and re-read if necessary. i.e. in case of
343
356
partially written pages */
344
357
for (page = cursor->buf , i = 0 ; i < npages;
@@ -349,11 +362,26 @@ xb_fil_cur_read(
349
362
page_no >= FSP_EXTENT_SIZE &&
350
363
page_no < FSP_EXTENT_SIZE * 3 ) {
351
364
/* We ignore the doublewrite buffer pages */
352
- } else if (!fil_space_verify_crypt_checksum (
353
- page, cursor->page_size , space->id , page_no)
354
- && buf_page_is_corrupted (true , page,
355
- cursor->page_size ,
356
- space)) {
365
+ } else if (fil_space_verify_crypt_checksum (
366
+ page, cursor->page_size ,
367
+ space->id , page_no)) {
368
+ ut_ad (mach_read_from_4 (page + FIL_PAGE_SPACE_ID)
369
+ == space->id );
370
+
371
+ bool decrypted = false ;
372
+
373
+ memcpy (tmp_page, page, page_size);
374
+
375
+ if (!fil_space_decrypt (space, tmp_frame,
376
+ tmp_page, &decrypted)
377
+ || buf_page_is_corrupted (true , tmp_page,
378
+ cursor->page_size ,
379
+ space)) {
380
+ goto corrupted;
381
+ }
382
+ } else if (buf_page_is_corrupted (true , page, cursor->page_size ,
383
+ space)) {
384
+ corrupted:
357
385
retry_count--;
358
386
if (retry_count == 0 ) {
359
387
msg (" [%02u] mariabackup: "
@@ -373,15 +401,15 @@ xb_fil_cur_read(
373
401
}
374
402
375
403
os_thread_sleep (100000 );
376
-
377
404
goto read_retry;
378
405
}
379
406
cursor->buf_read += page_size;
380
407
cursor->buf_npages ++;
381
408
}
382
409
383
410
posix_fadvise (cursor->file , offset, to_read, POSIX_FADV_DONTNEED);
384
-
411
+ func_exit:
412
+ fil_space_release_for_io (space);
385
413
return (ret);
386
414
}
387
415
0 commit comments