You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
7.1 KiB

MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-19229 Allow innodb_undo_tablespaces to be changed after database creation trx_sys_t::undo_log_nonempty: Set to true if there are undo logs to rollback and purge. The algorithm for re-creating the undo tablespace when trx_sys_t::undo_log_nonempty is disabled: 1) trx_sys_t::reset_page(): Reset the TRX_SYS page and assign all rollback segment slots from 1..127 to FIL_NULL 2) Free the rollback segment header page of system tablespace for the slots 1..127 3) Update the binlog and WSREP information in system tablespace rollback segment header Step (1), (2) and Step (3) should happen atomically within a single mini-transaction. 4) srv_undo_delete_old_tablespaces(): Delete the old undo tablespaces present in the undo log directory 5) Make checkpoint to get rid of old undo log tablespaces redo logs 6) Assign new start space id for the undo log tablespaces 7) Re-create the specified undo log tablespaces. InnoDB uses same mtr for this one and step (6) 8) Make checkpoint again, so that server or mariabackup can read the undo log tablespace page0 before applying the redo logs srv_undo_tablespaces_reinit(): Recreate the undo log tablespaces. It does reset trx_sys page, delete the old undo tablespaces, update the binlog offset, write set replication checkpoint in system rollback segment page trx_rseg_update_binlog_offset(): Added 2 new parameters to pass binlog file name and binlog offset trx_rseg_array_init(): Return error if the rollback segment slot points to non-existent tablespace srv_undo_tablespaces_init(): Added new parameter mtr to initialize all undo tablespaces trx_assign_rseg_low(): Allow the transaction to use the rollback segment slots(1..127) even if InnoDB failed to change to the requested innodb_undo_tablespaces=0 srv_start(): Override the user specified value of innodb_undo_tablespaces variable with already existing actual undo tablespaces wf_incremental_process(): Detects whether TRX_SYS page has been modified since last backup. If it is then incremental backup fails and throws the information about taking full backup again xb_assign_undo_space_start(): Removed the function. Because undo001 has first undo space id value in page0 Added test case to test the scenario during startup and mariabackup incremental process too. Reviewed-by : Marko Mäkelä Tested-by : Matthias Leich
3 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
MDEV-22929 MariaBackup option to report and/or continue when corruption is encountered The new option --log-innodb-page-corruption is introduced. When this option is set, backup is not interrupted if innodb corrupted page is detected. Instead it logs all found corrupted pages in innodb_corrupted_pages file in backup directory and finishes with error. For incremental backup corrupted pages are also copied to .delta file, because we can't do LSN check for such pages during backup, innodb_corrupted_pages will also be created in incremental backup directory. During --prepare, corrupted pages list is read from the file just after redo log is applied, and each page from the list is checked if it is allocated in it's tablespace or not. If it is not allocated, then it is zeroed out, flushed to the tablespace and removed from the list. If all pages are removed from the list, then --prepare is finished successfully and innodb_corrupted_pages file is removed from backup directory. Otherwise --prepare is finished with error message and innodb_corrupted_pages contains the list of the pages, which are detected as corrupted during backup, and are allocated in their tablespaces, what means backup directory contains corrupted innodb pages, and backup can not be considered as consistent. For incremental --prepare corrupted pages from .delta files are applied to the base backup, innodb_corrupted_pages is read from both base in incremental directories, and the same action is proceded for corrupted pages list as for full --prepare. innodb_corrupted_pages file is modified or removed only in base directory. If DDL happens during backup, it is also processed at the end of backup to have correct tablespace names in innodb_corrupted_pages.
5 years ago
  1. /******************************************************
  2. MariaBackup: hot backup tool for InnoDB
  3. (c) 2009-2013 Percona LLC and/or its affiliates.
  4. Originally Created 3/3/2009 Yasufumi Kinoshita
  5. Written by Alexey Kopytov, Aleksandr Kuzminsky, Stewart Smith, Vadim Tkachenko,
  6. Yasufumi Kinoshita, Ignacio Nin and Baron Schwartz.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; version 2 of the License.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
  17. *******************************************************/
  18. /* Page write filters implementation */
  19. #include <my_global.h>
  20. #include <my_base.h>
  21. #include "common.h"
  22. #include "write_filt.h"
  23. #include "fil_cur.h"
  24. #include "xtrabackup.h"
  25. /************************************************************************
  26. Write-through page write filter. */
  27. static my_bool wf_wt_init(ds_ctxt *ds_meta,
  28. xb_write_filt_ctxt_t *ctxt, char *dst_name,
  29. xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages);
  30. static my_bool wf_wt_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile);
  31. xb_write_filt_t wf_write_through = {
  32. &wf_wt_init,
  33. &wf_wt_process,
  34. NULL,
  35. NULL
  36. };
  37. /************************************************************************
  38. Incremental page write filter. */
  39. static my_bool wf_incremental_init(ds_ctxt *ds_meta,
  40. xb_write_filt_ctxt_t *ctxt, char *dst_name,
  41. xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages);
  42. static my_bool wf_incremental_process(xb_write_filt_ctxt_t *ctxt,
  43. ds_file_t *dstfile);
  44. static my_bool wf_incremental_finalize(xb_write_filt_ctxt_t *ctxt,
  45. ds_file_t *dstfile);
  46. static void wf_incremental_deinit(xb_write_filt_ctxt_t *ctxt);
  47. xb_write_filt_t wf_incremental = {
  48. &wf_incremental_init,
  49. &wf_incremental_process,
  50. &wf_incremental_finalize,
  51. &wf_incremental_deinit
  52. };
  53. /************************************************************************
  54. Initialize incremental page write filter.
  55. @return TRUE on success, FALSE on error. */
  56. static my_bool
  57. wf_incremental_init(ds_ctxt *ds_meta,
  58. xb_write_filt_ctxt_t *ctxt, char *dst_name,
  59. xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages)
  60. {
  61. char meta_name[FN_REFLEN];
  62. xb_wf_incremental_ctxt_t *cp =
  63. &(ctxt->wf_incremental_ctxt);
  64. ctxt->cursor = cursor;
  65. /* allocate buffer for incremental backup (4096 pages) */
  66. cp->delta_buf_size = (cursor->page_size / 4) * cursor->page_size;
  67. cp->delta_buf = (unsigned char *)my_large_malloc(&cp->delta_buf_size, MYF(0));
  68. if (!cp->delta_buf) {
  69. msg(cursor->thread_n,"Can't allocate %zu bytes",
  70. (size_t) cp->delta_buf_size);
  71. return (FALSE);
  72. }
  73. /* write delta meta info */
  74. snprintf(meta_name, sizeof(meta_name), "%s%s", dst_name,
  75. XB_DELTA_INFO_SUFFIX);
  76. const xb_delta_info_t info(cursor->page_size, cursor->zip_size,
  77. cursor->space_id);
  78. if (!xb_write_delta_metadata(ds_meta, meta_name, &info)) {
  79. msg(cursor->thread_n,"Error: "
  80. "failed to write meta info for %s",
  81. cursor->rel_path);
  82. return(FALSE);
  83. }
  84. /* change the target file name, since we are only going to write
  85. delta pages */
  86. strcat(dst_name, ".delta");
  87. mach_write_to_4(cp->delta_buf, 0x78747261UL); /*"xtra"*/
  88. cp->npages = 1;
  89. cp->corrupted_pages = corrupted_pages;
  90. return(TRUE);
  91. }
  92. /************************************************************************
  93. Run the next batch of pages through incremental page write filter.
  94. @return TRUE on success, FALSE on error. */
  95. static my_bool
  96. wf_incremental_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile)
  97. {
  98. unsigned i;
  99. xb_fil_cur_t *cursor = ctxt->cursor;
  100. byte *page;
  101. const ulint page_size = cursor->page_size;
  102. xb_wf_incremental_ctxt_t *cp = &(ctxt->wf_incremental_ctxt);
  103. for (i = 0, page = cursor->buf; i < cursor->buf_npages;
  104. i++, page += page_size) {
  105. if ((!cp->corrupted_pages ||
  106. !cp->corrupted_pages->contains({cursor->node->space->id,
  107. cursor->buf_page_no + i})) &&
  108. incremental_lsn >= mach_read_from_8(page + FIL_PAGE_LSN))
  109. continue;
  110. /* Check whether TRX_SYS page has been changed */
  111. if (mach_read_from_4(page + FIL_PAGE_SPACE_ID)
  112. == TRX_SYS_SPACE
  113. && mach_read_from_4(page + FIL_PAGE_OFFSET)
  114. == TRX_SYS_PAGE_NO) {
  115. msg(cursor->thread_n,
  116. "--incremental backup is impossible if "
  117. "the server had been restarted with "
  118. "different innodb_undo_tablespaces.");
  119. return false;
  120. }
  121. /* updated page */
  122. if (cp->npages == page_size / 4) {
  123. /* flush buffer */
  124. if (ds_write(dstfile, cp->delta_buf,
  125. cp->npages * page_size)) {
  126. return(FALSE);
  127. }
  128. /* clear buffer */
  129. memset(cp->delta_buf, 0, page_size / 4 * page_size);
  130. /*"xtra"*/
  131. mach_write_to_4(cp->delta_buf, 0x78747261UL);
  132. cp->npages = 1;
  133. }
  134. mach_write_to_4(cp->delta_buf + cp->npages * 4,
  135. cursor->buf_page_no + i);
  136. memcpy(cp->delta_buf + cp->npages * page_size, page,
  137. page_size);
  138. cp->npages++;
  139. }
  140. return(TRUE);
  141. }
  142. /************************************************************************
  143. Flush the incremental page write filter's buffer.
  144. @return TRUE on success, FALSE on error. */
  145. static my_bool
  146. wf_incremental_finalize(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile)
  147. {
  148. xb_fil_cur_t *cursor = ctxt->cursor;
  149. const ulint page_size = cursor->page_size;
  150. xb_wf_incremental_ctxt_t *cp = &(ctxt->wf_incremental_ctxt);
  151. if (cp->npages != page_size / 4) {
  152. mach_write_to_4(cp->delta_buf + cp->npages * 4, 0xFFFFFFFFUL);
  153. }
  154. /* Mark the final block */
  155. mach_write_to_4(cp->delta_buf, 0x58545241UL); /*"XTRA"*/
  156. /* flush buffer */
  157. if (ds_write(dstfile, cp->delta_buf, cp->npages * page_size)) {
  158. return(FALSE);
  159. }
  160. return(TRUE);
  161. }
  162. /************************************************************************
  163. Free the incremental page write filter's buffer. */
  164. static void
  165. wf_incremental_deinit(xb_write_filt_ctxt_t *ctxt)
  166. {
  167. xb_wf_incremental_ctxt_t *cp = &(ctxt->wf_incremental_ctxt);
  168. my_large_free(cp->delta_buf, cp->delta_buf_size);
  169. }
  170. /************************************************************************
  171. Initialize the write-through page write filter.
  172. @return TRUE on success, FALSE on error. */
  173. static my_bool
  174. wf_wt_init(ds_ctxt *ds_meta __attribute__((unused)),
  175. xb_write_filt_ctxt_t *ctxt, char *dst_name __attribute__((unused)),
  176. xb_fil_cur_t *cursor, CorruptedPages *)
  177. {
  178. ctxt->cursor = cursor;
  179. return(TRUE);
  180. }
  181. /************************************************************************
  182. Write the next batch of pages to the destination datasink.
  183. @return TRUE on success, FALSE on error. */
  184. static my_bool
  185. wf_wt_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile)
  186. {
  187. xb_fil_cur_t *cursor = ctxt->cursor;
  188. if (ds_write(dstfile, cursor->buf, cursor->buf_read)) {
  189. return(FALSE);
  190. }
  191. return(TRUE);
  192. }