MySQL  8.0.18
Source Code Documentation
arch0arch.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2017, 2019, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/arch0arch.h
28  Common interface for redo log and dirty page archiver system
29 
30  *******************************************************/
31 
32 #ifndef ARCH_ARCH_INCLUDE
33 #define ARCH_ARCH_INCLUDE
34 
36 #include "log0log.h"
37 #include "ut0mutex.h"
38 
39 #include <list>
40 
41 /** @name Archive file name prefix and constant length parameters. */
42 /* @{ */
43 /** Archive directory prefix */
44 const char ARCH_DIR[] = OS_FILE_PREFIX "ib_archive";
45 
46 /** Archive Log group directory prefix */
47 const char ARCH_LOG_DIR[] = "log_group_";
48 
49 /** Archive Page group directory prefix */
50 const char ARCH_PAGE_DIR[] = "page_group_";
51 
52 /** Archive log file prefix */
53 const char ARCH_LOG_FILE[] = "ib_log_";
54 
55 /** Archive page file prefix */
56 const char ARCH_PAGE_FILE[] = "ib_page_";
57 
58 /** //@} */
59 
60 /** File name for the durable file which indicates whether a group was made
61 durable or not. Required to differentiate durable group from group left over by
62 crash during clone operation. */
63 constexpr char ARCH_PAGE_GROUP_DURABLE_FILE_NAME[] = "durable";
64 
65 /** Byte length for printing LSN.
66 Each archive group name is appended with start LSN */
68 
69 /** Max string length for archive log file name */
71  sizeof(ARCH_DIR) + 1 + sizeof(ARCH_LOG_DIR) + MAX_LSN_DECIMAL_DIGIT + 1 +
73 
74 /** Max string length for archive page file name */
76  sizeof(ARCH_DIR) + 1 + sizeof(ARCH_PAGE_DIR) + MAX_LSN_DECIMAL_DIGIT + 1 +
78 
79 /** Max string length for archive group directory name */
81  sizeof(ARCH_DIR) + 1 + sizeof(ARCH_PAGE_DIR) + MAX_LSN_DECIMAL_DIGIT + 1;
82 
83 /** Log archiver background thread */
84 void log_archiver_thread();
85 
86 /** Archiver thread event to signal that data is available */
88 
89 /** Memory block size */
90 constexpr uint ARCH_PAGE_BLK_SIZE = UNIV_PAGE_SIZE_DEF;
91 
92 /** Archiver client state.
93 Archiver clients request archiving for specific interval using
94 the start and stop interfaces. During this time the client is
95 attached to global Archiver system. A client copies archived
96 data for the interval after calling stop. System keeps the data
97 till the time client object is destroyed.
98 
99 @startuml
100 
101  state ARCH_CLIENT_STATE_INIT
102  state ARCH_CLIENT_STATE_STARTED
103  state ARCH_CLIENT_STATE_STOPPED
104 
105  [*] -down-> ARCH_CLIENT_STATE_INIT
106  ARCH_CLIENT_STATE_INIT -down-> ARCH_CLIENT_STATE_STARTED : Attach and start \
107  archiving
108  ARCH_CLIENT_STATE_STARTED -right-> ARCH_CLIENT_STATE_STOPPED : Stop \
109  archiving
110  ARCH_CLIENT_STATE_STOPPED -down-> [*] : Detach client
111 
112 @enduml */
114  /** Client is initialized */
116 
117  /** Archiving started by client */
119 
120  /** Archiving stopped by client */
122 };
123 
124 /** Remove files related to page and log archiving.
125 @param[in] file_path path to the file
126 @param[in] file_name name of the file */
127 void arch_remove_file(const char *file_path, const char *file_name);
128 
129 /** Remove group directory and the files related to page and log archiving.
130 @param[in] dir_path path to the directory
131 @param[in] dir_name directory name */
132 void arch_remove_dir(const char *dir_path, const char *dir_name);
133 
134 /** Archiver system state.
135 Archiver state changes are triggered by client request to start or
136 stop archiving and system wide events like shutdown fatal error etc.
137 Following diagram shows the state transfer.
138 
139 @startuml
140 
141  state ARCH_STATE_INIT
142  state ARCH_STATE_ACTIVE
143  state ARCH_STATE_PREPARE_IDLE
144  state ARCH_STATE_IDLE
145  state ARCH_STATE_ABORT
146 
147  [*] -down-> ARCH_STATE_INIT
148  ARCH_STATE_INIT -down-> ARCH_STATE_ACTIVE : Start archiving
149  ARCH_STATE_ACTIVE -right-> ARCH_STATE_PREPARE_IDLE : Stop archiving
150  ARCH_STATE_PREPARE_IDLE -right-> ARCH_STATE_IDLE : All data archived
151  ARCH_STATE_IDLE -down-> ARCH_STATE_ABORT : Shutdown or Fatal Error
152  ARCH_STATE_PREPARE_IDLE --> ARCH_STATE_ACTIVE : Resume archiving
153  ARCH_STATE_IDLE --> ARCH_STATE_ACTIVE : Start archiving
154  ARCH_STATE_ABORT -down-> [*]
155 
156 @enduml */
158  /** Archiver is initialized */
160 
161  /** Archiver is active and archiving data */
163 
164  /** Archiver is processing last data chunks before idle state */
166 
167  /** Archiver is idle */
169 
170  /** Archiver is aborted */
172 };
173 
174 /** Archived data block state.
175 A data block is a block in memory that holds dirty page IDs before persisting
176 into disk. Shown below is the state transfer diagram for a data block.
177 
178 @startuml
179 
180  state ARCH_BLOCK_INIT
181  state ARCH_BLOCK_ACTIVE
182  state ARCH_BLOCK_READY_TO_FLUSH
183  state ARCH_BLOCK_FLUSHED
184 
185  [*] -down-> ARCH_BLOCK_INIT
186  ARCH_BLOCK_INIT -> ARCH_BLOCK_ACTIVE : Writing page ID
187  ARCH_BLOCK_ACTIVE -> ARCH_BLOCK_READY_TO_FLUSH : Block is full
188  ARCH_BLOCK_READY_TO_FLUSH -> ARCH_BLOCK_FLUSHED : Block is flushed
189  ARCH_BLOCK_FLUSHED --> ARCH_BLOCK_ACTIVE : Writing page ID
190  ARCH_BLOCK_FLUSHED -down-> [*]
191 
192 @enduml */
194  /** Data block is initialized */
196 
197  /** Data block is active and having data */
199 
200  /** Data block is full but not flushed to disk */
202 
203  /** Data block is flushed and can be reused */
205 };
206 
207 /** Archiver block type */
209  /* Block which holds reset information */
211 
212  /* Block which holds archived page IDs */
214 };
215 
216 /** Archiver block flush type */
218  /** Flush when block is full */
220 
221  /** Flush partial block.
222  Needed for persistent page tracking. */
224 };
225 
226 /** Page Archive doublewrite buffer block offsets */
228  /** Archive doublewrite buffer page offset for RESET page. */
230 
231  /* Archive doublewrite buffer page offset for FULL FLUSH page. */
233 
234  /* Archive doublewrite buffer page offset for PARTIAL FLUSH page. */
236 };
237 
238 /** Initialize Page and Log archiver system
239 @return error code */
241 
242 /** Free Page and Log archiver system */
243 void arch_free();
244 
245 /** Start log archiver background thread.
246 @return error code */
248 
249 /** Start page archiver background thread.
250 @return error code */
252 
253 /** Archiver thread event to signal that data is available */
255 
256 /** Page archiver background thread */
257 void page_archiver_thread();
258 
259 /** Wakes up archiver threads.
260 @return true iff any thread was still alive */
261 bool arch_wake_threads();
262 
263 /** Forward declarations */
264 class Arch_Group;
265 class Arch_Log_Sys;
266 class Arch_Dblwr_Ctx;
267 struct Arch_Recv_Group_Info;
268 
269 /** Position in page ID archiving system */
271  /** Initialize a position */
272  void init();
273 
274  /** Position in the beginning of next block */
275  void set_next();
276 
277  /** Unique block number */
278  uint64_t m_block_num;
279 
280  /** Offset within a block */
282 
284  if (m_block_num < pos.m_block_num ||
285  (m_block_num == pos.m_block_num && m_offset <= pos.m_offset)) {
286  return (true);
287  }
288  return (false);
289  }
290 };
291 
292 /** Structure which represents a point in a file. */
293 struct Arch_Point {
294  /** LSN of the point */
296 
297  /** Position of the point */
299 };
300 
301 /* Structure which represents a file in a group and its reset points. */
303  /* Initialize the structure. */
304  void init();
305 
306  /* Index of the file in the group */
308 
309  /* LSN of the first reset point in the vector of reset points this
310  structure maintains. Treated as the file LSN. */
312 
313  /* Vector of reset points which belong to this file */
314  std::vector<Arch_Point> m_start_point;
315 };
316 
317 /* Structure representing list of archived files. */
318 using Arch_Reset = std::deque<Arch_Reset_File>;
319 
320 /** In memory data block in Page ID archiving system */
321 class Arch_Block {
322  public:
323  /** Constructor: Initialize elements
324  @param[in] blk_buf buffer for data block
325  @param[in] size buffer size
326  @param[in] type block type */
328  : m_data(blk_buf), m_size(size), m_type(type) {}
329 
330  /** Do a deep copy of the members of the block passed as the parameter.
331  @note This member needs to be updated whenever a new data member is added to
332  this class. */
333  void copy_data(const Arch_Block *block);
334 
335  /** Set the block ready to begin writing page ID
336  @param[in] pos position to initiate block number */
338 
339  /** End writing to a block.
340  Change state to #ARCH_BLOCK_READY_TO_FLUSH */
341  void end_write();
342 
343  /** Check if block is initialised or not.
344  @return true if it has been initialised, else false */
345  bool is_init() const { return (m_state == ARCH_BLOCK_INIT); }
346 
347  bool is_active() const { return (m_state == ARCH_BLOCK_ACTIVE); }
348  /** Check if the block can be flushed or not.
349  @return true, if the block cannot be flushed */
350  bool is_flushable() const { return (m_state != ARCH_BLOCK_READY_TO_FLUSH); }
351 
352  /** Set current block flushed.
353  Must hold page archiver sys operation mutex. */
355 
356  /** Add page ID to current block
357  @param[in] page page from buffer pool
358  @param[in] pos Archiver current position
359  @return true, if successful
360  false, if no more space in current block */
362 
363  /* Add reset information to the current reset block.
364  @param[in] reset_lsn reset lsn info
365  @param[in] reset_pos reset pos info which needs to be added
366  to the current reset block */
367  void add_reset(lsn_t reset_lsn, Arch_Page_Pos reset_pos);
368 
369  /** Copy page Ids from this block at read position to a buffer.
370  @param[in] read_pos current read position
371  @param[in] read_len length of data to copy
372  @param[out] read_buff buffer to copy page IDs.
373  Caller must allocate the buffer.
374  @return true, if successful
375  false, if block is already overwritten */
376  bool get_data(Arch_Page_Pos *read_pos, uint read_len, byte *read_buff);
377 
378  /** Copy page Ids from a buffer to this block.
379  @param[in] read_len length of data to copy
380  @param[in] read_buff buffer to copy page IDs from
381  @param[in] read_offset offset from where to write
382  @return true if successful */
383  bool set_data(uint read_len, byte *read_buff, uint read_offset);
384 
385  /** Flush this block to the file group
386  @param[in] file_group current archive group
387  @param[in] type flush type
388  @return error code. */
390 
391  /* Update the block header with the given LSN
392  @param[in] stop_lsn stop LSN to update in the block header
393  @param[in] reset_lsn reset LSN to update in the blk header */
394  void update_block_header(lsn_t stop_lsn, lsn_t reset_lsn);
395 
396  void read(Arch_Group *group, uint64_t offset);
397 
398  /** Set the data length of the block.
399  @param[in] data_len data length */
400  void set_data_len(uint data_len) { m_data_len = data_len; }
401 
402  /** @return data length of the block. */
403  uint get_data_len() const { return (m_data_len); }
404 
405  /** @return block number of the block. */
406  uint64_t get_number() const { return (m_number); }
407 
408  /** @return stop lsn */
409  lsn_t get_stop_lsn() const { return (m_stop_lsn); }
410 
411  /** Get oldest LSN among the pages that are added to this block
412  @return oldest LSN in block pages */
413  lsn_t get_oldest_lsn() const { return (m_oldest_lsn); }
414 
415  /** Get current state of the block
416  @return block state */
417  Arch_Blk_State get_state() const { return (m_state); }
418 
419  /** Check if the block contains only zeroes.
420  @param[in] block block data
421  @return true if block is filled with zeroes. */
422  static bool is_zeroes(const byte *block);
423 
424  /** Check if the block data is valid.
425  @param[in] block block to be validated
426  @return true if it's a valid block, else false */
427  static bool validate(byte *block);
428 
429  /** Get file index of the file the block belongs to.
430  @return file index */
431  static uint get_file_index(uint64_t block_num);
432 
433  /** Get block type from the block header.
434  @param[in] block block from where to get the type
435  @return block type */
436  static uint get_type(byte *block);
437 
438  /** Get block data length from the block header.
439  @param[in] block block from where to get the data length
440  @return block data length */
441  static uint get_data_len(byte *block);
442 
443  /** Get the stop lsn stored in the block header.
444  @param[in] block block from where to fetch the stop lsn
445  @return stop lsn */
446  static lsn_t get_stop_lsn(byte *block);
447 
448  /** Get the block number from the block header.
449  @param[in] block block from where to fetch the block number
450  @return block number */
451  static uint64_t get_block_number(byte *block);
452 
453  /** Get the reset lsn stored in the block header.
454  @param[in] block block from where to fetch the reset lsn
455  @return reset lsn */
456  static lsn_t get_reset_lsn(byte *block);
457 
458  /** Get the checksum stored in the block header.
459  @param[in] block block from where to fetch the checksum
460  @return checksum */
461  static uint32_t get_checksum(byte *block);
462 
463  /** Fetch the offset for a block in the archive file.
464  @param[in] block_num block number
465  @param[in] type type of block
466  @return file offset of the block */
467  static uint64_t get_file_offset(uint64_t block_num, Arch_Blk_Type type);
468 
469  private:
470  /* @note member function copy_data needs to be updated whenever a new data
471  member is added to this class. */
472 
473  /** Block data buffer */
475 
476  /** Block data length in bytes */
478 
479  /** Total block size in bytes */
481 
482  /** State of the block. */
484 
485  /** Unique block number */
486  uint64_t m_number{};
487 
488  /** Type of block. */
490 
491  /** Checkpoint lsn at the time the last page ID was added to the
492  block. */
494 
495  /** Oldest LSN of all the page IDs added to the block since the last
496  * checkpoint */
498 
499  /** Start LSN or the last reset LSN of the group */
501 };
502 
503 /** Archiver file context.
504 Represents a set of fixed size files within a group */
506  public:
507  /** Constructor: Initialize members */
509 
510  /** Destructor: Close open file and free resources */
512  close();
513 
514  if (m_name_buf != nullptr) {
516  }
517  }
518 
519  /** Initializes archiver file context.
520  @param[in] path path to the file
521  @param[in] base_dir directory name prefix
522  @param[in] base_file file name prefix
523  @param[in] num_files initial number of files
524  @param[in] file_size file size in bytes
525  @return error code. */
526  dberr_t init(const char *path, const char *base_dir, const char *base_file,
527  uint num_files, uint64_t file_size);
528 
529  /** Open a file at specific index
530  @param[in] read_only open in read only mode
531  @param[in] start_lsn start lsn for the group
532  @param[in] file_index index of the file within the group which needs
533  to be opened
534  @param[in] file_offset start offset
535  @return error code. */
536  dberr_t open(bool read_only, lsn_t start_lsn, uint file_index,
537  uint64_t file_offset);
538 
539  /** Add a new file and open
540  @param[in] start_lsn start lsn for the group
541  @param[in] file_offset start offset
542  @return error code. */
543  dberr_t open_new(lsn_t start_lsn, uint64_t file_offset);
544 
545  /** Open next file for read
546  @param[in] start_lsn start lsn for the group
547  @param[in] file_offset start offset
548  @return error code. */
549  dberr_t open_next(lsn_t start_lsn, uint64_t file_offset);
550 
551  /** Read data from the current file that is open.
552  Caller must ensure that the size is within the limits of current file
553  context.
554  @param[in,out] to_buffer read data into this buffer
555  @param[in] offset file offset from where to read
556  @param[in] size size of data to read in bytes
557  @return error code */
558  dberr_t read(byte *to_buffer, const uint offset, const uint size);
559 
560  /** Write data to this file context from the given file offset.
561  Data source is another file context or buffer. If buffer is NULL, data is
562  copied from input file context. Caller must ensure that the size is within
563  the limits of current file for both source and destination file context.
564  @param[in] from_file file context to copy data from
565  @param[in] from_buffer buffer to copy data or NULL
566  @param[in] offset file offset from where to write
567  @param[in] size size of data to copy in bytes
568  @return error code */
569  dberr_t write(Arch_File_Ctx *from_file, byte *from_buffer, uint offset,
570  uint size);
571 
572  /** Write data to this file context from the current offset.
573  Data source is another file context or buffer. If buffer is NULL, data is
574  copied from input file context. Caller must ensure that the size is within
575  the limits of current file for both source and destination file context.
576  @param[in] from_file file context to copy data from
577  @param[in] from_buffer buffer to copy data or NULL
578  @param[in] size size of data to copy in bytes
579  @return error code */
580  dberr_t write(Arch_File_Ctx *from_file, byte *from_buffer, uint size);
581 
582  /** Flush file. */
583  void flush() {
584  if (m_file.m_file != OS_FILE_CLOSED) {
586  }
587  }
588 
589  /** Close file, if open */
590  void close() {
591  if (m_file.m_file != OS_FILE_CLOSED) {
594  }
595  }
596 
597  /** Check if file is closed
598  @return true, if file is closed */
599  bool is_closed() const { return (m_file.m_file == OS_FILE_CLOSED); }
600 
601  /** Check how much is left in current file
602  @return length left in bytes */
603  uint64_t bytes_left() const {
604  ut_ad(m_size >= m_offset);
605  return (m_size - m_offset);
606  }
607 
608  /** Construct file name at specific index
609  @param[in] idx file index
610  @param[in] dir_lsn lsn of the group
611  @param[out] buffer file name including path.
612  The buffer is allocated by caller.
613  @param[in] length buffer length */
614  void build_name(uint idx, lsn_t dir_lsn, char *buffer, uint length);
615 
616  /** Construct group directory name
617  @param[in] dir_lsn lsn of the group
618  @param[out] buffer directory name.
619  The buffer is allocated by caller.
620  @param[in] length buffer length */
621  void build_dir_name(lsn_t dir_lsn, char *buffer, uint length);
622 
623  /** Get the logical size of a file.
624  @return logical file size. */
625  uint64_t get_size() const { return (m_size); }
626 
627  /* Fetch offset of the file open in this context.
628  @return file offset */
629  uint get_offset() const { return (m_offset); }
630 
631  /** Get number of files
632  @return current file count */
633  uint get_count() const { return (m_count); }
634 
635  /** Get the physical size of a file that is open in this context.
636  @return physical file size */
637  uint64_t get_phy_size() const {
638  ut_ad(m_name_buf != nullptr);
640  return (file_size.m_total_size);
641  }
642 
643  /** Update stop lsn of a file in the group.
644  @param[in] file_index file_index the current write_pos belongs to
645  @param[in] stop_lsn stop point */
646  void update_stop_point(uint file_index, lsn_t stop_lsn);
647 
648 #ifdef UNIV_DEBUG
649  /** Print recovery related data.
650  @param[in] file_start_index file index from where to begin */
651  void recovery_reset_print(uint file_start_index);
652 
653  /** Check if the information maintained in the memory is the same
654  as the information maintained in the files.
655  @return true if both sets of information are the same
656  @param[in] group group whose file is being validated
657  @param[in] file_index index of the file which is being validated
658  @param[in] start_lsn
659  @param[in,out] reset_count count of files which has been validated
660  @return true if both the sets of information are the same. */
661  bool validate(Arch_Group *group, uint file_index, lsn_t start_lsn,
662  uint &reset_count);
663 #endif
664 
665  /** Update the reset information in the in-memory structure that we maintain
666  for faster access.
667  @param[in] lsn lsn at the time of reset
668  @param[in] pos pos at the time of reset
669  @retval true if the reset point was saved
670  @retval false if the reset point wasn't saved because it was already saved */
672 
673  /** Find the appropriate reset LSN that is less than or equal to the
674  given lsn and fetch the reset point.
675  @param[in] check_lsn LSN to be searched against
676  @param[out] reset_point reset position of the fetched reset point
677  @return true if the search was successful. */
678  bool find_reset_point(lsn_t check_lsn, Arch_Point &reset_point);
679 
680  /** Find the first stop LSN that is greater than the given LSN and fetch
681  the stop point.
682  @param[in] group the group whose stop_point we're interested in
683  @param[in] check_lsn LSN to be searched against
684  @param[out] stop_point stop point
685  @param[in] last_pos position of the last block in the group;
686  m_write_pos if group is active and m_stop_pos if not
687  @return true if the search was successful. */
688  bool find_stop_point(Arch_Group *group, lsn_t check_lsn,
689  Arch_Point &stop_point, Arch_Page_Pos last_pos);
690 
691  /** Delete a single file belonging to the specified file index.
692  @param[in] file_index file index of the file which needs to be deleted
693  @param[in] begin_lsn group's start lsn
694  @return true if successful, else false. */
695  bool delete_file(uint file_index, lsn_t begin_lsn);
696 
697  /** Delete all files for this archive group
698  @param[in] begin_lsn group's start lsn */
699  void delete_files(lsn_t begin_lsn);
700 
701  /** Purge archived files until the specified purge LSN.
702  @param[in] begin_lsn start LSN of the group
703  @param[in] end_lsn end LSN of the group
704  @param[in] purge_lsn purge LSN until which files needs to be purged
705  @return LSN until which purging was successful
706  @retval LSN_MAX if there was no purging done. */
707  lsn_t purge(lsn_t begin_lsn, lsn_t end_lsn, lsn_t purge_lsn);
708 
709  /** Fetch the last reset file and last stop point info during recovery
710  @param[out] reset_file last reset file to be updated
711  @param[out] stop_lsn last stop lsn to be updated */
712  void recovery_fetch_info(Arch_Reset_File &reset_file, lsn_t &stop_lsn) {
713  if (m_reset.size() != 0) {
714  reset_file = m_reset.back();
715  }
716 
717  stop_lsn = get_last_stop_point();
718  }
719 
720  /** Fetch the status of the page tracking system.
721  @param[out] status vector of a pair of (ID, bool) where ID is the
722  start/stop point and bool is true if the ID is a start point else false */
723  void get_status(std::vector<std::pair<lsn_t, bool>> &status) {
724  for (auto reset_file : m_reset) {
725  for (auto reset_point : reset_file.m_start_point) {
726  status.push_back(std::make_pair(reset_point.lsn, true));
727  }
728  }
729  }
730 
731  /** @return the stop_point which was stored last */
733  if (m_stop_points.size() == 0) {
734  return (LSN_MAX);
735  }
736 
737  return (m_stop_points.back());
738  }
739 
740  /** Fetch the reset points pertaining to a file.
741  @param[in] file_index file index of the file from which reset points
742  needs to be fetched
743  @param[in,out] reset_pos Update the reset_pos while fetching the
744  reset points
745  @return error code. */
746  dberr_t fetch_reset_points(uint file_index, Arch_Page_Pos &reset_pos);
747 
748  /** Fetch the stop lsn pertaining to a file.
749  @param[in] last_file true if the file for which the stop point is
750  being fetched for is the last file
751  @param[in,out] write_pos Update the write_pos while fetching the
752  stop points
753  @return error code. */
754  dberr_t fetch_stop_points(bool last_file, Arch_Page_Pos &write_pos);
755 
756  private:
757 #ifdef UNIV_DEBUG
758  /** Check if the reset information maintained in the memory is the same
759  as the information maintained in the given file.
760  @param[in] file file descriptor
761  @param[in] file_index index of the file
762  @param[in,out] reset_count number of files processed containing
763  reset data
764  @return true if both sets of information are the same */
765  bool validate_reset_block_in_file(pfs_os_file_t file, uint file_index,
766  uint &reset_count);
767 
768  /** Check if the stop LSN maintained in the memory is the same as the
769  information maintained in the files.
770  @param[in] group group whose file is being validated
771  @param[in] file file descriptor
772  @param[in] file_index index of the file for which the validation is
773  happening
774  @return true if both the sets of information are the same. */
776  uint file_index);
777 #endif
778 
779  /** Fetch reset lsn of a particular reset point pertaining to a file.
780  @param[in] block_num block number where the reset occurred.
781  @return reset lsn */
782  lsn_t fetch_reset_lsn(uint64_t block_num);
783 
784  private:
785  /** File name buffer.
786  Used if caller doesn't allocate buffer. */
787  char *m_name_buf{nullptr};
788 
789  /** File name buffer length */
791 
792  /** Fixed length part of the file.
793  Path ended with directory separator. */
795 
796  /** Fixed part of the path to file */
797  const char *m_path_name{nullptr};
798 
799  /** Directory name prefix */
800  const char *m_dir_name{nullptr};
801 
802  /** File name prefix */
803  const char *m_file_name{nullptr};
804 
805  /** Current file descriptor */
807 
808  /** File index within the archive group */
810 
811  /** Current number of files in the archive group */
813 
814  /** Current file offset */
815  uint64_t m_offset{};
816 
817  /** File size limit in bytes */
818  uint64_t m_size{};
819 
820  /** Queue of file structure holding reset information pertaining to
821  their respective files in a group.
822  Protected by Arch_Page_Sys::m_mutex and Arch_Page_Sys::m_oper_mutex.
823  @note used only by the page archiver */
825 
826  /** Vector of stop points corresponding to a file.
827  Stop point refers to the stop lsn (checkpoint lsn) until which the pages are
828  guaranteed to be tracked in a file. Each block in a file maintains this
829  information.
830  Protected by Arch_Page_Sys::m_oper_mutex.
831  @note used only by the page archiver */
832  std::vector<lsn_t> m_stop_points;
833 };
834 
835 /** Contiguous archived data for redo log or page tracking.
836 If there is a gap, that is if archiving is stopped and started, a new
837 group is created. */
838 class Arch_Group {
839  public:
840  /** Constructor: Initialize members
841  @param[in] start_lsn start LSN for the group
842  @param[in] header_len length of header for archived files
843  @param[in] mutex archive system mutex from caller */
844  Arch_Group(lsn_t start_lsn, uint header_len, ib_mutex_t *mutex)
845  : m_begin_lsn(start_lsn),
846  m_header_len(header_len)
847 #ifdef UNIV_DEBUG
848  ,
850 #endif /* UNIV_DEBUG */
851  {
854  m_stop_pos.init();
855  }
856 
857  /** Destructor: Delete all files for non-durable archiving. */
858  ~Arch_Group();
859 
860  /** Initialize the doublewrite buffer file context for the archive group.
861  @param[in] path path to the file
862  @param[in] base_file file name prefix
863  @param[in] num_files initial number of files
864  @param[in] file_size file size in bytes
865  @return error code. */
866  static dberr_t init_dblwr_file_ctx(const char *path, const char *base_file,
867  uint num_files, uint64_t file_size);
868 
869  /** Initialize the file context for the archive group.
870  File context keeps the archived data in files on disk. There
871  is one file context for a archive group.
872  @param[in] path path to the file
873  @param[in] base_dir directory name prefix
874  @param[in] base_file file name prefix
875  @param[in] num_files initial number of files
876  @param[in] file_size file size in bytes
877  @return error code. */
878  dberr_t init_file_ctx(const char *path, const char *base_dir,
879  const char *base_file, uint num_files,
880  uint64_t file_size) {
881  return (m_file_ctx.init(path, base_dir, base_file, num_files, file_size));
882  }
883 
884  /* Close the file contexts when they're not required anymore. */
886  m_file_ctx.close();
887 
891  }
892  }
893 
894  /** Mark archive group inactive.
895  A group is marked inactive by archiver background before entering
896  into idle state ARCH_STATE_IDLE.
897  @param[in] end_lsn lsn where redo archiving is stopped */
898  void disable(lsn_t end_lsn) {
899  m_is_active = false;
900 
901  if (end_lsn != LSN_MAX) {
902  m_end_lsn = end_lsn;
903  }
904  }
905 
906  /** Attach a client to the archive group.
907  @param[in] is_durable true, if durable tracking is requested
908  @return number of client references */
909  void attach(bool is_durable) {
911  ++m_num_active;
912 
913  if (is_durable) {
914  ++m_dur_ref_count;
915  } else {
916  ++m_ref_count;
917  }
918  }
919 
920  /** Detach a client when archiving is stopped by the client.
921  The client still has reference to the group so that the group
922  is not destroyed when it retrieves the archived data. The
923  reference is removed later by #Arch_Group::release.
924  @param[in] stop_lsn archive stop lsn for client
925  @param[in] stop_pos archive stop position for client. Used only by
926  the page_archiver.
927  @return number of active clients */
928  uint detach(lsn_t stop_lsn, Arch_Page_Pos *stop_pos) {
929  ut_ad(m_num_active > 0);
931  --m_num_active;
932 
933  if (m_num_active == 0) {
934  m_end_lsn = stop_lsn;
935  if (stop_pos != nullptr) {
936  m_stop_pos = *stop_pos;
937  }
938  }
939 
940  return (m_num_active);
941  }
942 
943  /** Release the archive group from a client.
944  Reduce the reference count. When all clients release the group,
945  the reference count falls down to zero. The function would then
946  return zero and the caller can remove the group.
947  @param[in] is_durable the client needs durable archiving */
948  void release(bool is_durable) {
950  ut_a(!is_durable);
951 
952  ut_ad(m_ref_count > 0);
953  --m_ref_count;
954  }
955 
956  /** Construct file name for the active file which indicates whether a group
957  is active or not.
958  @note Used only by the page archiver.
959  @return error code. */
961 
962  /** Construct file name for the durable file which indicates whether a group
963  was made durable or not.
964  @note Used only by the page archiver.
965  @return error code. */
967 
968  /** Mark the group active by creating a file in the respective group
969  directory. This is required at the time of recovery to know whether a group
970  was active or not in case of a crash.
971  @note Used only by the page archiver.
972  @return error code. */
973  int mark_active();
974 
975  /** Mark the group durable by creating a file in the respective group
976  directory. This is required at the time of recovery to differentiate durable
977  group from group left over by crash during clone operation.
978  @note Used only by the page archiver.
979  @return error code. */
980  int mark_durable();
981 
982  /** Mark the group inactive by deleting the 'active' file. This is required
983  at the time of crash recovery to know whether a group was active or not in
984  case of a crash.
985  @note Used only by the page archiver.
986  @return error code */
987  int mark_inactive();
988 
989  /** Check if archiving is going on for this group
990  @return true, if the group is active */
991  bool is_active() const { return (m_is_active); }
992 
993  /** Write the header (RESET page) to an archived file.
994  @note Used only by the Page Archiver and not by the Redo Log Archiver.
995  @param[in] from_buffer buffer to copy data
996  @param[in] length size of data to copy in bytes
997  @note Used only by the Page Archiver.
998  @return error code */
999  dberr_t write_file_header(byte *from_buffer, uint length);
1000 
1001  /** Write to the doublewrite buffer before writing archived data to a file.
1002  The source is either a file context or buffer. Caller must ensure that data
1003  is in single file in source file context.
1004  @param[in] from_file file context to copy data from
1005  @param[in] from_buffer buffer to copy data or NULL
1006  @param[in] write_size size of data to write in bytes
1007  @param[in] offset offset from where to write
1008  @note Used only by the Page Archiver.
1009  @return error code */
1011  byte *from_buffer, uint write_size,
1012  Arch_Page_Dblwr_Offset offset);
1013 
1014  /** Archive data to one or more files.
1015  The source is either a file context or buffer. Caller must ensure that data
1016  is in single file in source file context.
1017  @param[in] from_file file context to copy data from
1018  @param[in] from_buffer buffer to copy data or NULL
1019  @param[in] length size of data to copy in bytes
1020  @param[in] partial_write true if the operation is part of partial flush
1021  @param[in] do_persist doublewrite to ensure persistence
1022  @return error code */
1023  dberr_t write_to_file(Arch_File_Ctx *from_file, byte *from_buffer,
1024  uint length, bool partial_write, bool do_persist);
1025 
1026  /** Find the appropriate reset LSN that is less than or equal to the
1027  given lsn and fetch the reset point.
1028  @param[in] check_lsn LSN to be searched against
1029  @param[out] reset_point reset position of the fetched reset point
1030  @return true if the search was successful. */
1031  bool find_reset_point(lsn_t check_lsn, Arch_Point &reset_point) {
1032  return (m_file_ctx.find_reset_point(check_lsn, reset_point));
1033  }
1034 
1035  /** Find the first stop LSN that is greater than the given LSN and fetch
1036  the stop point.
1037  @param[in] check_lsn LSN to be searched against
1038  @param[out] stop_point stop point
1039  @param[in] write_pos latest write_pos
1040  @return true if the search was successful. */
1041  bool find_stop_point(lsn_t check_lsn, Arch_Point &stop_point,
1042  Arch_Page_Pos write_pos) {
1044  Arch_Page_Pos last_pos = is_active() ? write_pos : m_stop_pos;
1045  return (m_file_ctx.find_stop_point(this, check_lsn, stop_point, last_pos));
1046  }
1047 
1048 #ifdef UNIV_DEBUG
1049  /** Adjust end LSN to end of file. This is used in debug
1050  mode to test the case when LSN is at file boundary.
1051  @param[in,out] stop_lsn stop lsn for client
1052  @param[out] blk_len last block length */
1053  void adjust_end_lsn(lsn_t &stop_lsn, uint32_t &blk_len);
1054 
1055  /** Adjust redo copy length to end of file. This is used
1056  in debug mode to archive only till end of file.
1057  @param[in,out] length data to copy in bytes */
1058  void adjust_copy_length(uint32_t &length);
1059 
1060  /** Check if the information maintained in the memory is the same
1061  as the information maintained in the files.
1062  @return true if both sets of information are the same */
1063  bool validate_info_in_files();
1064 #endif /* UNIV_DEBUG */
1065 
1066  /** Get the total number of archived files belonging to this group.
1067  @return number of archived files */
1068  uint get_file_count() const { return (m_file_ctx.get_count()); }
1069 
1070  /** Check if any client (durable or not) is attached to the archiver.
1071  @return true if any client is attached, else false */
1072  bool is_referenced() const {
1073  return (m_ref_count > 0) || (m_dur_ref_count > 0);
1074  }
1075 
1076  /** Check if any client requiring durable archiving is active.
1077  @return true if any durable client is still attached, else false */
1079  return (m_num_active != m_ref_count);
1080  }
1081 
1082  /** Check if any client requires durable archiving.
1083  @return true if there is at least 1 client that requires durable archiving*/
1084  bool is_durable() const { return (m_dur_ref_count > 0); }
1085 
1086  /** Attach system client to the archiver during recovery if any group was
1087  active at the time of crash. */
1089 
1090  /** Purge archived files until the specified purge LSN.
1091  @param[in] purge_lsn LSN until which archived files needs to be
1092  purged
1093  @param[out] purged_lsn LSN until which purging is successfule;
1094  LSN_MAX if there was no purging done
1095  @return error code */
1096  uint purge(lsn_t purge_lsn, lsn_t &purged_lsn);
1097 
1098  /** Operations to be done at the time of shutdown. */
1099  static void shutdown() { s_dblwr_file_ctx.close(); }
1100 
1101  /** Update the reset information in the in-memory structure that we maintain
1102  for faster access.
1103  @param[in] lsn lsn at the time of reset
1104  @param[in] pos pos at the time of reset
1105  @retval true if the reset point was saved
1106  @retval false if the reset point wasn't saved because it was already saved */
1109  }
1110 
1111  /** Update stop lsn of a file in the group.
1112  @param[in] pos stop position
1113  @param[in] stop_lsn stop point */
1116  stop_lsn);
1117  }
1118 
1119  /** Recover the information belonging to this group from the archived files.
1120  @param[in,out] group_info structure containing information of a
1121  group obtained during recovery by scanning files
1122  @param[in,out] new_empty_file true if there is/was an empty archived
1123  file
1124  @param[in] dblwr_ctx file context related to doublewrite
1125  buffer
1126  @param[out] write_pos latest write position at the time of
1127  crash /shutdown that needs to be filled
1128  @param[out] reset_pos latest reset position at the time crash
1129  /shutdown that needs to be filled
1130  @return error code */
1131  dberr_t recover(Arch_Recv_Group_Info *group_info, bool &new_empty_file,
1132  Arch_Dblwr_Ctx *dblwr_ctx, Arch_Page_Pos &write_pos,
1133  Arch_Page_Pos &reset_pos);
1134 
1135  /** Reads the latest data block and reset block.
1136  This would be required in case of active group to start page archiving after
1137  recovery, and in case of inactive group to fetch stop lsn. So we perform this
1138  operation regardless of whether it's an active or inactive group.
1139  @param[in] buf buffer to read the blocks into
1140  @param[in] offset offset from where to read
1141  @param[in] type block type
1142  @return error code */
1143  dberr_t recovery_read_latest_blocks(byte *buf, uint64_t offset,
1145 
1146  /** Fetch the last reset file and last stop point info during recovery
1147  @param[out] reset_file last reset file to be updated
1148  @param[out] stop_lsn last stop lsn to be updated */
1149  void recovery_fetch_info(Arch_Reset_File &reset_file, lsn_t &stop_lsn) {
1150  m_file_ctx.recovery_fetch_info(reset_file, stop_lsn);
1151  }
1152 
1153 #ifdef UNIV_DEBUG
1154  /** Print recovery related data.
1155  @param[in] file_start_index file index from where to begin */
1156  void recovery_reset_print(uint file_start_index) {
1157  DBUG_PRINT("page_archiver", ("Group : %" PRIu64 "", m_begin_lsn));
1158  m_file_ctx.recovery_reset_print(file_start_index);
1159  DBUG_PRINT("page_archiver", ("End lsn: %" PRIu64 "", m_end_lsn));
1160  }
1161 #endif
1162 
1163  /** Parse block for block info (header/data).
1164  @param[in] cur_pos position to read
1165  @param[in,out] buff buffer into which to write the parsed data
1166  @param[in] buff_len length of the buffer
1167  @return error code */
1168  int read_data(Arch_Page_Pos cur_pos, byte *buff, uint buff_len);
1169 
1170  /** Get archived file name at specific index in this group.
1171  Caller would use it to open and copy data from archived files.
1172  @param[in] idx file index in the group
1173  @param[out] name_buf file name and path. Caller must
1174  allocate the buffer.
1175  @param[in] buf_len allocated buffer length */
1176  void get_file_name(uint idx, char *name_buf, uint buf_len) {
1177  ut_ad(name_buf != nullptr);
1178 
1179  /* Build name from the file context. */
1180  m_file_ctx.build_name(idx, m_begin_lsn, name_buf, buf_len);
1181  }
1182 
1183  /** Get file size for this group.
1184  Fixed size files are used for archiving data in a group.
1185  @return file size in bytes */
1186  uint64_t get_file_size() const { return (m_file_ctx.get_size()); }
1187 
1188  /** Get start LSN for this group
1189  @return start LSN */
1190  lsn_t get_begin_lsn() const { return (m_begin_lsn); }
1191 
1192  /** @return stop LSN for this group */
1193  lsn_t get_end_lsn() const { return (m_end_lsn); }
1194 
1195  /** @return stop block position of the group. */
1196  Arch_Page_Pos get_stop_pos() const { return (m_stop_pos); }
1197 
1198  /** Fetch the status of the page tracking system.
1199  @param[out] status vector of a pair of (ID, bool) where ID is the
1200  start/stop point and bool is true if the ID is a start point else false */
1201  void get_status(std::vector<std::pair<lsn_t, bool>> &status) {
1203 
1204  if (!is_active()) {
1205  status.push_back(std::make_pair(m_end_lsn, false));
1206  }
1207  }
1208 
1209  /** Disable copy construction */
1210  Arch_Group(Arch_Group const &) = delete;
1211 
1212  /** Disable assignment */
1213  Arch_Group &operator=(Arch_Group const &) = delete;
1214 
1215  private:
1216  /** Get page IDs from archived file
1217  @param[in] read_pos position to read from
1218  @param[in] read_len length of data to read
1219  @param[in] read_buff buffer to read page IDs
1220  @return error code */
1221  int read_from_file(Arch_Page_Pos *read_pos, uint read_len, byte *read_buff);
1222 
1223  /** Get the directory name for this archive group.
1224  It is used for cleaning up the archive directory.
1225  @param[out] name_buf directory name and path. Caller must
1226  allocate the buffer.
1227  @param[in] buf_len buffer length */
1228  void get_dir_name(char *name_buf, uint buf_len) {
1229  m_file_ctx.build_dir_name(m_begin_lsn, name_buf, buf_len);
1230  }
1231 
1232  /** Check and replace blocks in archived files belonging to a group
1233  from the doublewrite buffer if required.
1234  @param[in] dblwr_ctx Doublewrite context which has the doublewrite
1235  buffer blocks
1236  @return error code */
1238 
1239  /** Delete the last file if there are no blocks flushed to it.
1240  @param[out] num_files number of files present in the group
1241  @param[in] start_index file index from where the files are present
1242  If this is not 0 then the files with file index less that this might have
1243  been purged.
1244  @param[in] durable true if the group is durable
1245  @param[out] empty_file true if there is/was an empty archived file
1246  @return error code. */
1247  dberr_t recovery_cleanup_if_required(uint &num_files, uint start_index,
1248  bool durable, bool &empty_file);
1249 
1250  /** Start parsing the archive file for archive group information.
1251  @param[out] write_pos latest write position at the time of
1252  crash /shutdown that needs to be filled
1253  @param[out] reset_pos latest reset position at the time crash
1254  /shutdown that needs to be filled
1255  @param[in] start_index file index from where the files are present
1256  If this is not 0 then the files with file index less that this might have
1257  been purged.
1258  @return error code */
1259  dberr_t recovery_parse(Arch_Page_Pos &write_pos, Arch_Page_Pos &reset_pos,
1260  size_t start_index);
1261 
1262  /** Open the file which was open at the time of a crash, during crash
1263  recovery, and set the file offset to the last written offset.
1264  @param[in] write_pos block position from where page IDs will be
1265  tracked
1266  @param[in] empty_file true if an empty archived file was present at
1267  the time of crash. We delete this file as part of crash recovery process so
1268  this needs to be handled here.
1269  @return error code. */
1270  dberr_t open_file_during_recovery(Arch_Page_Pos write_pos, bool empty_file);
1271 
1272  private:
1273  /** If the group is active */
1274  bool m_is_active{true};
1275 
1276  /** To know which group was active at the time of a crash/shutdown during
1277  recovery we create an empty file in the group directory. This holds the name
1278  of the file. */
1279  char *m_active_file_name{nullptr};
1280 
1281  /** File descriptor for a file required to indicate that the group was
1282  active at the time of crash during recovery . */
1284 
1285  /** File name for the durable file which indicates whether a group was made
1286  durable or not. Required to differentiate durable group from group left over
1287  by crash during clone operation. */
1288  char *m_durable_file_name{nullptr};
1289 
1290  /** File descriptor for a file to indicate that the group was made durable or
1291  not. Required to differentiate durable group from group left over by crash
1292  during clone operation. */
1294 
1295  /** Number of clients referencing the group */
1297 
1298  /** Number of clients referencing for durable archiving */
1300 
1301  /** Number of clients for which archiving is in progress */
1303 
1304  /** Start LSN for the archive group */
1306 
1307  /** End lsn for this archive group */
1309 
1310  /** Stop position of the group, if it's not active. */
1312 
1313  /** Header length for the archived files */
1315 
1316  /** Archive file context */
1318 
1319  /** Doublewrite buffer file context.
1320  Note - Used only in the case of page archiver. */
1322 
1323 #ifdef UNIV_DEBUG
1324  /** Mutex protecting concurrent operations by multiple clients.
1325  This is either the redo log or page archive system mutex. Currently
1326  used for assert checks. */
1327  ib_mutex_t *m_arch_mutex;
1328 #endif /* UNIV_DEBUG */
1329 };
1330 
1331 /** A list of archive groups */
1332 using Arch_Grp_List = std::list<Arch_Group *, ut_allocator<Arch_Group *>>;
1333 
1334 /** An iterator for archive group */
1335 using Arch_Grp_List_Iter = Arch_Grp_List::iterator;
1336 
1337 /** Redo log archiving system */
1339  public:
1340  /** Constructor: Initialize members */
1344  m_group_list(),
1345  m_current_group() {
1347  }
1348 
1349  /** Destructor: Free mutex */
1352  ut_ad(m_current_group == nullptr);
1353  ut_ad(m_group_list.empty());
1354 
1355  mutex_free(&m_mutex);
1356  }
1357 
1358  /** Check if archiving is in progress.
1359  In #ARCH_STATE_PREPARE_IDLE state, all clients have already detached
1360  but archiver background task is yet to finish.
1361  @return true, if archiving is active */
1362  bool is_active() {
1364  }
1365 
1366  /** Check if archiver system is in initial state
1367  @return true, if redo log archiver state is #ARCH_STATE_INIT */
1368  bool is_init() { return (m_state == ARCH_STATE_INIT); }
1369 
1370  /** Get LSN up to which redo is archived
1371  @return last archived redo LSN */
1372  lsn_t get_archived_lsn() { return (m_archived_lsn.load()); }
1373 
1374  /** Get current redo log archive group
1375  @return current archive group */
1377 
1378  /** Start redo log archiving.
1379  If archiving is already in progress, the client
1380  is attached to current group.
1381  @param[out] group log archive group
1382  @param[out] start_lsn start lsn for client
1383  @param[out] header redo log header
1384  @param[in] is_durable if client needs durable archiving
1385  @return error code */
1386  int start(Arch_Group *&group, lsn_t &start_lsn, byte *header,
1387  bool is_durable);
1388 
1389  /** Stop redo log archiving.
1390  If other clients are there, the client is detached from
1391  the current group.
1392  @param[out] group log archive group
1393  @param[out] stop_lsn stop lsn for client
1394  @param[out] log_blk redo log trailer block
1395  @param[in,out] blk_len length in bytes
1396  @return error code */
1397  int stop(Arch_Group *group, lsn_t &stop_lsn, byte *log_blk,
1398  uint32_t &blk_len);
1399 
1400  /** Force to abort the archiver (state becomes ARCH_STATE_ABORT). */
1401  void force_abort();
1402 
1403  /** Release the current group from client.
1404  @param[in] group group the client is attached to
1405  @param[in] is_durable if client needs durable archiving */
1406  void release(Arch_Group *group, bool is_durable);
1407 
1408  /** Archive accumulated redo log in current group.
1409  This interface is for archiver background task to archive redo log
1410  data by calling it repeatedly over time.
1411  @param[in] init true when called for first time; it will then
1412  be set to false
1413  @param[in] curr_ctx system redo logs to copy data from
1414  @param[out] arch_lsn LSN up to which archiving is completed
1415  @param[out] wait true, if no more redo to archive
1416  @return true, if archiving is aborted */
1417  bool archive(bool init, Arch_File_Ctx *curr_ctx, lsn_t *arch_lsn, bool *wait);
1418 
1419  /** Acquire redo log archiver mutex.
1420  It synchronizes concurrent start and stop operations by
1421  multiple clients. */
1423 
1424  /** Release redo log archiver mutex */
1426 
1427  /** Disable copy construction */
1428  Arch_Log_Sys(Arch_Log_Sys const &) = delete;
1429 
1430  /** Disable assignment */
1431  Arch_Log_Sys &operator=(Arch_Log_Sys const &) = delete;
1432 
1433  private:
1434  /** Wait for archive system to come out of #ARCH_STATE_PREPARE_IDLE.
1435  If the system is preparing to idle, #start needs to wait
1436  for it to come to idle state.
1437  @return true, if successful
1438  false, if needs to abort */
1439  bool wait_idle();
1440 
1441  /** Wait for redo log archive up to the target LSN.
1442  We need to wait till current log sys LSN during archive stop.
1443  @param[in] target_lsn target archive LSN to wait for
1444  @return error code */
1445  int wait_archive_complete(lsn_t target_lsn);
1446 
1447  /** Update checkpoint LSN and related information in redo
1448  log header block.
1449  @param[in,out] header redo log header buffer
1450  @param[in] checkpoint_lsn checkpoint LSN for recovery */
1451  void update_header(byte *header, lsn_t checkpoint_lsn);
1452 
1453  /** Check and set log archive system state and output the
1454  amount of redo log available for archiving.
1455  @param[in] is_abort need to abort
1456  @param[in,out] archived_lsn LSN up to which redo log is archived
1457  @param[out] to_archive amount of redo log to be archived */
1458  Arch_State check_set_state(bool is_abort, lsn_t *archived_lsn,
1459  uint *to_archive);
1460 
1461  /** Copy redo log from file context to archiver files.
1462  @param[in] file_ctx file context for system redo logs
1463  @param[in] length data to copy in bytes
1464  @return error code */
1466 
1467  private:
1468  /** Mutex to protect concurrent start, stop operations */
1469  ib_mutex_t m_mutex;
1470 
1471  /** Archiver system state.
1472  #m_state is protected by #m_mutex and #log_t::writer_mutex. For changing
1473  the state both needs to be acquired. For reading, hold any of the two
1474  mutexes. Same is true for #m_archived_lsn. */
1476 
1477  /** System has archived log up to this LSN */
1479 
1480  /** List of log archive groups */
1482 
1483  /** Current archive group */
1485 
1486  /** Chunk size to copy redo data */
1488 
1489  /** System log file number where the archiving started */
1491 
1492  /** System log file offset where the archiving started */
1493  ib_uint64_t m_start_log_offset;
1494 };
1495 
1496 /** Vector of page archive in memory blocks */
1497 using Arch_Block_Vec = std::vector<Arch_Block *, ut_allocator<Arch_Block *>>;
1498 
1499 /** Page archiver in memory data */
1501  /** Constructor */
1503 
1504  /** Allocate buffer and initialize blocks
1505  @return true, if successful */
1506  bool init();
1507 
1508  /** Delete blocks and buffer */
1509  void clean();
1510 
1511  /** Get the block for a position
1512  @param[in] pos position in page archive sys
1513  @param[in] type block type
1514  @return page archive in memory block */
1516 
1517  /** @return temporary block used to copy active block for partial flush. */
1519  return (m_partial_flush_block);
1520  }
1521 
1522  /** Vector of data blocks */
1524 
1525  /** Reset block */
1527 
1528  /** Temporary block used to copy active block for partial flush. */
1530 
1531  /** Block size in bytes */
1533 
1534  /** Total number of blocks */
1536 
1537  /** In memory buffer */
1538  byte *m_buffer{nullptr};
1539 };
1540 
1541 /** Forward declaration. */
1542 class Page_Arch_Client_Ctx;
1543 
1544 /** Dirty page archive system */
1546  public:
1547  /** Constructor: Initialize elements and create mutex */
1548  Arch_Page_Sys();
1549 
1550  /** Destructor: Free memory buffer and mutexes */
1551  ~Arch_Page_Sys();
1552 
1553  /** Start dirty page ID archiving.
1554  If archiving is already in progress, the client is attached to current group.
1555  @param[out] group page archive group the client gets attached to
1556  @param[out] start_lsn start lsn for client in archived data
1557  @param[out] start_pos start position for client in archived data
1558  @param[in] is_durable true if client needs durable archiving
1559  @param[in] restart true if client is already attached to current group
1560  @param[in] recovery true if archiving is being started during
1561  recovery
1562  @return error code */
1563  int start(Arch_Group **group, lsn_t *start_lsn, Arch_Page_Pos *start_pos,
1564  bool is_durable, bool restart, bool recovery);
1565 
1566  /** Stop dirty page ID archiving.
1567  If other clients are there, the client is detached from the current group.
1568  @param[in] group page archive group the client is attached to
1569  @param[out] stop_lsn stop lsn for client
1570  @param[out] stop_pos stop position in archived data
1571  @param[in] is_durable true if client needs durable archiving
1572  @return error code */
1573  int stop(Arch_Group *group, lsn_t *stop_lsn, Arch_Page_Pos *stop_pos,
1574  bool is_durable);
1575 
1576  /** Start dirty page ID archiving during recovery.
1577  @param[in] group Group which needs to be attached to the archiver
1578  @param[in] new_empty_file true if there was a empty file created
1579  @return error code */
1580  int start_during_recovery(Arch_Group *group, bool new_empty_file);
1581 
1582  /** Release the current group from client.
1583  @param[in] group group the client is attached to
1584  @param[in] is_durable if client needs durable archiving
1585  @param[in] start_pos start position when the client calling the
1586  release was started */
1587  void release(Arch_Group *group, bool is_durable, Arch_Page_Pos start_pos);
1588 
1589  /** Check and add page ID to archived data.
1590  Check for duplicate page.
1591  @param[in] bpage page to track
1592  @param[in] track_lsn LSN when tracking started
1593  @param[in] frame_lsn current LSN of the page
1594  @param[in] force if true, add page ID without check */
1595  void track_page(buf_page_t *bpage, lsn_t track_lsn, lsn_t frame_lsn,
1596  bool force);
1597 
1598  /** Flush all the unflushed inactive blocks and flush the active block if
1599  required.
1600  @note Used only during the checkpointing process.
1601  @param[in] checkpoint_lsn next checkpoint LSN */
1602  void flush_at_checkpoint(lsn_t checkpoint_lsn);
1603 
1604  /** Archive dirty page IDs in current group.
1605  This interface is for archiver background task to flush page archive
1606  data to disk by calling it repeatedly over time.
1607  @param[out] wait true, if no more data to archive
1608  @return true, if archiving is aborted */
1609  bool archive(bool *wait);
1610 
1611  /** Acquire dirty page ID archiver mutex.
1612  It synchronizes concurrent start and stop operations by multiple clients. */
1614 
1615  /** Release page ID archiver mutex */
1617 
1618  /** Acquire dirty page ID archive operation mutex.
1619  It synchronizes concurrent page ID write to memory buffer. */
1621 
1622  /** Release page ID archiver operatiion mutex */
1624 
1625  /* Save information at the time of a reset considered as the reset point.
1626  @return error code */
1627  void save_reset_point(bool is_durable);
1628 
1629  /** Wait for reset info to be flushed to disk.
1630  @param[in] request_block block number until which blocks need to be
1631  flushed
1632  @return true if flushed, else false */
1633  bool wait_for_reset_info_flush(uint64_t request_block);
1634 
1635  /** Get the group which has tracked pages between the start_id and stop_id.
1636  @param[in,out] start_id start LSN from which tracked pages are
1637  required; updated to the actual start LSN used for the search
1638  @param[in,out] stop_id stop_lsn until when tracked pages are
1639  required; updated to the actual stop LSN used for the search
1640  @param[out] group group which has the required tracked
1641  pages, else nullptr.
1642  @return error */
1643  int fetch_group_within_lsn_range(lsn_t &start_id, lsn_t &stop_id,
1644  Arch_Group **group);
1645 
1646  /** Purge the archived files until the specified purge LSN.
1647  @param[in] purge_lsn purge lsn until where files needs to be purged
1648  @return error code
1649  @retval 0 if purge was successful */
1650  uint purge(lsn_t *purge_lsn);
1651 
1652  /** Update the stop point in all the required structures.
1653  @param[in] cur_blk block which needs to be updated with the stop info */
1654  void update_stop_info(Arch_Block *cur_blk);
1655 
1656  /** Fetch the status of the page tracking system.
1657  @param[out] status vector of a pair of (ID, bool) where ID is the
1658  start/stop point and bool is true if the ID is a start point else false */
1659  void get_status(std::vector<std::pair<lsn_t, bool>> &status) {
1660  for (auto group : m_group_list) {
1661  group->get_status(status);
1662  }
1663  }
1664 
1665  /** Given start and stop position find number of pages tracked between them
1666  @param[in] start_pos start position
1667  @param[in] stop_pos stop position
1668  @param[out] num_pages number of pages tracked between start and stop
1669  position
1670  @return false if start_pos and stop_pos are invalid else true */
1671  bool get_num_pages(Arch_Page_Pos start_pos, Arch_Page_Pos stop_pos,
1672  uint64_t &num_pages);
1673 
1674  /** Get approximate number of tracked pages between two given LSN values.
1675  @param[in,out] start_id fetch archived page Ids from this LSN
1676  @param[in,out] stop_id fetch archived page Ids until this LSN
1677  @param[out] num_pages number of pages tracked between specified
1678  LSN range
1679  @return error code */
1680  int get_num_pages(lsn_t &start_id, lsn_t &stop_id, uint64_t *num_pages);
1681 
1682  /** Get page IDs from a specific position.
1683  Caller must ensure that read_len doesn't exceed the block.
1684  @param[in] group group whose pages we're interested in
1685  @param[in] read_pos position in archived data
1686  @param[in] read_len amount of data to read
1687  @param[out] read_buff buffer to return the page IDs.
1688  @note Caller must allocate the buffer.
1689  @return true if we could successfully read the block. */
1690  bool get_pages(Arch_Group *group, Arch_Page_Pos *read_pos, uint read_len,
1691  byte *read_buff);
1692 
1693  /** Get archived page Ids between two given LSN values.
1694  Attempt to read blocks directly from in memory buffer. If overwritten,
1695  copy from archived files.
1696  @param[in] thd thread handle
1697  @param[in] cbk_func called repeatedly with page ID buffer
1698  @param[in] cbk_ctx callback function context
1699  @param[in,out] start_id fetch archived page Ids from this LSN
1700  @param[in,out] stop_id fetch archived page Ids until this LSN
1701  @param[in] buf buffer to fill page IDs
1702  @param[in] buf_len buffer length in bytes
1703  @return error code */
1704  int get_pages(MYSQL_THD thd, Page_Track_Callback cbk_func, void *cbk_ctx,
1705  lsn_t &start_id, lsn_t &stop_id, byte *buf, uint buf_len);
1706 
1707  /** Set the latest stop LSN to the checkpoint LSN at the time it's called. */
1708  void post_recovery_init();
1709 
1710  /** Recover the archiver system at the time of startup. Recover information
1711  related to all the durable groups and start archiving if any group was active
1712  at the time of crash/shutdown.
1713  @return error code */
1714  dberr_t recover();
1715 
1716 #ifdef UNIV_DEBUG
1717  /** Print information related to the archiver for debugging purposes. */
1718  void print();
1719 #endif
1720 
1721  /** Check if archiver system is in initial state
1722  @return true, if page ID archiver state is #ARCH_STATE_INIT */
1723  bool is_init() const { return (m_state == ARCH_STATE_INIT); }
1724 
1725  /** Check if archiver system is active
1726  @return true, if page ID archiver state is #ARCH_STATE_ACTIVE or
1727  #ARCH_STATE_PREPARE_IDLE. */
1728  bool is_active() const {
1730  }
1731 
1732  /** @return true if in abort state */
1733  bool is_abort() const { return (m_state == ARCH_STATE_ABORT); }
1734 
1735  /** Get the mutex protecting concurrent start, stop operations required
1736  for initialising group during recovery.
1737  @return mutex */
1738  ib_mutex_t *get_mutex() { return (&m_mutex); }
1739 
1740  /** @return operation mutex */
1741  ib_mutex_t *get_oper_mutex() { return (&m_oper_mutex); }
1742 
1743  /** Fetch the system client context.
1744  @return system client context. */
1746 
1747  /** @return the latest stop LSN */
1749 
1750  /** Disable copy construction */
1751  Arch_Page_Sys(Arch_Page_Sys const &) = delete;
1752 
1753  /** Disable assignment */
1754  Arch_Page_Sys &operator=(Arch_Page_Sys const &) = delete;
1755 
1756  class Recv;
1757 
1758  private:
1759  /** Wait for archive system to come out of #ARCH_STATE_PREPARE_IDLE.
1760  If the system is preparing to idle, #start needs to wait
1761  for it to come to idle state.
1762  @return true, if successful
1763  false, if needs to abort */
1764  bool wait_idle();
1765 
1766  /** Check if the gap from last reset is short.
1767  If not many page IDs are added till last reset, we avoid
1768  taking a new reset point
1769  @return true, if the gap is small. */
1770  bool is_gap_small();
1771 
1772  /** Enable tracking pages in all buffer pools.
1773  @param[in] tracking_lsn track pages from this LSN */
1774  void set_tracking_buf_pool(lsn_t tracking_lsn);
1775 
1776  /** Track pages for which IO is already started. */
1777  void track_initial_pages();
1778 
1779  /** Flush the blocks to disk.
1780  @param[out] wait true, if no more data to archive
1781  @return error code */
1782  dberr_t flush_blocks(bool *wait);
1783 
1784  /** Flush all the blocks which are ready to be flushed but not flushed.
1785  @param[out] cur_pos position of block which needs to be flushed
1786  @param[in] end_pos position of block until which the blocks need to
1787  be flushed
1788  @return error code */
1790 
1791  /** Do a partial flush of the current active block
1792  @param[in] cur_pos position of block which needs to be flushed
1793  @param[in] partial_reset_block_flush true if reset block needs to be
1794  flushed
1795  @return error code */
1797  bool partial_reset_block_flush);
1798 
1799  private:
1800  /** Mutex protecting concurrent start, stop operations */
1801  ib_mutex_t m_mutex;
1802 
1803  /** Archiver system state. */
1805 
1806  /** List of log archive groups */
1808 
1809  /** Position where last client started archiving */
1811 
1812  /** LSN when last client started archiving */
1814 
1815  /** Latest LSN until where the tracked pages have been flushed. */
1817 
1818  /** LSN until where the groups are purged. */
1820 
1821  /** Mutex protecting concurrent operation on data */
1822  ib_mutex_t m_oper_mutex;
1823 
1824  /** Current archive group */
1826 
1827  /** In memory data buffer */
1829 
1830  /** Position to add new page ID */
1832 
1833  /** Position to add new reset element */
1835 
1836  /** Position set to explicitly request the flush archiver to flush until
1837  this position.
1838  @note this is always increasing and is only updated by the requester thread
1839  like checkpoint */
1841 
1842  /** Block number set to explicitly request the flush archiver to partially
1843  flush the current active block with reset LSN.
1844  @note this is always increasing and is only updated by the requester thread
1845  like checkpoint */
1846  uint64_t m_request_blk_num_with_lsn{std::numeric_limits<uint64_t>::max()};
1847 
1848  /** Block number set once the flush archiver partially flushes the current
1849  active block with reset LSN.
1850  @note this is always increasing and is only updated by the requester thread
1851  like checkpoint */
1852  uint64_t m_flush_blk_num_with_lsn{std::numeric_limits<uint64_t>::max()};
1853 
1854  /** Position for start flushing
1855  @note this is always increasing and is only updated by the page archiver
1856  thread */
1858 
1859  /** The index of the file the last reset belonged to. */
1861 
1862  /** System client. */
1864 };
1865 
1866 /** Redo log archiver system global */
1867 extern Arch_Log_Sys *arch_log_sys;
1868 
1869 /** Dirty page ID archiver system global */
1871 
1872 #endif /* ARCH_ARCH_INCLUDE */
static bool is_zeroes(const byte *block)
Check if the block contains only zeroes.
Definition: arch0page.cc:1241
lsn_t purge(lsn_t begin_lsn, lsn_t end_lsn, lsn_t purge_lsn)
Purge archived files until the specified purge LSN.
Definition: arch0page.cc:812
~Arch_Page_Sys()
Destructor: Free memory buffer and mutexes.
Definition: arch0page.cc:1604
uint m_base_len
Fixed length part of the file.
Definition: arch0arch.h:794
uint64_t m_flush_blk_num_with_lsn
Block number set once the flush archiver partially flushes the current active block with reset LSN...
Definition: arch0arch.h:1852
void arch_oper_mutex_enter()
Acquire dirty page ID archive operation mutex.
Definition: arch0arch.h:1620
Arch_State m_state
Archiver system state.
Definition: arch0arch.h:1804
static bool validate(byte *block)
Check if the block data is valid.
Definition: arch0page.cc:1250
uint64_t get_phy_size() const
Get the physical size of a file that is open in this context.
Definition: arch0arch.h:637
ib_mutex_t * get_oper_mutex()
Definition: arch0arch.h:1741
Doublewrite buffer context.
Definition: arch0recv.h:82
const uint MAX_LSN_DECIMAL_DIGIT
Byte length for printing LSN.
Definition: arch0arch.h:67
Arch_State m_state
Archiver system state.
Definition: arch0arch.h:1475
uint m_file_index
Definition: arch0arch.h:307
bool is_durable() const
Check if any client requires durable archiving.
Definition: arch0arch.h:1084
bool validate_info_in_files()
Check if the information maintained in the memory is the same as the information maintained in the fi...
Definition: arch0page.cc:732
Arch_State check_set_state(bool is_abort, lsn_t *archived_lsn, uint *to_archive)
Check and set log archive system state and output the amount of redo log available for archiving...
Definition: arch0log.cc:493
void recovery_reset_print(uint file_start_index)
Print recovery related data.
Definition: arch0recv.cc:498
const uint MAX_ARCH_DIR_NAME_LEN
Max string length for archive group directory name.
Definition: arch0arch.h:80
uint get_file_count() const
Get the total number of archived files belonging to this group.
Definition: arch0arch.h:1068
dberr_t write(Arch_File_Ctx *from_file, byte *from_buffer, uint offset, uint size)
Write data to this file context from the given file offset.
Definition: arch0page.cc:464
Arch_Blk_Flush_Type
Archiver block flush type.
Definition: arch0arch.h:217
static lsn_t get_reset_lsn(byte *block)
Get the reset lsn stored in the block header.
Definition: arch0page.cc:1212
uint purge(lsn_t purge_lsn, lsn_t &purged_lsn)
Purge archived files until the specified purge LSN.
Definition: arch0page.cc:874
dberr_t flush_inactive_blocks(Arch_Page_Pos &cur_pos, Arch_Page_Pos end_pos)
Flush all the blocks which are ready to be flushed but not flushed.
Definition: arch0page.cc:2693
void update_block_header(lsn_t stop_lsn, lsn_t reset_lsn)
Definition: arch0page.cc:1268
Arch_Page_Sys * arch_page_sys
Dirty page ID archiver system global.
Definition: arch0arch.cc:39
uint64_t lsn_t
Type used for all log sequence number storage and arithmetics.
Definition: log0types.h:59
Arch_Blk_Type m_type
Type of block.
Definition: arch0arch.h:489
bool archive(bool *wait)
Archive dirty page IDs in current group.
Definition: arch0page.cc:2833
Archiving stopped by client.
Definition: arch0arch.h:121
atomic_lsn_t m_archived_lsn
System has archived log up to this LSN.
Definition: arch0arch.h:1478
int start_page_archiver_background()
Start page archiver background thread.
Definition: arch0arch.cc:525
bool is_closed() const
Check if file is closed.
Definition: arch0arch.h:599
void arch_mutex_exit()
Release redo log archiver mutex.
Definition: arch0arch.h:1425
Dirty page archiver client context.
Definition: arch0page.h:166
int wait_archive_complete(lsn_t target_lsn)
Wait for redo log archive up to the target LSN.
Definition: arch0log.cc:704
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
void update_header(byte *header, lsn_t checkpoint_lsn)
Update checkpoint LSN and related information in redo log header block.
Definition: arch0log.cc:206
std::vector< T, ut_allocator< T > > vector
Specialization of vector which uses ut_allocator.
Definition: ut0new.h:1281
lsn_t get_end_lsn() const
Definition: arch0arch.h:1193
lsn_t get_last_stop_point() const
Definition: arch0arch.h:732
Definition: arch0arch.h:213
os_event_t page_archiver_thread_event
Archiver thread event to signal that data is available.
Definition: arch0page.cc:48
Sparse file size information.
Definition: os0file.h:783
byte * m_data
Block data buffer.
Definition: arch0arch.h:474
const char ARCH_LOG_FILE[]
Archive log file prefix.
Definition: arch0arch.h:53
constexpr char ARCH_PAGE_GROUP_DURABLE_FILE_NAME[]
File name for the durable file which indicates whether a group was made durable or not...
Definition: arch0arch.h:63
Arch_Log_Sys * arch_log_sys
Redo log archiver system global.
Definition: arch0arch.cc:36
int start(Arch_Group **group, lsn_t *start_lsn, Arch_Page_Pos *start_pos, bool is_durable, bool restart, bool recovery)
Start dirty page ID archiving.
Definition: arch0page.cc:2356
Arch_Page_Sys & operator=(Arch_Page_Sys const &)=delete
Disable assignment.
uint m_header_len
Header length for the archived files.
Definition: arch0arch.h:1314
int start_log_archiver_background()
Start log archiver background thread.
Definition: arch0arch.cc:503
pthread_mutex_t mutex
Definition: memcached.c:384
Archiving started by client.
Definition: arch0arch.h:118
ArchPageData()
Constructor.
Definition: arch0arch.h:1502
uint64_t get_size() const
Get the logical size of a file.
Definition: arch0arch.h:625
bool archive(bool init, Arch_File_Ctx *curr_ctx, lsn_t *arch_lsn, bool *wait)
Archive accumulated redo log in current group.
Definition: arch0log.cc:786
bool m_is_active
If the group is active.
Definition: arch0arch.h:1274
bool operator<(Arch_Page_Pos pos)
Definition: arch0arch.h:283
const char * m_path_name
Fixed part of the path to file.
Definition: arch0arch.h:797
Arch_Grp_List::iterator Arch_Grp_List_Iter
An iterator for archive group.
Definition: arch0arch.h:1335
bool is_gap_small()
Check if the gap from last reset is short.
Definition: arch0page.cc:2165
Arch_Page_Pos m_reset_pos
Position to add new reset element.
Definition: arch0arch.h:1834
int read_data(Arch_Page_Pos cur_pos, byte *buff, uint buff_len)
Parse block for block info (header/data).
Definition: arch0page.cc:2960
lsn_t get_oldest_lsn() const
Get oldest LSN among the pages that are added to this block.
Definition: arch0arch.h:413
void add_reset(lsn_t reset_lsn, Arch_Page_Pos reset_pos)
Definition: arch0page.cc:1417
static Arch_File_Ctx s_dblwr_file_ctx
Doublewrite buffer file context.
Definition: arch0arch.h:1321
ib_mutex_t m_mutex
Mutex to protect concurrent start, stop operations.
Definition: arch0arch.h:1469
lsn_t get_stop_lsn() const
Definition: arch0arch.h:409
const uint MAX_ARCH_LOG_FILE_NAME_LEN
Max string length for archive log file name.
Definition: arch0arch.h:70
uint m_block_size
Block size in bytes.
Definition: arch0arch.h:1532
void adjust_end_lsn(lsn_t &stop_lsn, uint32_t &blk_len)
Adjust end LSN to end of file.
Definition: arch0log.cc:386
void force_abort()
Force to abort the archiver (state becomes ARCH_STATE_ABORT).
Definition: arch0log.cc:457
lsn_t get_latest_stop_lsn() const
Definition: arch0arch.h:1748
dberr_t recover()
Recover the archiver system at the time of startup.
Definition: arch0recv.cc:36
void arch_mutex_enter()
Acquire redo log archiver mutex.
Definition: arch0arch.h:1422
Arch_Page_Pos m_request_flush_pos
Position set to explicitly request the flush archiver to flush until this position.
Definition: arch0arch.h:1840
bool is_init() const
Check if block is initialised or not.
Definition: arch0arch.h:345
uint m_name_len
File name buffer length.
Definition: arch0arch.h:790
pfs_os_file_t m_active_file
File descriptor for a file required to indicate that the group was active at the time of crash during...
Definition: arch0arch.h:1283
uint m_index
File index within the archive group.
Definition: arch0arch.h:809
Arch_Block * m_reset_block
Reset block.
Definition: arch0arch.h:1526
static uint32_t get_checksum(byte *block)
Get the checksum stored in the block header.
Definition: arch0page.cc:1216
static uint64_t lsn
Definition: xcom_base.c:406
uint m_last_reset_file_index
The index of the file the last reset belonged to.
Definition: arch0arch.h:1860
char * m_name_buf
File name buffer.
Definition: arch0arch.h:787
uint purge(lsn_t *purge_lsn)
Purge the archived files until the specified purge LSN.
Definition: arch0page.cc:3113
Position in page ID archiving system.
Definition: arch0arch.h:270
Archiver is active and archiving data.
Definition: arch0arch.h:162
uint get_offset() const
Definition: arch0arch.h:629
lsn_t lsn
LSN of the point.
Definition: arch0arch.h:295
bool find_stop_point(Arch_Group *group, lsn_t check_lsn, Arch_Point &stop_point, Arch_Page_Pos last_pos)
Find the first stop LSN that is greater than the given LSN and fetch the stop point.
Definition: arch0page.cc:488
Arch_Group * m_current_group
Current archive group.
Definition: arch0arch.h:1825
dberr_t fetch_reset_points(uint file_index, Arch_Page_Pos &reset_pos)
Fetch the reset points pertaining to a file.
Definition: arch0recv.cc:616
uint64_t m_number
Unique block number.
Definition: arch0arch.h:486
uint m_count
Current number of files in the archive group.
Definition: arch0arch.h:812
const char ARCH_PAGE_DIR[]
Archive Page group directory prefix.
Definition: arch0arch.h:50
dberr_t open_file_during_recovery(Arch_Page_Pos write_pos, bool empty_file)
Open the file which was open at the time of a crash, during crash recovery, and set the file offset t...
Definition: arch0page.cc:350
Information of a group required for parsing information from the archived file.
Definition: arch0recv.h:41
uint detach(lsn_t stop_lsn, Arch_Page_Pos *stop_pos)
Detach a client when archiving is stopped by the client.
Definition: arch0arch.h:928
Arch_File_Ctx()
Constructor: Initialize members.
Definition: arch0arch.h:508
ib_uint64_t m_start_log_offset
System log file offset where the archiving started.
Definition: arch0arch.h:1493
uint get_data_len() const
Definition: arch0arch.h:403
void attach(bool is_durable)
Attach a client to the archive group.
Definition: arch0arch.h:909
void release(Arch_Group *group, bool is_durable, Arch_Page_Pos start_pos)
Release the current group from client.
Definition: arch0page.cc:2669
uint m_num_data_blocks
Total number of blocks.
Definition: arch0arch.h:1535
#define MYSQL_THD
Definition: backup_page_tracker.h:15
dberr_t recovery_replace_pages_from_dblwr(Arch_Dblwr_Ctx *dblwr_ctx)
Check and replace blocks in archived files belonging to a group from the doublewrite buffer if requir...
Definition: arch0recv.cc:234
void arch_remove_file(const char *file_path, const char *file_name)
Remove files related to page and log archiving.
Definition: arch0arch.cc:59
Redo log constants and functions.
dberr_t recovery_cleanup_if_required(uint &num_files, uint start_index, bool durable, bool &empty_file)
Delete the last file if there are no blocks flushed to it.
Definition: arch0recv.cc:308
void set_tracking_buf_pool(lsn_t tracking_lsn)
Enable tracking pages in all buffer pools.
Definition: arch0page.cc:2264
void build_dir_name(lsn_t dir_lsn, char *buffer, uint length)
Construct group directory name.
Definition: arch0arch.cc:492
bool is_active()
Check if archiving is in progress.
Definition: arch0arch.h:1362
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:519
uint64_t m_block_num
Unique block number.
Definition: arch0arch.h:278
Definition: arch0arch.h:232
void delete_files(lsn_t begin_lsn)
Delete all files for this archive group.
Definition: arch0arch.cc:266
dberr_t build_durable_file_name()
Construct file name for the durable file which indicates whether a group was made durable or not...
Definition: arch0page.cc:201
uint64_t get_file_size() const
Get file size for this group.
Definition: arch0arch.h:1186
std::deque< Arch_Reset_File > Arch_Reset
Definition: arch0arch.h:318
uint m_ref_count
Number of clients referencing the group.
Definition: arch0arch.h:1296
Definition: sync0types.h:380
uint64_t m_offset
Current file offset.
Definition: arch0arch.h:815
Arch_Group * m_current_group
Current archive group.
Definition: arch0arch.h:1484
void print()
Print information related to the archiver for debugging purposes.
Definition: arch0page.cc:3187
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:179
void close()
Close file, if open.
Definition: arch0arch.h:590
~Arch_File_Ctx()
Destructor: Close open file and free resources.
Definition: arch0arch.h:511
Arch_Page_Pos pos
Position of the point.
Definition: arch0arch.h:298
void recovery_fetch_info(Arch_Reset_File &reset_file, lsn_t &stop_lsn)
Fetch the last reset file and last stop point info during recovery.
Definition: arch0arch.h:712
char * m_durable_file_name
File name for the durable file which indicates whether a group was made durable or not...
Definition: arch0arch.h:1288
pfs_os_file_t m_file
Current file descriptor.
Definition: arch0arch.h:806
static const os_file_t OS_FILE_CLOSED
Definition: os0file.h:149
void save_reset_point_in_mem(lsn_t lsn, Arch_Page_Pos pos)
Update the reset information in the in-memory structure that we maintain for faster access...
Definition: arch0arch.h:1107
const char * m_dir_name
Directory name prefix.
Definition: arch0arch.h:800
bool read_only
Definition: mysqld.cc:1054
static uint64_t get_file_offset(uint64_t block_num, Arch_Blk_Type type)
Fetch the offset for a block in the archive file.
Definition: arch0page.cc:1220
lsn_t m_end_lsn
End lsn for this archive group.
Definition: arch0arch.h:1308
void set_next()
Position in the beginning of next block.
Definition: arch0page.cc:1473
int page
Definition: ctype-mb.cc:1231
void track_initial_pages()
Track pages for which IO is already started.
Definition: arch0page.cc:2188
dberr_t init_file_ctx(const char *path, const char *base_dir, const char *base_file, uint num_files, uint64_t file_size)
Initialize the file context for the archive group.
Definition: arch0arch.h:878
bool wait_idle()
Wait for archive system to come out of ARCH_STATE_PREPARE_IDLE.
Definition: arch0log.cc:655
Arch_Page_Pos m_write_pos
Position to add new page ID.
Definition: arch0arch.h:1831
Arch_Page_Dblwr_Offset
Page Archive doublewrite buffer block offsets.
Definition: arch0arch.h:227
bool get_data(Arch_Page_Pos *read_pos, uint read_len, byte *read_buff)
Copy page Ids from this block at read position to a buffer.
Definition: arch0page.cc:1347
char * pos
Definition: do_ctype.cc:76
static uint get_file_index(uint64_t block_num)
Get file index of the file the block belongs to.
Definition: arch0page.cc:1192
void copy_data(const Arch_Block *block)
Do a deep copy of the members of the block passed as the parameter.
Definition: arch0page.cc:1441
lsn_t get_begin_lsn() const
Get start LSN for this group.
Definition: arch0arch.h:1190
constexpr lsn_t LSN_MAX
Maximum possible lsn value is slightly higher than the maximum sn value, because lsn sequence enumera...
Definition: log0log.h:156
lsn_t fetch_reset_lsn(uint64_t block_num)
Fetch reset lsn of a particular reset point pertaining to a file.
Definition: arch0recv.cc:685
bool find_reset_point(lsn_t check_lsn, Arch_Point &reset_point)
Find the appropriate reset LSN that is less than or equal to the given lsn and fetch the reset point...
Definition: arch0page.cc:411
void arch_free()
Free Page and Log archiver system.
Definition: arch0arch.cc:144
Definition: arch0arch.h:235
dberr_t fetch_stop_points(bool last_file, Arch_Page_Pos &write_pos)
Fetch the stop lsn pertaining to a file.
Definition: arch0recv.cc:586
dberr_t open_next(lsn_t start_lsn, uint64_t file_offset)
Open next file for read.
Definition: arch0arch.cc:397
static uint64_t get_block_number(byte *block)
Get the block number from the block header.
Definition: arch0page.cc:1208
Archiver is idle.
Definition: arch0arch.h:168
uint m_offset
Offset within a block.
Definition: arch0arch.h:281
Archiver is processing last data chunks before idle state.
Definition: arch0arch.h:165
Archiver is aborted.
Definition: arch0arch.h:171
#define mutex_free(M)
Definition: ut0mutex.h:124
bool is_abort() const
Definition: arch0arch.h:1733
int start_during_recovery(Arch_Group *group, bool new_empty_file)
Start dirty page ID archiving during recovery.
Definition: arch0page.cc:2282
bool is_flushable() const
Check if the block can be flushed or not.
Definition: arch0arch.h:350
bool init()
Allocate buffer and initialize blocks.
Definition: arch0page.cc:1480
lsn_t m_begin_lsn
Start LSN for the archive group.
Definition: arch0arch.h:1305
int mark_durable()
Mark the group durable by creating a file in the respective group directory.
Definition: arch0page.cc:256
Dirty page archive system.
Definition: arch0arch.h:1545
bool is_durable_client_active() const
Check if any client requiring durable archiving is active.
Definition: arch0arch.h:1078
ib_mutex_t * get_mutex()
Get the mutex protecting concurrent start, stop operations required for initialising group during rec...
Definition: arch0arch.h:1738
bool is_active() const
Definition: arch0arch.h:347
void recovery_fetch_info(Arch_Reset_File &reset_file, lsn_t &stop_lsn)
Fetch the last reset file and last stop point info during recovery.
Definition: arch0arch.h:1149
Arch_Log_Sys & operator=(Arch_Log_Sys const &)=delete
Disable assignment.
void arch_mutex_enter()
Acquire dirty page ID archiver mutex.
Definition: arch0arch.h:1613
bool wait_idle()
Wait for archive system to come out of ARCH_STATE_PREPARE_IDLE.
Definition: arch0page.cc:2116
bool validate_stop_point_in_file(Arch_Group *group, pfs_os_file_t file, uint file_index)
Check if the stop LSN maintained in the memory is the same as the information maintained in the files...
Definition: arch0page.cc:583
dberr_t
Definition: db0err.h:38
Data block is active and having data.
Definition: arch0arch.h:198
void post_recovery_init()
Set the latest stop LSN to the checkpoint LSN at the time it&#39;s called.
Definition: arch0page.cc:1621
bool delete_file(uint file_index, lsn_t begin_lsn)
Delete a single file belonging to the specified file index.
Definition: arch0arch.cc:244
void arch_oper_mutex_exit()
Release page ID archiver operatiion mutex.
Definition: arch0arch.h:1623
#define os_file_close(file)
Definition: os0file.h:1531
static char * path
Definition: mysqldump.cc:125
uint64_t m_request_blk_num_with_lsn
Block number set to explicitly request the flush archiver to partially flush the current active block...
Definition: arch0arch.h:1846
void get_status(std::vector< std::pair< lsn_t, bool >> &status)
Fetch the status of the page tracking system.
Definition: arch0arch.h:723
const char ARCH_PAGE_FILE[]
Archive page file prefix.
Definition: arch0arch.h:56
uint64_t bytes_left() const
Check how much is left in current file.
Definition: arch0arch.h:603
constexpr uint ARCH_PAGE_BLK_SIZE
Memory block size.
Definition: arch0arch.h:90
dberr_t copy_log(Arch_File_Ctx *file_ctx, uint length)
Copy redo log from file context to archiver files.
Definition: arch0log.cc:598
Archive doublewrite buffer page offset for RESET page.
Definition: arch0arch.h:229
unsigned int uint
Definition: uca-dump.cc:29
bool wait_for_reset_info_flush(uint64_t request_block)
Wait for reset info to be flushed to disk.
Definition: arch0page.cc:3043
int mark_inactive()
Mark the group inactive by deleting the &#39;active&#39; file.
Definition: arch0page.cc:292
bool get_pages(Arch_Group *group, Arch_Page_Pos *read_pos, uint read_len, byte *read_buff)
Get page IDs from a specific position.
Definition: arch0page.cc:1817
Arch_Blk_State
Archived data block state.
Definition: arch0arch.h:193
void release(Arch_Group *group, bool is_durable)
Release the current group from client.
Definition: arch0log.cc:466
Arch_File_Ctx m_file_ctx
Archive file context.
Definition: arch0arch.h:1317
void get_file_name(uint idx, char *name_buf, uint buf_len)
Get archived file name at specific index in this group.
Definition: arch0arch.h:1176
Arch_Reset m_reset
Queue of file structure holding reset information pertaining to their respective files in a group...
Definition: arch0arch.h:824
static dberr_t write_to_doublewrite_file(Arch_File_Ctx *from_file, byte *from_buffer, uint write_size, Arch_Page_Dblwr_Offset offset)
Write to the doublewrite buffer before writing archived data to a file.
Definition: arch0page.cc:112
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:53
void recovery_reset_print(uint file_start_index)
Print recovery related data.
Definition: arch0arch.h:1156
~Arch_Group()
Destructor: Delete all files for non-durable archiving.
Definition: arch0page.cc:86
dberr_t write_file_header(byte *from_buffer, uint length)
Write the header (RESET page) to an archived file.
Definition: arch0page.cc:328
int stop(Arch_Group *group, lsn_t &stop_lsn, byte *log_blk, uint32_t &blk_len)
Stop redo log archiving.
Definition: arch0log.cc:408
Data block is initialized.
Definition: arch0arch.h:195
int stop(Arch_Group *group, lsn_t *stop_lsn, Arch_Page_Pos *stop_pos, bool is_durable)
Stop dirty page ID archiving.
Definition: arch0page.cc:2591
bool add_page(buf_page_t *page, Arch_Page_Pos *pos)
Add page ID to current block.
Definition: arch0page.cc:1311
Page_Arch_Client_Ctx * get_sys_client() const
Fetch the system client context.
Definition: arch0arch.h:1745
Arch_Client_State
Archiver client state.
Definition: arch0arch.h:113
Arch_Page_Pos m_last_pos
Position where last client started archiving.
Definition: arch0arch.h:1810
dberr_t build_active_file_name()
Construct file name for the active file which indicates whether a group is active or not...
Definition: arch0page.cc:179
lsn_t m_stop_lsn
Checkpoint lsn at the time the last page ID was added to the block.
Definition: arch0arch.h:493
void set_flushed()
Set current block flushed.
Definition: arch0arch.h:354
bool is_referenced() const
Check if any client (durable or not) is attached to the archiver.
Definition: arch0arch.h:1072
dberr_t read(byte *to_buffer, const uint offset, const uint size)
Read data from the current file that is open.
Definition: arch0arch.cc:412
void update_stop_point(Arch_Page_Pos pos, lsn_t stop_lsn)
Update stop lsn of a file in the group.
Definition: arch0arch.h:1114
dberr_t arch_init()
Initialize Page and Log archiver system.
Definition: arch0arch.cc:117
Arch_Group & operator=(Arch_Group const &)=delete
Disable assignment.
bool validate(Arch_Group *group, uint file_index, lsn_t start_lsn, uint &reset_count)
Check if the information maintained in the memory is the same as the information maintained in the fi...
Definition: arch0page.cc:759
lsn_t m_last_lsn
LSN when last client started archiving.
Definition: arch0arch.h:1813
dberr_t write_to_file(Arch_File_Ctx *from_file, byte *from_buffer, uint length, bool partial_write, bool do_persist)
Archive data to one or more files.
Definition: arch0arch.cc:160
uint m_data_len
Block data length in bytes.
Definition: arch0arch.h:477
const char ARCH_LOG_DIR[]
Archive Log group directory prefix.
Definition: arch0arch.h:47
Page archiver in memory data.
Definition: arch0arch.h:1500
Policy based mutexes.
std::vector< Arch_Point > m_start_point
Definition: arch0arch.h:314
uint m_start_log_index
System log file number where the archiving started.
Definition: arch0arch.h:1490
void arch_mutex_exit()
Release page ID archiver mutex.
Definition: arch0arch.h:1616
Client is initialized.
Definition: arch0arch.h:115
bool get_num_pages(Arch_Page_Pos start_pos, Arch_Page_Pos stop_pos, uint64_t &num_pages)
Given start and stop position find number of pages tracked between them.
Definition: arch0page.cc:1994
void release(bool is_durable)
Release the archive group from a client.
Definition: arch0arch.h:948
void save_reset_point(bool is_durable)
Definition: arch0page.cc:2974
lsn_t get_archived_lsn()
Get LSN up to which redo is archived.
Definition: arch0arch.h:1372
Definition: buf0buf.h:1161
ib_mutex_t * m_arch_mutex
Mutex protecting concurrent operations by multiple clients.
Definition: arch0arch.h:1327
Archiver file context.
Definition: arch0arch.h:505
void flush_at_checkpoint(lsn_t checkpoint_lsn)
Flush all the unflushed inactive blocks and flush the active block if required.
Definition: arch0page.cc:1633
ib_mutex_t m_oper_mutex
Mutex protecting concurrent operation on data.
Definition: arch0arch.h:1822
lsn_t m_latest_stop_lsn
Latest LSN until where the tracked pages have been flushed.
Definition: arch0arch.h:1816
#define os_file_flush(file)
Definition: os0file.h:1553
Arch_Group * get_arch_group()
Get current redo log archive group.
Definition: arch0arch.h:1376
bool is_active() const
Check if archiver system is active.
Definition: arch0arch.h:1728
int read_from_file(Arch_Page_Pos *read_pos, uint read_len, byte *read_buff)
Get page IDs from archived file.
Definition: arch0page.cc:2910
pfs_os_file_t m_durable_file
File descriptor for a file to indicate that the group was made durable or not.
Definition: arch0arch.h:1293
std::vector< Arch_Block *, ut_allocator< Arch_Block * > > Arch_Block_Vec
Vector of page archive in memory blocks.
Definition: arch0arch.h:1497
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:65
In memory data block in Page ID archiving system.
Definition: arch0arch.h:321
os_file_t m_file
Definition: os0file.h:146
void flush()
Flush file.
Definition: arch0arch.h:583
dberr_t flush(Arch_Group *file_group, Arch_Blk_Flush_Type type)
Flush this block to the file group.
Definition: arch0page.cc:1378
os_event_t log_archiver_thread_event
Archiver thread event to signal that data is available.
Definition: arch0arch.cc:42
void save_reset_point_in_mem(lsn_t lsn, Arch_Page_Pos pos)
Update the reset information in the in-memory structure that we maintain for faster access...
Definition: arch0page.cc:384
dberr_t open_new(lsn_t start_lsn, uint64_t file_offset)
Add a new file and open.
Definition: arch0arch.cc:382
bool set_data(uint read_len, byte *read_buff, uint read_offset)
Copy page Ids from a buffer to this block.
Definition: arch0page.cc:1363
void clean()
Delete blocks and buffer.
Definition: arch0page.cc:1547
int fetch_group_within_lsn_range(lsn_t &start_id, lsn_t &stop_id, Arch_Group **group)
Get the group which has tracked pages between the start_id and stop_id.
Definition: arch0page.cc:3060
uint64_t m_size
File size limit in bytes.
Definition: arch0arch.h:818
int type
Definition: http_common.h:411
Structure which represents a point in a file.
Definition: arch0arch.h:293
byte * m_buffer
In memory buffer.
Definition: arch0arch.h:1538
Arch_Block * m_partial_flush_block
Temporary block used to copy active block for partial flush.
Definition: arch0arch.h:1529
Arch_Block_Vec m_data_blocks
Vector of data blocks.
Definition: arch0arch.h:1523
static size_t file_size
Definition: mysql_config_editor.cc:70
#define mutex_enter(M)
Definition: ut0mutex.h:115
lsn_t m_lsn
Definition: arch0arch.h:311
void begin_write(Arch_Page_Pos pos)
Set the block ready to begin writing page ID.
Definition: arch0page.cc:1285
Definition: arch0arch.h:302
Flush partial block.
Definition: arch0arch.h:223
Arch_State
Archiver system state.
Definition: arch0arch.h:157
Arch_Block(byte *blk_buf, uint size, Arch_Blk_Type type)
Constructor: Initialize elements.
Definition: arch0arch.h:327
Page_Arch_Client_Ctx * m_ctx
System client.
Definition: arch0arch.h:1863
std::vector< lsn_t > m_stop_points
Vector of stop points corresponding to a file.
Definition: arch0arch.h:832
Data block is flushed and can be reused.
Definition: arch0arch.h:204
Arch_Block * get_partial_flush_block() const
Definition: arch0arch.h:1518
void init()
Initialize a position.
Definition: arch0page.cc:1467
Common file descriptor for file IO instrumentation with PFS on windows and other platforms.
Definition: os0file.h:136
uint m_size
Total block size in bytes.
Definition: arch0arch.h:480
Arch_Page_Pos m_stop_pos
Stop position of the group, if it&#39;s not active.
Definition: arch0arch.h:1311
bool is_init() const
Check if archiver system is in initial state.
Definition: arch0arch.h:1723
void arch_remove_dir(const char *dir_path, const char *dir_name)
Remove group directory and the files related to page and log archiving.
Definition: arch0arch.cc:89
#define mutex_exit(M)
Definition: ut0mutex.h:122
const char * m_file_name
File name prefix.
Definition: arch0arch.h:803
void page_archiver_thread()
Page archiver background thread.
Definition: arch0page.cc:51
Arch_Grp_List m_group_list
List of log archive groups.
Definition: arch0arch.h:1481
uint m_num_active
Number of clients for which archiving is in progress.
Definition: arch0arch.h:1302
dberr_t recovery_parse(Arch_Page_Pos &write_pos, Arch_Page_Pos &reset_pos, size_t start_index)
Start parsing the archive file for archive group information.
Definition: arch0recv.cc:539
Arch_Page_Pos m_flush_pos
Position for start flushing.
Definition: arch0arch.h:1857
static void shutdown()
Operations to be done at the time of shutdown.
Definition: arch0arch.h:1099
#define ut_free(ptr)
Definition: ut0new.h:1097
InnoDB condition variable.
Definition: os0event.cc:66
Archiver is initialized.
Definition: arch0arch.h:159
void get_status(std::vector< std::pair< lsn_t, bool >> &status)
Fetch the status of the page tracking system.
Definition: arch0arch.h:1201
bool find_reset_point(lsn_t check_lsn, Arch_Point &reset_point)
Find the appropriate reset LSN that is less than or equal to the given lsn and fetch the reset point...
Definition: arch0arch.h:1031
void update_stop_info(Arch_Block *cur_blk)
Update the stop point in all the required structures.
Definition: arch0page.cc:3174
void get_dir_name(char *name_buf, uint buf_len)
Get the directory name for this archive group.
Definition: arch0arch.h:1228
uint64_t get_number() const
Definition: arch0arch.h:406
bool arch_wake_threads()
Wakes up archiver threads.
Definition: arch0arch.cc:46
dberr_t open(bool read_only, lsn_t start_lsn, uint file_index, uint64_t file_offset)
Open a file at specific index.
Definition: arch0arch.cc:335
Arch_Page_Sys()
Constructor: Initialize elements and create mutex.
Definition: arch0page.cc:1592
void update_stop_point(uint file_index, lsn_t stop_lsn)
Update stop lsn of a file in the group.
Definition: arch0page.cc:374
Flush when block is full.
Definition: arch0arch.h:219
Arch_Block * get_block(Arch_Page_Pos *pos, Arch_Blk_Type type)
Get the block for a position.
Definition: arch0page.cc:1572
uint m_dur_ref_count
Number of clients referencing for durable archiving.
Definition: arch0arch.h:1299
void read(Arch_Group *group, uint64_t offset)
Definition: arch0page.cc:1453
dberr_t recovery_read_latest_blocks(byte *buf, uint64_t offset, Arch_Blk_Type type)
Reads the latest data block and reset block.
Definition: arch0recv.cc:708
void set_data_len(uint data_len)
Set the data length of the block.
Definition: arch0arch.h:400
void attach_during_recovery()
Attach system client to the archiver during recovery if any group was active at the time of crash...
Definition: arch0arch.h:1088
Arch_Blk_Type
Archiver block type.
Definition: arch0arch.h:208
ArchPageData m_data
In memory data buffer.
Definition: arch0arch.h:1828
void log_archiver_thread()
Log archiver background thread.
Definition: arch0arch.cc:548
bool is_active() const
Check if archiving is going on for this group.
Definition: arch0arch.h:991
Arch_Blk_State get_state() const
Get current state of the block.
Definition: arch0arch.h:417
#define OS_FILE_PREFIX
Prefix all files and directory created under data directory with special string so that it never conf...
Definition: os0file.h:65
Data block is full but not flushed to disk.
Definition: arch0arch.h:201
Arch_Page_Pos get_stop_pos() const
Definition: arch0arch.h:1196
static STATUS status
Definition: mysql.cc:193
ib_mutex_t m_mutex
Mutex protecting concurrent start, stop operations.
Definition: arch0arch.h:1801
~Arch_Log_Sys()
Destructor: Free mutex.
Definition: arch0arch.h:1350
#define mutex_create(I, M)
Definition: ut0mutex.h:113
os_file_size_t os_file_get_size(const char *filename)
Gets a file size.
Definition: os0file.cc:3464
Contiguous archived data for redo log or page tracking.
Definition: arch0arch.h:838
lsn_t m_reset_lsn
Start LSN or the last reset LSN of the group.
Definition: arch0arch.h:500
const uint MAX_ARCH_PAGE_FILE_NAME_LEN
Max string length for archive page file name.
Definition: arch0arch.h:75
#define mutex_own(M)
Checks that the current thread owns the mutex.
Definition: ut0mutex.h:156
static uint get_type(byte *block)
Get block type from the block header.
Definition: arch0page.cc:1196
dberr_t flush_blocks(bool *wait)
Flush the blocks to disk.
Definition: arch0page.cc:2773
bool validate_reset_block_in_file(pfs_os_file_t file, uint file_index, uint &reset_count)
Check if the reset information maintained in the memory is the same as the information maintained in ...
Definition: arch0page.cc:636
unsigned char byte
Blob class.
Definition: common.h:159
const char ARCH_DIR[]
Archive directory prefix.
Definition: arch0arch.h:44
static dberr_t init_dblwr_file_ctx(const char *path, const char *base_file, uint num_files, uint64_t file_size)
Initialize the doublewrite buffer file context for the archive group.
Definition: arch0page.cc:147
bool find_stop_point(lsn_t check_lsn, Arch_Point &stop_point, Arch_Page_Pos write_pos)
Find the first stop LSN that is greater than the given LSN and fetch the stop point.
Definition: arch0arch.h:1041
Redo log archiving system.
Definition: arch0arch.h:1338
void init()
Definition: arch0page.cc:78
uint m_chunk_size
Chunk size to copy redo data.
Definition: arch0arch.h:1487
dberr_t init(const char *path, const char *base_dir, const char *base_file, uint num_files, uint64_t file_size)
Initializes archiver file context.
Definition: arch0arch.cc:281
Arch_Blk_State m_state
State of the block.
Definition: arch0arch.h:483
std::atomic< lsn_t > atomic_lsn_t
Alias for atomic based on lsn_t.
Definition: log0types.h:65
int mark_active()
Mark the group active by creating a file in the respective group directory.
Definition: arch0page.cc:223
lsn_t m_latest_purged_lsn
LSN until where the groups are purged.
Definition: arch0arch.h:1819
void close_file_ctxs()
Definition: arch0arch.h:885
Arch_Log_Sys()
Constructor: Initialize members.
Definition: arch0arch.h:1341
void end_write()
End writing to a block.
Definition: arch0page.cc:1304
char * m_active_file_name
To know which group was active at the time of a crash/shutdown during recovery we create an empty fil...
Definition: arch0arch.h:1279
void disable(lsn_t end_lsn)
Mark archive group inactive.
Definition: arch0arch.h:898
bool restart(THD *thd)
Initialize the dictionary while restarting the server.
Definition: bootstrapper.cc:902
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
lsn_t m_oldest_lsn
Oldest LSN of all the page IDs added to the block since the last checkpoint.
Definition: arch0arch.h:497
std::list< Arch_Group *, ut_allocator< Arch_Group * > > Arch_Grp_List
A list of archive groups.
Definition: arch0arch.h:1332
bool is_init()
Check if archiver system is in initial state.
Definition: arch0arch.h:1368
uint get_count() const
Get number of files.
Definition: arch0arch.h:633
Arch_Group(lsn_t start_lsn, uint header_len, ib_mutex_t *mutex)
Constructor: Initialize members.
Definition: arch0arch.h:844
void get_status(std::vector< std::pair< lsn_t, bool >> &status)
Fetch the status of the page tracking system.
Definition: arch0arch.h:1659
void adjust_copy_length(uint32_t &length)
Adjust redo copy length to end of file.
void build_name(uint idx, lsn_t dir_lsn, char *buffer, uint length)
Construct file name at specific index.
Definition: arch0arch.cc:460
dberr_t recover(Arch_Recv_Group_Info *group_info, bool &new_empty_file, Arch_Dblwr_Ctx *dblwr_ctx, Arch_Page_Pos &write_pos, Arch_Page_Pos &reset_pos)
Recover the information belonging to this group from the archived files.
Definition: arch0recv.cc:433
dberr_t flush_active_block(Arch_Page_Pos cur_pos, bool partial_reset_block_flush)
Do a partial flush of the current active block.
Definition: arch0page.cc:2723
void track_page(buf_page_t *bpage, lsn_t track_lsn, lsn_t frame_lsn, bool force)
Check and add page ID to archived data.
Definition: arch0page.cc:1714
int(* Page_Track_Callback)(MYSQL_THD thd, const unsigned char *buffer, size_t buf_len, int num_pages, void *user_ctx)
Page tracking callback function.
Definition: page_track_service.h:55
int start(Arch_Group *&group, lsn_t &start_lsn, byte *header, bool is_durable)
Start redo log archiving.
Definition: arch0log.cc:259
Arch_Grp_List m_group_list
List of log archive groups.
Definition: arch0arch.h:1807
Definition: arch0arch.h:210