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.

365 lines
12 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /******************************************************
  2. Recovery
  3. (c) 1997 Innobase Oy
  4. Created 9/20/1997 Heikki Tuuri
  5. *******************************************************/
  6. #ifndef log0recv_h
  7. #define log0recv_h
  8. #include "univ.i"
  9. #include "ut0byte.h"
  10. #include "buf0types.h"
  11. #include "hash0hash.h"
  12. #include "log0log.h"
  13. #ifdef UNIV_HOTBACKUP
  14. extern ibool recv_replay_file_ops;
  15. #endif /* UNIV_HOTBACKUP */
  16. /***********************************************************************
  17. Reads the checkpoint info needed in hot backup. */
  18. ibool
  19. recv_read_cp_info_for_backup(
  20. /*=========================*/
  21. /* out: TRUE if success */
  22. byte* hdr, /* in: buffer containing the log group
  23. header */
  24. ib_uint64_t* lsn, /* out: checkpoint lsn */
  25. ulint* offset, /* out: checkpoint offset in the log group */
  26. ulint* fsp_limit,/* out: fsp limit of space 0,
  27. 1000000000 if the database is running
  28. with < version 3.23.50 of InnoDB */
  29. ib_uint64_t* cp_no, /* out: checkpoint number */
  30. ib_uint64_t* first_header_lsn);
  31. /* out: lsn of of the start of the
  32. first log file */
  33. /***********************************************************************
  34. Scans the log segment and n_bytes_scanned is set to the length of valid
  35. log scanned. */
  36. void
  37. recv_scan_log_seg_for_backup(
  38. /*=========================*/
  39. byte* buf, /* in: buffer containing log data */
  40. ulint buf_len, /* in: data length in that buffer */
  41. ib_uint64_t* scanned_lsn, /* in/out: lsn of buffer start,
  42. we return scanned lsn */
  43. ulint* scanned_checkpoint_no,
  44. /* in/out: 4 lowest bytes of the
  45. highest scanned checkpoint number so
  46. far */
  47. ulint* n_bytes_scanned);/* out: how much we were able to
  48. scan, smaller than buf_len if log
  49. data ended here */
  50. /***********************************************************************
  51. Returns TRUE if recovery is currently running. */
  52. UNIV_INLINE
  53. ibool
  54. recv_recovery_is_on(void);
  55. /*=====================*/
  56. /***********************************************************************
  57. Returns TRUE if recovery from backup is currently running. */
  58. UNIV_INLINE
  59. ibool
  60. recv_recovery_from_backup_is_on(void);
  61. /*=================================*/
  62. /****************************************************************************
  63. Applies the hashed log records to the page, if the page lsn is less than the
  64. lsn of a log record. This can be called when a buffer page has just been
  65. read in, or also for a page already in the buffer pool. */
  66. void
  67. recv_recover_page(
  68. /*==============*/
  69. ibool recover_backup,
  70. /* in: TRUE if we are recovering a backup
  71. page: then we do not acquire any latches
  72. since the page was read in outside the
  73. buffer pool */
  74. ibool just_read_in,
  75. /* in: TRUE if the i/o-handler calls this for
  76. a freshly read page */
  77. buf_block_t* block); /* in: buffer block */
  78. /************************************************************
  79. Recovers from a checkpoint. When this function returns, the database is able
  80. to start processing of new user transactions, but the function
  81. recv_recovery_from_checkpoint_finish should be called later to complete
  82. the recovery and free the resources used in it. */
  83. ulint
  84. recv_recovery_from_checkpoint_start(
  85. /*================================*/
  86. /* out: error code or DB_SUCCESS */
  87. ulint type, /* in: LOG_CHECKPOINT or LOG_ARCHIVE */
  88. ib_uint64_t limit_lsn, /* in: recover up to this lsn
  89. if possible */
  90. ib_uint64_t min_flushed_lsn,/* in: min flushed lsn from
  91. data files */
  92. ib_uint64_t max_flushed_lsn);/* in: max flushed lsn from
  93. data files */
  94. /************************************************************
  95. Completes recovery from a checkpoint. */
  96. void
  97. recv_recovery_from_checkpoint_finish(void);
  98. /*======================================*/
  99. /***********************************************************
  100. Scans log from a buffer and stores new log data to the parsing buffer. Parses
  101. and hashes the log records if new data found. */
  102. ibool
  103. recv_scan_log_recs(
  104. /*===============*/
  105. /* out: TRUE if limit_lsn has been
  106. reached, or not able to scan any more
  107. in this log group */
  108. ibool apply_automatically,/* in: TRUE if we want this
  109. function to apply log records
  110. automatically when the hash table
  111. becomes full; in the hot backup tool
  112. the tool does the applying, not this
  113. function */
  114. ulint available_memory,/* in: we let the hash table of recs
  115. to grow to this size, at the maximum */
  116. ibool store_to_hash, /* in: TRUE if the records should be
  117. stored to the hash table; this is set
  118. to FALSE if just debug checking is
  119. needed */
  120. byte* buf, /* in: buffer containing a log segment
  121. or garbage */
  122. ulint len, /* in: buffer length */
  123. ib_uint64_t start_lsn, /* in: buffer start lsn */
  124. ib_uint64_t* contiguous_lsn, /* in/out: it is known that all log
  125. groups contain contiguous log data up
  126. to this lsn */
  127. ib_uint64_t* group_scanned_lsn);/* out: scanning succeeded up to
  128. this lsn */
  129. /**********************************************************
  130. Resets the logs. The contents of log files will be lost! */
  131. void
  132. recv_reset_logs(
  133. /*============*/
  134. ib_uint64_t lsn, /* in: reset to this lsn
  135. rounded up to be divisible by
  136. OS_FILE_LOG_BLOCK_SIZE, after
  137. which we add
  138. LOG_BLOCK_HDR_SIZE */
  139. #ifdef UNIV_LOG_ARCHIVE
  140. ulint arch_log_no, /* in: next archived log file number */
  141. #endif /* UNIV_LOG_ARCHIVE */
  142. ibool new_logs_created);/* in: TRUE if resetting logs
  143. is done at the log creation;
  144. FALSE if it is done after
  145. archive recovery */
  146. #ifdef UNIV_HOTBACKUP
  147. /**********************************************************
  148. Creates new log files after a backup has been restored. */
  149. void
  150. recv_reset_log_files_for_backup(
  151. /*============================*/
  152. const char* log_dir, /* in: log file directory path */
  153. ulint n_log_files, /* in: number of log files */
  154. ulint log_file_size, /* in: log file size */
  155. ib_uint64_t lsn); /* in: new start lsn, must be
  156. divisible by OS_FILE_LOG_BLOCK_SIZE */
  157. #endif /* UNIV_HOTBACKUP */
  158. /************************************************************
  159. Creates the recovery system. */
  160. void
  161. recv_sys_create(void);
  162. /*=================*/
  163. /************************************************************
  164. Inits the recovery system for a recovery operation. */
  165. void
  166. recv_sys_init(
  167. /*==========*/
  168. ibool recover_from_backup, /* in: TRUE if this is called
  169. to recover from a hot backup */
  170. ulint available_memory); /* in: available memory in bytes */
  171. /***********************************************************************
  172. Empties the hash table of stored log records, applying them to appropriate
  173. pages. */
  174. void
  175. recv_apply_hashed_log_recs(
  176. /*=======================*/
  177. ibool allow_ibuf); /* in: if TRUE, also ibuf operations are
  178. allowed during the application; if FALSE,
  179. no ibuf operations are allowed, and after
  180. the application all file pages are flushed to
  181. disk and invalidated in buffer pool: this
  182. alternative means that no new log records
  183. can be generated during the application */
  184. #ifdef UNIV_HOTBACKUP
  185. /***********************************************************************
  186. Applies log records in the hash table to a backup. */
  187. void
  188. recv_apply_log_recs_for_backup(void);
  189. /*================================*/
  190. #endif
  191. #ifdef UNIV_LOG_ARCHIVE
  192. /************************************************************
  193. Recovers from archived log files, and also from log files, if they exist. */
  194. ulint
  195. recv_recovery_from_archive_start(
  196. /*=============================*/
  197. /* out: error code or DB_SUCCESS */
  198. ib_uint64_t min_flushed_lsn,/* in: min flushed lsn field from the
  199. data files */
  200. ib_uint64_t limit_lsn, /* in: recover up to this lsn if
  201. possible */
  202. ulint first_log_no); /* in: number of the first archived
  203. log file to use in the recovery; the
  204. file will be searched from
  205. INNOBASE_LOG_ARCH_DIR specified in
  206. server config file */
  207. /************************************************************
  208. Completes recovery from archive. */
  209. void
  210. recv_recovery_from_archive_finish(void);
  211. /*===================================*/
  212. #endif /* UNIV_LOG_ARCHIVE */
  213. /* Block of log record data */
  214. typedef struct recv_data_struct recv_data_t;
  215. struct recv_data_struct{
  216. recv_data_t* next; /* pointer to the next block or NULL */
  217. /* the log record data is stored physically
  218. immediately after this struct, max amount
  219. RECV_DATA_BLOCK_SIZE bytes of it */
  220. };
  221. /* Stored log record struct */
  222. typedef struct recv_struct recv_t;
  223. struct recv_struct{
  224. byte type; /* log record type */
  225. ulint len; /* log record body length in bytes */
  226. recv_data_t* data; /* chain of blocks containing the log record
  227. body */
  228. ib_uint64_t start_lsn;/* start lsn of the log segment written by
  229. the mtr which generated this log record: NOTE
  230. that this is not necessarily the start lsn of
  231. this log record */
  232. ib_uint64_t end_lsn;/* end lsn of the log segment written by
  233. the mtr which generated this log record: NOTE
  234. that this is not necessarily the end lsn of
  235. this log record */
  236. UT_LIST_NODE_T(recv_t)
  237. rec_list;/* list of log records for this page */
  238. };
  239. /* Hashed page file address struct */
  240. typedef struct recv_addr_struct recv_addr_t;
  241. struct recv_addr_struct{
  242. ulint state; /* RECV_NOT_PROCESSED, RECV_BEING_PROCESSED,
  243. or RECV_PROCESSED */
  244. ulint space; /* space id */
  245. ulint page_no;/* page number */
  246. UT_LIST_BASE_NODE_T(recv_t)
  247. rec_list;/* list of log records for this page */
  248. hash_node_t addr_hash;
  249. };
  250. /* Recovery system data structure */
  251. typedef struct recv_sys_struct recv_sys_t;
  252. struct recv_sys_struct{
  253. mutex_t mutex; /* mutex protecting the fields apply_log_recs,
  254. n_addrs, and the state field in each recv_addr
  255. struct */
  256. ibool apply_log_recs;
  257. /* this is TRUE when log rec application to
  258. pages is allowed; this flag tells the
  259. i/o-handler if it should do log record
  260. application */
  261. ibool apply_batch_on;
  262. /* this is TRUE when a log rec application
  263. batch is running */
  264. ib_uint64_t lsn; /* log sequence number */
  265. ulint last_log_buf_size;
  266. /* size of the log buffer when the database
  267. last time wrote to the log */
  268. byte* last_block;
  269. /* possible incomplete last recovered log
  270. block */
  271. byte* last_block_buf_start;
  272. /* the nonaligned start address of the
  273. preceding buffer */
  274. byte* buf; /* buffer for parsing log records */
  275. ulint len; /* amount of data in buf */
  276. ib_uint64_t parse_start_lsn;
  277. /* this is the lsn from which we were able to
  278. start parsing log records and adding them to
  279. the hash table; zero if a suitable
  280. start point not found yet */
  281. ib_uint64_t scanned_lsn;
  282. /* the log data has been scanned up to this
  283. lsn */
  284. ulint scanned_checkpoint_no;
  285. /* the log data has been scanned up to this
  286. checkpoint number (lowest 4 bytes) */
  287. ulint recovered_offset;
  288. /* start offset of non-parsed log records in
  289. buf */
  290. ib_uint64_t recovered_lsn;
  291. /* the log records have been parsed up to
  292. this lsn */
  293. ib_uint64_t limit_lsn;/* recovery should be made at most up to this
  294. lsn */
  295. ibool found_corrupt_log;
  296. /* this is set to TRUE if we during log
  297. scan find a corrupt log block, or a corrupt
  298. log record, or there is a log parsing
  299. buffer overflow */
  300. log_group_t* archive_group;
  301. /* in archive recovery: the log group whose
  302. archive is read */
  303. mem_heap_t* heap; /* memory heap of log records and file
  304. addresses*/
  305. hash_table_t* addr_hash;/* hash table of file addresses of pages */
  306. ulint n_addrs;/* number of not processed hashed file
  307. addresses in the hash table */
  308. };
  309. extern recv_sys_t* recv_sys;
  310. extern ibool recv_recovery_on;
  311. extern ibool recv_no_ibuf_operations;
  312. extern ibool recv_needed_recovery;
  313. extern ibool recv_lsn_checks_on;
  314. #ifdef UNIV_HOTBACKUP
  315. extern ibool recv_is_making_a_backup;
  316. #endif /* UNIV_HOTBACKUP */
  317. extern ulint recv_max_parsed_page_no;
  318. /* Size of the parsing buffer; it must accommodate RECV_SCAN_SIZE many
  319. times! */
  320. #define RECV_PARSING_BUF_SIZE (2 * 1024 * 1024)
  321. /* Size of block reads when the log groups are scanned forward to do a
  322. roll-forward */
  323. #define RECV_SCAN_SIZE (4 * UNIV_PAGE_SIZE)
  324. /* States of recv_addr_struct */
  325. #define RECV_NOT_PROCESSED 71
  326. #define RECV_BEING_READ 72
  327. #define RECV_BEING_PROCESSED 73
  328. #define RECV_PROCESSED 74
  329. extern ulint recv_n_pool_free_frames;
  330. #ifndef UNIV_NONINL
  331. #include "log0recv.ic"
  332. #endif
  333. #endif