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