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