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