MySQL 8.0.31
Source Code Documentation
clone0snapshot.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2022, 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/clone0snapshot.h
28 Database Physical Snapshot
29
30 *******************************************************/
31
32#ifndef CLONE_SNAPSHOT_INCLUDE
33#define CLONE_SNAPSHOT_INCLUDE
34
35#include "univ.i"
36
37#include "arch0log.h"
38#include "arch0page.h"
39#include "clone0api.h"
40#include "clone0desc.h"
41#include "clone0monitor.h"
42#include "fil0fil.h"
43#include "sql/handler.h"
44
45#include <map>
46#include <vector>
47
49 /** File state:
50 [CREATED] -------------> [DROPPING] --> [DROPPED] --> [DROPPED_HANDLED]
51 | ^
52 | |
53 ----> [RENAMING] -> [RENAMED]
54 | |
55 <------------
56 */
57 enum class State {
58 /* Invalid state. */
59 NONE,
60 /* File is being dropped. */
62 /* File is being renamed. */
64 /* Newly created file or pre-existing before clone. */
65 CREATED,
66 /* File is renamed during clone. */
67 RENAMED,
68 /* File is deleted during clone. */
69 DROPPED,
70 /* File is deleted and chunk information is handled. */
72 };
73
74 /** File extension to use with name. */
75 enum class Extension {
76 /* No extension. */
77 NONE,
78 /* Replace extension - clone file to be replaced during recovery. */
79 REPLACE,
80 /* DDL extension - temporary extension used during rename. */
81 DDL
82 };
83
84 /** Initialize file state.
85 @param[in] extn file name extension */
86 void init(Extension extn) {
88 m_extension = extn;
89
90 m_pin.store(0);
91 m_modified_ddl = false;
92 m_waiting = 0;
93
95
96 m_meta.init();
97 }
98
99 /** Get file name with extension.
100 @param[out] name file name. */
101 void get_file_name(std::string &name) const;
102
103 /** Mark file added by DDL.
104 @param[in] next_state next snapshot state */
105 void set_ddl(Snapshot_State next_state) {
106 m_modified_ddl = true;
107 m_next_state = next_state;
108 }
109
110 /** @return true iff added or modified by ddl in previous state.
111 @param[in] state current snapshot state */
112 bool by_ddl(Snapshot_State state) const {
113 return m_modified_ddl && (state <= m_next_state);
114 }
115
116 /** Start waiting for DDL */
117 void begin_wait() { ++m_waiting; }
118
119 /** Finish waiting for DDL */
120 void end_wait() {
121 ut_a(m_waiting > 0);
122 --m_waiting;
123 }
124
125 /** @return true, iff there are waiting clone tasks. */
126 bool is_waiting() const { return (m_waiting > 0); }
127
128 /** Pin the file. */
129 void pin() { ++m_pin; }
130
131 /** Unpin the file. */
132 void unpin() {
133 ut_a(m_pin > 0);
134 --m_pin;
135 }
136
137 /** @return true, iff clone tasks are using the file. */
138 bool is_pinned() const { return (m_pin.load() > 0); }
139
140 /** @return true, iff DDL is modifying file. */
141 bool modifying() const {
142 State state = m_state.load();
143 return (state == State::RENAMING || state == State::DROPPING);
144 }
145
146 /** @return true, iff DDL is deleting file. */
147 bool deleting() const {
148 State state = m_state.load();
149 return (state == State::DROPPING);
150 }
151
152 /** @return true, iff file is already deleted. */
153 bool deleted() const {
154 State state = m_state.load();
155 return (state == State::DROPPED || state == State::DROPPED_HANDLED);
156 }
157
158 /** @return true, iff file is already renamed. */
159 bool renamed() const {
160 State state = m_state.load();
161 return (state == State::RENAMED);
162 }
163
164 /** @return file metadata. */
166
167 /** @return file metadata for read. */
168 const Clone_File_Meta *get_file_meta_read() const { return &m_meta; }
169
170 /** File metadata state. Modified by DDL commands. Protected by snapshot
171 mutex. Atomic operation helps clone to skip mutex when no ddl. */
172 std::atomic<State> m_state;
173
174 /** File name extension. */
176
177 private:
178 /** Pin count incremented and decremented by clone tasks to synchronize with
179 concurrent DDL. Protected by snapshot mutex. */
180 std::atomic<uint32_t> m_pin;
181
182 /** Waiting count incremented and decremented by clone tasks while waiting
183 DDL file operation in progress. Protected by snapshot mutex. */
184 uint32_t m_waiting;
185
186 /** true, if file created or modified after clone is started. */
187 bool m_modified_ddl{false};
188
189 /** Next state when ddl last modified file. */
191
192 /** File metadata. */
194};
195
196/** Vector type for storing clone files */
197using Clone_File_Vec = std::vector<Clone_file_ctx *>;
198
199/** Map type for mapping space ID to clone file index */
200using Clone_File_Map = std::map<space_id_t, uint>;
201
202/** Page identified by space and page number */
204 /** Tablespace ID */
205 uint32_t m_space_id;
206
207 /** Page number within tablespace */
208 uint32_t m_page_no;
209};
210
211/** Comparator for storing sorted page ID. */
213 /** Less than operator for page ID.
214 @param[in] page1 first page
215 @param[in] page2 second page
216 @return true, if page1 is less than page2 */
217 inline bool operator()(const Clone_Page &page1,
218 const Clone_Page &page2) const {
219 if (page1.m_space_id < page2.m_space_id) {
220 return (true);
221 }
222
223 if (page1.m_space_id == page2.m_space_id &&
224 page1.m_page_no < page2.m_page_no) {
225 return (true);
226 }
227 return (false);
228 }
229};
230
231/** Vector type for storing clone page IDs */
232using Clone_Page_Vec = std::vector<Clone_Page>;
233
234/** Set for storing unique page IDs. */
235using Clone_Page_Set = std::set<Clone_Page, Less_Clone_Page>;
236
237/** Clone handle type */
239 /** Clone Handle for COPY */
241
242 /** Clone Handle for APPLY */
245
246/** Default chunk size in power of 2 in unit of pages.
247Chunks are reserved by each thread for multi-threaded clone. For 16k page
248size, chunk size is 64M. */
250
251/** Default block size in power of 2 in unit of pages.
252Data transfer callback is invoked once for each block. This is also
253the maximum size of data that would be re-send if clone is stopped
254and resumed. For 16k page size, block size is 1M. */
256
257/** Maximum block size in power of 2 in unit of pages.
258For 16k page size, maximum block size is 64M. */
260
261/** Dynamic database snapshot: Holds metadata and handle to data */
263 public:
264 /** RAII style guard for begin & end of snapshot state transition. */
266 public:
267 /** Constructor to begin state transition.
268 @param[in,out] snapshot Clone Snapshot
269 @param[in] new_state State to transit */
270 explicit State_transit(Clone_Snapshot *snapshot, Snapshot_State new_state);
271
272 /** Destructor to end state transition. */
274
275 /** @return error code */
276 int get_error() const { return m_error; }
277
278 /** Disable copy construction */
279 State_transit(State_transit const &) = delete;
280
281 /** Disable assignment */
283
284 private:
285 /** Clone Snapshot */
287
288 /** Saved error while beginning transition. */
290 };
291
292 /** Construct snapshot
293 @param[in] hdl_type copy, apply
294 @param[in] clone_type clone type
295 @param[in] arr_idx index in global array
296 @param[in] snap_id unique snapshot ID */
298 uint arr_idx, uint64_t snap_id);
299
300 /** Release contexts and free heap */
302
303 /** DDL notification before the operation.
304 @param[in] type type of DDL notification
305 @param[in] space space ID for the ddl operation
306 @param[in] no_wait return with error if needs to wait
307 @param[in] check_intr check for interrupt during wait
308 @param[out] error mysql error code
309 @return true iff clone state change is blocked. */
310 bool begin_ddl_state(Clone_notify::Type type, space_id_t space, bool no_wait,
311 bool check_intr, int &error);
312
313 /** DDL notification after the operation.
314 @param[in] type type of DDL notification
315 @param[in] space space ID for the ddl operation */
317
318 /** Wait for concurrent DDL file operation and pin file.
319 @param[in,out] file_ctx file context
320 @param[out] handle_delete if caller needs to handle deleted state
321 @return mysql error code. */
322 int pin_file(Clone_file_ctx *file_ctx, bool &handle_delete);
323
324 /** Unpin a file.
325 @param[in,out] file_ctx file context */
326 void unpin_file(Clone_file_ctx *file_ctx) { file_ctx->unpin(); }
327
328 /** Check if DDL needs to block clone operation.
329 @param[in] file_ctx file context
330 @return true iff clone operation needs to be blocked. */
331 bool blocks_clone(const Clone_file_ctx *file_ctx);
332
333 /** @return estimated bytes on disk */
334 uint64_t get_disk_estimate() const { return (m_data_bytes_disk); }
335
336 /** Get unique snapshot identifier
337 @return snapshot ID */
338 uint64_t get_id() { return (m_snapshot_id); }
339
340 /** Get snapshot index in global array
341 @return array index */
343
344 /** Get performance schema accounting object used to monitor stage
345 progress.
346 @return PFS stage object */
348
349 /** Get snapshot heap used for allocation during clone.
350 @return heap */
353 return (m_snapshot_heap);
354 }
355
356 /* Release snapshot heap */
358 heap = nullptr;
360 }
361
362 /** Get snapshot state
363 @return state */
365
366 /** Get the redo file size for the snapshot
367 @return redo file size */
368 uint64_t get_redo_file_size() { return (m_redo_file_size); }
369
370 /** Get total number of chunks for current state
371 @return number of data chunks */
373
374 /** Get maximum file length seen till now
375 @return file name length */
377
378 /** Get maximum buffer size required for clone
379 @return maximum dynamic buffer */
381 uint ret_len = 0;
382
384 ret_len = static_cast<uint>(2 * UNIV_PAGE_SIZE);
385 }
386
387 return (ret_len);
388 }
389
390 using File_Cbk_Func = std::function<int(Clone_file_ctx *)>;
391
392 /** Iterate through all files in current state
393 @param[in] func callback function
394 @return error code */
395 int iterate_files(File_Cbk_Func &&func);
396
397 /** Iterate through all data files
398 @param[in] func callback function
399 @return error code */
401
402 /** Iterate through all redo files
403 @param[in] func callback function
404 @return error code */
406
407 /** Fill state descriptor from snapshot
408 @param[in] do_estimate estimate data bytes to transfer
409 @param[out] state_desc snapshot state descriptor */
410 void get_state_info(bool do_estimate, Clone_Desc_State *state_desc);
411
412 /** Set state information during apply
413 @param[in] state_desc snapshot state descriptor */
414 void set_state_info(Clone_Desc_State *state_desc);
415
416 /** Get next state based on snapshot type
417 @return next state */
419
420 /** Try to attach to snapshot
421 @param[in] hdl_type copy, apply
422 @param[in] pfs_monitor enable PFS monitoring
423 @return true if successfully attached */
424 bool attach(Clone_Handle_Type hdl_type, bool pfs_monitor);
425
426 /** Detach from snapshot. */
427 void detach();
428
429 /** Set current snapshot aborted state. Used in error cases before exiting
430 clone to make sure any DDL notifier exits waiting. */
431 void set_abort();
432
433 /** @return true, iff clone has aborted. */
434 bool is_aborted() const;
435
436 /** Start transition to new state
437 @param[in] state_desc descriptor for next state
438 @param[in] new_state state to move for apply
439 @param[in] temp_buffer buffer used for collecting page IDs
440 @param[in] temp_buffer_len buffer length
441 @param[in] cbk alter callback for long wait
442 @return error code */
443 int change_state(Clone_Desc_State *state_desc, Snapshot_State new_state,
444 byte *temp_buffer, uint temp_buffer_len,
445 Clone_Alert_Func cbk);
446
447 /** Add file metadata entry at destination
448 @param[in] file_meta file metadata from donor
449 @param[in] data_dir destination data directory
450 @param[in] desc_create create if doesn't exist
451 @param[out] desc_exists descriptor already exists
452 @param[out] file_ctx if there, set to current file context
453 @return error code */
454 int get_file_from_desc(const Clone_File_Meta *file_meta, const char *data_dir,
455 bool desc_create, bool &desc_exists,
456 Clone_file_ctx *&file_ctx);
457
458 /** Rename an existing file descriptor.
459 @param[in] file_meta renamed file metadata from donor
460 @param[in] data_dir destination data directory
461 @param[out] file_ctx if there, set to current file context
462 @return error code */
463 int rename_desc(const Clone_File_Meta *file_meta, const char *data_dir,
464 Clone_file_ctx *&file_ctx);
465
466 /** Fix files renamed with ddl extension. The file name is checked against
467 existing file and added to appropriate status file.
468 @param[in] data_dir destination data directory
469 @param[in,out] file_ctx Set to correct extension
470 @return error code */
471 int fix_ddl_extension(const char *data_dir, Clone_file_ctx *file_ctx);
472
473 /** Add file descriptor to file list
474 @param[in,out] file_ctx current file context
475 @param[in] ddl_create added by DDL concurrently
476 @return true, if it is the last file. */
477 bool add_file_from_desc(Clone_file_ctx *&file_ctx, bool ddl_create);
478
479 /** Extract file information from node and add to snapshot
480 @param[in] node file node
481 @param[in] by_ddl node is added concurrently by DDL
482 @return error code */
483 dberr_t add_node(fil_node_t *node, bool by_ddl);
484
485 /** Add page ID to to the set of pages in snapshot
486 @param[in] space_id page tablespace
487 @param[in] page_num page number within tablespace
488 @return error code */
489 int add_page(uint32_t space_id, uint32_t page_num);
490
491 /** Add redo file to snapshot
492 @param[in] file_name file name
493 @param[in] file_size file size in bytes
494 @param[in] file_offset start offset
495 @return error code. */
496 int add_redo_file(char *file_name, uint64_t file_size, uint64_t file_offset);
497
498 /** Get file metadata by index for current state
499 @param[in] index file index
500 @return file metadata entry */
502
503 /** Get clone file context by index for current state
504 @param[in] index file index
505 @return file context */
507
508 /** Get clone file context by chunk and block number.
509 @param[in] chunk_num chunk number
510 @param[in] block_num block number
511 @param[in] hint_index hint file index number to start search.
512 @return file context */
513 Clone_file_ctx *get_file_ctx(uint32_t chunk_num, uint32_t block_num,
514 uint32_t hint_index);
515
516 /** Get next block of data to transfer
517 @param[in] chunk_num current chunk
518 @param[in,out] block_num current/next block
519 @param[in,out] file_ctx current/next block file context
520 @param[out] data_offset block offset in file
521 @param[out] data_buf data buffer or NULL if transfer from file
522 @param[out] data_size size of data in bytes
523 @param[out] file_size updated file size if extended
524 @return error code */
525 int get_next_block(uint chunk_num, uint &block_num,
526 const Clone_file_ctx *&file_ctx, uint64_t &data_offset,
527 byte *&data_buf, uint32_t &data_size, uint64_t &file_size);
528
529 /** Update snapshot block size based on caller's buffer size
530 @param[in] buff_size buffer size for clone transfer */
531 void update_block_size(uint buff_size);
532
533 /** @return chunk size in bytes. */
534 inline uint32_t get_chunk_size() const {
535 return chunk_size() * UNIV_PAGE_SIZE;
536 }
537
538 /** @return number of blocks per chunk for different states. */
539 uint32_t get_blocks_per_chunk() const;
540
541 /** Check if copy snapshot
542 @return true if snapshot is for copy */
543 bool is_copy() const { return (m_snapshot_handle_type == CLONE_HDL_COPY); }
544
545 /** Update file size when file is extended during page copy
546 @param[in] file_index current file index
547 @param[in] file_size new file size */
548 void update_file_size(uint32_t file_index, uint64_t file_size);
549
550 /** Encrypt tablespace key in header page with master key.
551 @param[in] page_size page size descriptor
552 @param[in,out] page_data page data to update
553 @return true, if successful. */
554 bool encrypt_key_in_header(const page_size_t &page_size, byte *page_data);
555
556 /** Encrypt tablespace key in header page with master key.
557 @param[in,out] log_header page data to update
558 @param[in] header_len length of log header
559 @return true, if successful. */
560 bool encrypt_key_in_log_header(byte *log_header, uint32_t header_len);
561
562 /** Decrypt tablespace key in header page with master key.
563 @param[in] file_meta clone file metadata
564 @param[in] page_size page size descriptor
565 @param[in,out] page_data page data to update */
566 void decrypt_key_in_header(const Clone_File_Meta *file_meta,
567 const page_size_t &page_size, byte *&page_data);
568
569 /** @return maximum blocks to transfer with file pinned. */
570 uint32_t get_max_blocks_pin() const;
571
572 /** Skip all blocks belonging to currently deleted file context.
573 @param[in] chunk_num current chunk
574 @param[in,out] block_num current, next block */
575 void skip_deleted_blocks(uint32_t chunk_num, uint32_t &block_num);
576
577 private:
578 /** Allow DDL file operation after 64 pages. */
579 const static uint32_t S_MAX_PAGES_PIN = 64;
580
581 /** Allow DDL file operation after every block (1M data by default) */
582 const static uint32_t S_MAX_BLOCKS_PIN = 1;
583
584 /** File name allocation size base. */
585 const static size_t S_FILE_NAME_BASE_LEN = 256;
586
587 /** Various wait types related to snapshot state. */
588 enum class Wait_type {
589 /* DDL- limited wait if clone is waiting for another DDL. */
591 /* DDL- Wait till snapshot state transition is over. */
593 /* DDL- Wait till PAGE COPY state is over. */
595 /* Clone - Wait till there are no blockers for state transition. */
597 /*DDL - Wait till the waiting clone threads are active. This are
598 clone threads from last DDL and useful to prevent starvation. */
600 /* DDL - Wait till all threads have closed active data files. */
602 /* Clone - Wait till DDL file operation is complete. */
604 };
605
606#ifdef UNIV_DEBUG
607 /** Debug sync Wait during state transition. */
609#endif /* UNIV_DEBUG */
610
611 /** Update deleted state of a file if not yet done.
612 @param[in,out] file_ctx file context
613 @return true, if updated state */
614 bool update_deleted_state(Clone_file_ctx *file_ctx);
615
616 /** Get clone data file context by chunk number.
617 @param[in] chunk_num chunk number
618 @param[in] hint_index hint file index number to start search.
619 @return file context */
620 Clone_file_ctx *get_data_file_ctx(uint32_t chunk_num, uint32_t hint_index);
621
622 /** Get clone page file context by chunk number and block number.
623 @param[in] chunk_num chunk number
624 @param[in] block_num block number
625 @return file context */
626 Clone_file_ctx *get_page_file_ctx(uint32_t chunk_num, uint32_t block_num);
627
628 /** Get clone redo file context by chunk number.
629 @param[in] chunk_num chunk number
630 @param[in] hint_index hint file index number to start search.
631 @return file context */
632 Clone_file_ctx *get_redo_file_ctx(uint32_t chunk_num, uint32_t hint_index);
633
634 /** Get wait information string based on wait type.
635 @param[in] wait_type wait type
636 @return wait information string. */
637 const char *wait_string(Wait_type wait_type) const;
638
639 /** Wait for various operations based on type.
640 @param[in] type wait type
641 @param[in] ctx file context when relevant
642 @param[in] no_wait return with error if needs to wait
643 @param[in] check_intr check for interrupt during wait
644 @return mysql error code. */
645 int wait(Wait_type type, const Clone_file_ctx *ctx, bool no_wait,
646 bool check_intr);
647
648 /** During wait get relevant message string for logging.
649 @param[in] wait_type wait type
650 @param[out] info notification to log while waiting
651 @param[out] error error message to log on timeout */
652 void get_wait_mesg(Wait_type wait_type, std::string &info,
653 std::string &error);
654
655 /** Block clone state transition. Clone must wait.
656 @param[in] type type of DDL notification
657 @param[in] space space ID for the ddl operation
658 @param[in] no_wait return with error if needs to wait
659 @param[in] check_intr check for interrupt during wait`
660 @param[out] error mysql error code
661 @return true iff clone state change is blocked. */
663 bool no_wait, bool check_intr, int &error);
664
665 /** Unblock clone state transition. */
667
668 /** Get next file state while being modified by ddl.
669 @param[in] type ddl notification type
670 @param[in] begin true, if DDL begin notification
671 false, if DDL end notification
672 @return target file state. */
674 bool begin);
675
676 /** Handle files for DDL begin notification.
677 @param[in] type type of DDL notification
678 @param[in] space space ID for the ddl operation
679 @param[in] no_wait return with error if needs to wait
680 @param[in] check_intr check for interrupt during wait
681 @return mysql error code */
682 int begin_ddl_file(Clone_notify::Type type, space_id_t space, bool no_wait,
683 bool check_intr);
684
685 /** Handle files for DDL end notification.
686 @param[in] type type of DDL notification
687 @param[in] space space ID for the ddl operation */
689
690 /** Synchronize snapshot with binary log and GTID.
691 @param[in] cbk alert callback for long wait
692 @return error code. */
694
695 /** Make sure that the trx sys page binary log position correctly reflects
696 all transactions committed to innodb. It updates binary log position
697 in transaction sys page, if required. The caller must ensure that any new
698 transaction is committed in order of binary log.
699 @return error code. */
701
702 /** Wait for already prepared binlog transactions to end.
703 @return error code. */
705
706 /** Wait for a transaction to end.
707 @param[in] thd current THD
708 @param[in] trx_id transaction to wait for
709 @return error code. */
710 int wait_trx_end(THD *thd, trx_id_t trx_id);
711
712 /** Begin state transition before waiting for DDL. */
715 /* Update number of clones to transit to new state. Set this prior to
716 waiting for DDLs blocking state transfer. This would help a new DDL to
717 find if clone is blocked by other DDL before state transition. */
719 }
720
721 /** Begin state transition.
722 @param[in] new_state state to transit to */
725 m_snapshot_next_state = new_state;
726 /* Move to next state. This is ok as the snapshot
727 mutex is not released till transition is ended, This
728 could change later when we ideally should release
729 the snapshot mutex during transition. */
731 }
732
733 /** End state transition. */
734 void end_transit() {
738 }
739
740 /** Check if state transition is in progress
741 @return true during state transition */
742 bool in_transit_state() const {
745 }
746
747 /** @return true, if waiting before starting transition. Generally the
748 case when some DDL blocks state transition. */
749 bool in_transit_wait() const {
751 return (!in_transit_state() && m_num_clones_transit != 0);
752 }
753
754 /** Start redo archiving.
755 @return error code */
757
758 /** Initialize snapshot state for file copy
759 @param[in] new_state state to move for apply
760 @return error code */
761 int init_file_copy(Snapshot_State new_state);
762
763 /** Initialize disk byte estimate. */
765 /* Initial size is set to the redo file size on disk. */
768 }
769
770 /** Initialize snapshot state for page copy
771 @param[in] new_state state to move for apply
772 @param[in] page_buffer temporary buffer to copy page IDs
773 @param[in] page_buffer_len buffer length
774 @return error code */
775 int init_page_copy(Snapshot_State new_state, byte *page_buffer,
776 uint page_buffer_len);
777
778 /** Initialize snapshot state for redo copy
779 @param[in] new_state state to move for apply
780 @param[in] cbk alert callback for long wait
781 @return error code */
783
784 /** Initialize state while applying cloned data
785 @param[in] state_desc snapshot state descriptor
786 @return error code */
787 int init_apply_state(Clone_Desc_State *state_desc);
788
789 /** Extend and flush files after copying data
790 @param[in] is_redo if true flush redo, otherwise data
791 @return error code */
792 int extend_and_flush_files(bool is_redo);
793
794 /** Create file descriptor and add to current file list
795 @param[in] data_dir destination data directory
796 @param[in] file_meta file metadata from donor
797 @param[in] is_ddl if ddl temporary file
798 @param[out] file_ctx file context
799 @return error code */
800 int create_desc(const char *data_dir, const Clone_File_Meta *file_meta,
801 bool is_ddl, Clone_file_ctx *&file_ctx);
802
803 /** Get file context for current chunk
804 @param[in] file_vector clone file vector
805 @param[in] chunk_num current chunk number
806 @param[in] start_index index for starting the search
807 @return file context */
808 Clone_file_ctx *get_file(Clone_File_Vec &file_vector, uint32_t chunk_num,
809 uint32_t start_index);
810
811 /** Get next page from buffer pool
812 @param[in] chunk_num current chunk
813 @param[in,out] block_num current, next block
814 @param[in,out] file_ctx current, next block file context
815 @param[out] data_offset offset in file
816 @param[out] data_buf page data
817 @param[out] data_size page data size
818 @param[out] file_size updated file size if extended
819 @return error code */
820 int get_next_page(uint chunk_num, uint &block_num,
821 const Clone_file_ctx *&file_ctx, uint64_t &data_offset,
822 byte *&data_buf, uint32_t &data_size, uint64_t &file_size);
823
824 /** Get page from buffer pool and make ready for write
825 @param[in] page_id page ID chunk
826 @param[in] page_size page size descriptor
827 @param[in] file_ctx clone file context
828 @param[out] page_data data page
829 @param[out] data_size page size in bytes
830 @return error code */
831 int get_page_for_write(const page_id_t &page_id, const page_size_t &page_size,
832 const Clone_file_ctx *file_ctx, byte *&page_data,
833 uint &data_size);
834
835 /* Make page ready for flush by updating LSN anc checksum
836 @param[in] page_size page size descriptor
837 @param[in] page_lsn LSN to update the page with
838 @param[in,out] page_data data page */
839 void page_update_for_flush(const page_size_t &page_size, lsn_t page_lsn,
840 byte *&page_data);
841
842 /** Build file metadata entry
843 @param[in] file_name name of the file
844 @param[in] file_size file size in bytes
845 @param[in] file_offset start offset
846 @param[in] num_chunks total number of chunks in the file
847 @return file context */
848 Clone_file_ctx *build_file(const char *file_name, uint64_t file_size,
849 uint64_t file_offset, uint &num_chunks);
850
851 /** Allocate and set clone file name.
852 @param[in,out] file_meta file metadata
853 @param[in] file_name file name
854 @return true iff successful. */
855 bool build_file_name(Clone_File_Meta *file_meta, const char *file_name);
856
857 /** Add buffer pool dump file to the file list
858 @return error code */
859 int add_buf_pool_file();
860
861 /** Add file to snapshot
862 @param[in] name file name
863 @param[in] size_bytes file size in bytes
864 @param[in] alloc_bytes allocation size on disk for sparse file
865 @param[in] node file node
866 @param[in] by_ddl node is added concurrently by DDL
867 @return error code. */
868 int add_file(const char *name, uint64_t size_bytes, uint64_t alloc_bytes,
869 fil_node_t *node, bool by_ddl);
870
871 /** Check if file context has been changed by ddl.
872 @param[in] node tablespace file node
873 @param[out] file_ctx file context if exists
874 @return true iff file is created or modified by DDL. */
875 bool file_ctx_changed(const fil_node_t *node, Clone_file_ctx *&file_ctx);
876
877 /** Get chunk size
878 @return chunk size in pages */
879 inline uint32_t chunk_size() const {
880 auto size = static_cast<uint32_t>(ut_2_exp(m_chunk_size_pow2));
881 return size;
882 }
883
884 /** Get block size for file copy
885 @return block size in pages */
886 uint32_t block_size() {
888 auto size = static_cast<uint32_t>(ut_2_exp(m_block_size_pow2));
889
890 return size;
891 }
892
893 /** Get number of blocks per chunk for file copy
894 @return blocks per chunk */
895 inline uint32_t blocks_per_chunk() const {
897 return (1 << (m_chunk_size_pow2 - m_block_size_pow2));
898 }
899
900 /** Update system file name from configuration.
901 @param[in] replace if replacing current data directory
902 @param[in] file_meta file descriptor
903 @param[in,out] file_name file name to update
904 @return error code */
905 int update_sys_file_name(bool replace, const Clone_File_Meta *file_meta,
906 std::string &file_name);
907
908 /** Build file name along with path for cloned data files.
909 @param[in] data_dir clone data directory
910 @param[in] file_desc file descriptor
911 @param[out] file_path built file path if returned 0
912 @return error code (0 on success) */
913 int build_file_path(const char *data_dir, const Clone_File_Meta *file_desc,
914 std::string &file_path);
915
916 /** Build file context from file path.
917 @param[in] extn file extension type
918 @param[in] file_meta file descriptor
919 @param[in] file_path data file along with path
920 @param[out] file_ctx created file context
921 @return error code */
923 const Clone_File_Meta *file_meta,
924 const std::string &file_path, Clone_file_ctx *&file_ctx);
925
926 /** Check for existing file and if clone extension is needed. This function
927 has the side effect to add undo file indexes.
928 @param[in] replace if data directory is replaced
929 @param[in] undo_file if undo tablespace file
930 @param[in] redo_file if redo file
931 @param[in] data_file_index index of file
932 @param[in] data_file data file name
933 @param[out] extn file extension needs to be used
934 @return error code */
935 int handle_existing_file(bool replace, bool undo_file, bool redo_file,
936 uint32_t data_file_index,
937 const std::string &data_file,
939
940 /** @return number of data files to transfer. */
941 inline size_t num_data_files() const { return m_data_file_vector.size(); }
942
943 /** @return number of redo files to transfer. */
944 inline size_t num_redo_files() const { return m_redo_file_vector.size(); }
945
946 private:
947 /** @name Snapshot type and ID */
948
949 /** Snapshot handle type */
951
952 /** Clone type */
954
955 /** Unique snapshot ID */
957
958 /** Index in global snapshot array */
960
961 /** @name Snapshot State */
962
963 /** Mutex to handle access by concurrent clones */
964 mutable ib_mutex_t m_snapshot_mutex;
965
966 /** Number of blockers for state change. Usually DDLs for short duration. */
968
969 /** Set to true only if clone is aborted after error. */
971
972 /** Number of clones attached to this snapshot */
974
975 /** Number of clones in in state transition */
977
978 /** Current state */
980
981 /** Next state to move to. Set only during state transfer. */
983
984 /** @name Snapshot data block */
985
986 /** Memory allocation heap */
988
989 /** Chunk size in power of 2 */
991
992 /** Block size in power of 2 */
994
995 /** Number of chunks in current state */
997
998 /** Maximum file name length observed till now. */
1000
1001 /** @name Snapshot file data */
1002
1003 /** All data files for transfer */
1005
1006 /** Map space ID to file vector index */
1008
1009 /** Total number of data chunks */
1011
1012 /** Number of bytes on disk. */
1014
1015 /** Index into m_data_file_vector for all undo files. */
1016 std::vector<int> m_undo_file_indexes;
1017
1018 /** @name Snapshot page data */
1019
1020 /** Page archiver client */
1022
1023 /** Set of unique page IDs */
1025
1026 /** Sorted page IDs to transfer */
1028
1029 /** Number of pages to transfer */
1031
1032 /** Number of duplicate pages found */
1034
1035 /** @name Snapshot redo data */
1036
1037 /** redo log archiver client */
1039
1040 /** All archived redo files to transfer */
1042
1043 /** Start offset in first redo file */
1045
1046 /** Redo header block */
1048
1049 /** Redo header size */
1051
1052 /** Redo trailer block */
1054
1055 /** Redo trailer size */
1057
1058 /** Redo trailer block offset */
1060
1061 /** Archived redo file size */
1063
1064 /** Total number of redo data chunks */
1066
1067 /** Enable PFS monitoring */
1069
1070 /** Performance Schema accounting object to monitor stage progress */
1072};
1073
1074#endif /* CLONE_SNAPSHOT_INCLUDE */
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:50
Innodb interface for log archive.
Innodb interface for modified page archive.
Class used to report CLONE progress via Performance Schema.
Definition: clone0monitor.h:45
RAII style guard for begin & end of snapshot state transition.
Definition: clone0snapshot.h:265
Clone_Snapshot * m_snapshot
Clone Snapshot.
Definition: clone0snapshot.h:286
State_transit(State_transit const &)=delete
Disable copy construction.
State_transit & operator=(State_transit const &)=delete
Disable assignment.
~State_transit()
Destructor to end state transition.
Definition: clone0snapshot.cc:269
int get_error() const
Definition: clone0snapshot.h:276
State_transit(Clone_Snapshot *snapshot, Snapshot_State new_state)
Constructor to begin state transition.
Definition: clone0snapshot.cc:247
int m_error
Saved error while beginning transition.
Definition: clone0snapshot.h:289
Dynamic database snapshot: Holds metadata and handle to data.
Definition: clone0snapshot.h:262
bool encrypt_key_in_header(const page_size_t &page_size, byte *page_data)
Encrypt tablespace key in header page with master key.
Definition: clone0snapshot.cc:758
int init_redo_archiving()
Start redo archiving.
Definition: clone0copy.cc:121
const char * wait_string(Wait_type wait_type) const
Get wait information string based on wait type.
Definition: clone0snapshot.cc:1248
uint m_num_duplicate_pages
Number of duplicate pages found.
Definition: clone0snapshot.h:1033
mem_heap_t * lock_heap()
Get snapshot heap used for allocation during clone.
Definition: clone0snapshot.h:351
void get_state_info(bool do_estimate, Clone_Desc_State *state_desc)
Fill state descriptor from snapshot.
Definition: clone0snapshot.cc:96
void end_ddl_file(Clone_notify::Type type, space_id_t space)
Handle files for DDL end notification.
Definition: clone0snapshot.cc:1546
uint32_t get_blocks_per_chunk() const
Definition: clone0snapshot.cc:528
uint64_t get_id()
Get unique snapshot identifier.
Definition: clone0snapshot.h:338
int wait_for_binlog_prepared_trx()
Wait for already prepared binlog transactions to end.
Definition: clone0copy.cc:453
uint64_t m_redo_start_offset
Start offset in first redo file.
Definition: clone0snapshot.h:1044
uint get_dyn_buffer_length()
Get maximum buffer size required for clone.
Definition: clone0snapshot.h:380
int rename_desc(const Clone_File_Meta *file_meta, const char *data_dir, Clone_file_ctx *&file_ctx)
Rename an existing file descriptor.
Definition: clone0apply.cc:76
size_t num_redo_files() const
Definition: clone0snapshot.h:944
uint m_redo_header_size
Redo header size.
Definition: clone0snapshot.h:1050
Clone_Monitor & get_clone_monitor()
Get performance schema accounting object used to monitor stage progress.
Definition: clone0snapshot.h:347
void page_update_for_flush(const page_size_t &page_size, lsn_t page_lsn, byte *&page_data)
Definition: clone0snapshot.cc:804
uint32_t block_size()
Get block size for file copy.
Definition: clone0snapshot.h:886
Clone_Snapshot(Clone_Handle_Type hdl_type, Ha_clone_type clone_type, uint arr_idx, uint64_t snap_id)
Construct snapshot.
Definition: clone0snapshot.cc:44
bool in_transit_wait() const
Definition: clone0snapshot.h:749
ib_mutex_t m_snapshot_mutex
Mutex to handle access by concurrent clones.
Definition: clone0snapshot.h:964
void decrypt_key_in_header(const Clone_File_Meta *file_meta, const page_size_t &page_size, byte *&page_data)
Decrypt tablespace key in header page with master key.
Definition: clone0snapshot.cc:789
uint m_num_current_chunks
Number of chunks in current state.
Definition: clone0snapshot.h:996
int add_page(uint32_t space_id, uint32_t page_num)
Add page ID to to the set of pages in snapshot.
Definition: clone0copy.cc:914
int pin_file(Clone_file_ctx *file_ctx, bool &handle_delete)
Wait for concurrent DDL file operation and pin file.
Definition: clone0snapshot.cc:1620
mem_heap_t * m_snapshot_heap
Memory allocation heap.
Definition: clone0snapshot.h:987
void get_wait_mesg(Wait_type wait_type, std::string &info, std::string &error)
During wait get relevant message string for logging.
Definition: clone0snapshot.cc:1212
Clone_File_Vec m_data_file_vector
All data files for transfer.
Definition: clone0snapshot.h:1004
size_t m_max_file_name_len
Maximum file name length observed till now.
Definition: clone0snapshot.h:999
uint32_t get_max_blocks_pin() const
Definition: clone0snapshot.cc:994
uint m_num_clones_transit
Number of clones in in state transition.
Definition: clone0snapshot.h:976
size_t num_data_files() const
Definition: clone0snapshot.h:941
uint32_t chunk_size() const
Get chunk size.
Definition: clone0snapshot.h:879
uint32_t m_num_blockers
Number of blockers for state change.
Definition: clone0snapshot.h:967
static const size_t S_FILE_NAME_BASE_LEN
File name allocation size base.
Definition: clone0snapshot.h:585
static const uint32_t S_MAX_BLOCKS_PIN
Allow DDL file operation after every block (1M data by default)
Definition: clone0snapshot.h:582
void release_heap(mem_heap_t *&heap)
Definition: clone0snapshot.h:357
int add_redo_file(char *file_name, uint64_t file_size, uint64_t file_offset)
Add redo file to snapshot.
Definition: clone0copy.cc:940
bool add_file_from_desc(Clone_file_ctx *&file_ctx, bool ddl_create)
Add file descriptor to file list.
Definition: clone0apply.cc:501
int add_file(const char *name, uint64_t size_bytes, uint64_t alloc_bytes, fil_node_t *node, bool by_ddl)
Add file to snapshot.
Definition: clone0copy.cc:746
dberr_t add_node(fil_node_t *node, bool by_ddl)
Extract file information from node and add to snapshot.
Definition: clone0copy.cc:861
uint64_t m_data_bytes_disk
Number of bytes on disk.
Definition: clone0snapshot.h:1013
int get_next_block(uint chunk_num, uint &block_num, const Clone_file_ctx *&file_ctx, uint64_t &data_offset, byte *&data_buf, uint32_t &data_size, uint64_t &file_size)
Get next block of data to transfer.
Definition: clone0snapshot.cc:349
bool in_transit_state() const
Check if state transition is in progress.
Definition: clone0snapshot.h:742
uint get_index()
Get snapshot index in global array.
Definition: clone0snapshot.h:342
Snapshot_State get_state()
Get snapshot state.
Definition: clone0snapshot.h:364
uint64_t get_disk_estimate() const
Definition: clone0snapshot.h:334
int change_state(Clone_Desc_State *state_desc, Snapshot_State new_state, byte *temp_buffer, uint temp_buffer_len, Clone_Alert_Func cbk)
Start transition to new state.
Definition: clone0snapshot.cc:553
void begin_transit(Snapshot_State new_state)
Begin state transition.
Definition: clone0snapshot.h:723
uint get_num_chunks()
Get total number of chunks for current state.
Definition: clone0snapshot.h:372
Log_Arch_Client_Ctx m_redo_ctx
redo log archiver client
Definition: clone0snapshot.h:1038
int wait(Wait_type type, const Clone_file_ctx *ctx, bool no_wait, bool check_intr)
Wait for various operations based on type.
Definition: clone0snapshot.cc:1287
Clone_file_ctx * get_file(Clone_File_Vec &file_vector, uint32_t chunk_num, uint32_t start_index)
Get file context for current chunk.
Definition: clone0snapshot.cc:613
void set_abort()
Set current snapshot aborted state.
Definition: clone0snapshot.cc:241
bool m_aborted
Set to true only if clone is aborted after error.
Definition: clone0snapshot.h:970
Clone_File_Meta * get_file_by_index(uint index)
Get file metadata by index for current state.
Definition: clone0snapshot.cc:280
void init_disk_estimate()
Initialize disk byte estimate.
Definition: clone0snapshot.h:764
Clone_Monitor m_monitor
Performance Schema accounting object to monitor stage progress.
Definition: clone0snapshot.h:1071
int get_page_for_write(const page_id_t &page_id, const page_size_t &page_size, const Clone_file_ctx *file_ctx, byte *&page_data, uint &data_size)
Get page from buffer pool and make ready for write.
Definition: clone0snapshot.cc:850
Snapshot_State get_next_state()
Get next state based on snapshot type.
Definition: clone0snapshot.cc:175
int init_redo_copy(Snapshot_State new_state, Clone_Alert_Func cbk)
Initialize snapshot state for redo copy.
Definition: clone0copy.cc:473
Snapshot_State m_snapshot_state
Current state.
Definition: clone0snapshot.h:979
void unblock_state_change()
Unblock clone state transition.
Definition: clone0snapshot.cc:1443
int handle_existing_file(bool replace, bool undo_file, bool redo_file, uint32_t data_file_index, const std::string &data_file, Clone_file_ctx::Extension &extn)
Check for existing file and if clone extension is needed.
Definition: clone0apply.cc:216
int update_binlog_position()
Make sure that the trx sys page binary log position correctly reflects all transactions committed to ...
Definition: clone0copy.cc:349
std::function< int(Clone_file_ctx *)> File_Cbk_Func
Definition: clone0snapshot.h:390
bool is_copy() const
Check if copy snapshot.
Definition: clone0snapshot.h:543
Clone_File_Map m_data_file_map
Map space ID to file vector index.
Definition: clone0snapshot.h:1007
Clone_file_ctx * get_file_ctx(uint32_t chunk_num, uint32_t block_num, uint32_t hint_index)
Get clone file context by chunk and block number.
Definition: clone0snapshot.cc:999
uint m_snapshot_arr_idx
Index in global snapshot array.
Definition: clone0snapshot.h:959
Clone_file_ctx * get_page_file_ctx(uint32_t chunk_num, uint32_t block_num)
Get clone page file context by chunk number and block number.
Definition: clone0snapshot.cc:1038
int get_file_from_desc(const Clone_File_Meta *file_meta, const char *data_dir, bool desc_create, bool &desc_exists, Clone_file_ctx *&file_ctx)
Add file metadata entry at destination.
Definition: clone0apply.cc:42
int build_file_path(const char *data_dir, const Clone_File_Meta *file_desc, std::string &file_path)
Build file name along with path for cloned data files.
Definition: clone0apply.cc:322
Clone_Page_Set m_page_set
Set of unique page IDs.
Definition: clone0snapshot.h:1024
Page_Arch_Client_Ctx m_page_ctx
Page archiver client.
Definition: clone0snapshot.h:1021
int update_sys_file_name(bool replace, const Clone_File_Meta *file_meta, std::string &file_name)
Update system file name from configuration.
Definition: clone0apply.cc:118
int begin_ddl_file(Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr)
Handle files for DDL begin notification.
Definition: clone0snapshot.cc:1492
bool block_state_change(Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr, int &error)
Block clone state transition.
Definition: clone0snapshot.cc:1389
byte * m_redo_trailer
Redo trailer block.
Definition: clone0snapshot.h:1053
bool attach(Clone_Handle_Type hdl_type, bool pfs_monitor)
Try to attach to snapshot.
Definition: clone0snapshot.cc:207
int init_file_copy(Snapshot_State new_state)
Initialize snapshot state for file copy.
Definition: clone0copy.cc:183
Clone_Handle_Type m_snapshot_handle_type
Snapshot handle type.
Definition: clone0snapshot.h:950
Clone_file_ctx::State get_target_file_state(Clone_notify::Type type, bool begin)
Get next file state while being modified by ddl.
Definition: clone0snapshot.cc:1448
void detach()
Detach from snapshot.
Definition: clone0snapshot.cc:224
Clone_File_Vec m_redo_file_vector
All archived redo files to transfer.
Definition: clone0snapshot.h:1041
bool build_file_name(Clone_File_Meta *file_meta, const char *file_name)
Allocate and set clone file name.
Definition: clone0copy.cc:575
void set_state_info(Clone_Desc_State *state_desc)
Set state information during apply.
Definition: clone0snapshot.cc:136
Clone_file_ctx * get_data_file_ctx(uint32_t chunk_num, uint32_t hint_index)
Get clone data file context by chunk number.
Definition: clone0snapshot.cc:1020
std::vector< int > m_undo_file_indexes
Index into m_data_file_vector for all undo files.
Definition: clone0snapshot.h:1016
bool begin_ddl_state(Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr, int &error)
DDL notification before the operation.
Definition: clone0snapshot.cc:1100
uint32_t get_chunk_size() const
Definition: clone0snapshot.h:534
int iterate_redo_files(File_Cbk_Func &&func)
Iterate through all redo files.
Definition: clone0snapshot.cc:339
Clone_Page_Vec m_page_vector
Sorted page IDs to transfer.
Definition: clone0snapshot.h:1027
uint32_t blocks_per_chunk() const
Get number of blocks per chunk for file copy.
Definition: clone0snapshot.h:895
bool encrypt_key_in_log_header(byte *log_header, uint32_t header_len)
Encrypt tablespace key in header page with master key.
Definition: clone0snapshot.cc:738
Ha_clone_type m_snapshot_type
Clone type.
Definition: clone0snapshot.h:953
int extend_and_flush_files(bool is_redo)
Extend and flush files after copying data.
Definition: clone0apply.cc:1722
void begin_transit_ddl_wait()
Begin state transition before waiting for DDL.
Definition: clone0snapshot.h:713
int create_desc(const char *data_dir, const Clone_File_Meta *file_meta, bool is_ddl, Clone_file_ctx *&file_ctx)
Create file descriptor and add to current file list.
Definition: clone0apply.cc:461
uint m_num_redo_chunks
Total number of redo data chunks.
Definition: clone0snapshot.h:1065
bool file_ctx_changed(const fil_node_t *node, Clone_file_ctx *&file_ctx)
Check if file context has been changed by ddl.
Definition: clone0copy.cc:674
int build_file_ctx(Clone_file_ctx::Extension extn, const Clone_File_Meta *file_meta, const std::string &file_path, Clone_file_ctx *&file_ctx)
Build file context from file path.
Definition: clone0apply.cc:406
static const uint32_t S_MAX_PAGES_PIN
Allow DDL file operation after 64 pages.
Definition: clone0snapshot.h:579
int add_buf_pool_file()
Add buffer pool dump file to the file list.
Definition: clone0copy.cc:89
int get_next_page(uint chunk_num, uint &block_num, const Clone_file_ctx *&file_ctx, uint64_t &data_offset, byte *&data_buf, uint32_t &data_size, uint64_t &file_size)
Get next page from buffer pool.
Definition: clone0snapshot.cc:664
int init_apply_state(Clone_Desc_State *state_desc)
Initialize state while applying cloned data.
Definition: clone0apply.cc:1672
int init_page_copy(Snapshot_State new_state, byte *page_buffer, uint page_buffer_len)
Initialize snapshot state for page copy.
Definition: clone0copy.cc:246
bool is_aborted() const
Definition: clone0snapshot.cc:236
uint m_num_clones
Number of clones attached to this snapshot.
Definition: clone0snapshot.h:973
void unpin_file(Clone_file_ctx *file_ctx)
Unpin a file.
Definition: clone0snapshot.h:326
uint64_t get_redo_file_size()
Get the redo file size for the snapshot.
Definition: clone0snapshot.h:368
int iterate_files(File_Cbk_Func &&func)
Iterate through all files in current state.
Definition: clone0snapshot.cc:311
void update_file_size(uint32_t file_index, uint64_t file_size)
Update file size when file is extended during page copy.
Definition: clone0apply.cc:1641
void debug_wait_state_transit()
Debug sync Wait during state transition.
Definition: clone0copy.cc:171
size_t get_max_file_name_length()
Get maximum file length seen till now.
Definition: clone0snapshot.h:376
void update_block_size(uint buff_size)
Update snapshot block size based on caller's buffer size.
Definition: clone0snapshot.cc:510
uint m_block_size_pow2
Block size in power of 2.
Definition: clone0snapshot.h:993
uint64_t m_redo_file_size
Archived redo file size.
Definition: clone0snapshot.h:1062
Snapshot_State m_snapshot_next_state
Next state to move to.
Definition: clone0snapshot.h:982
void skip_deleted_blocks(uint32_t chunk_num, uint32_t &block_num)
Skip all blocks belonging to currently deleted file context.
Definition: clone0snapshot.cc:636
uint m_num_data_chunks
Total number of data chunks.
Definition: clone0snapshot.h:1010
uint m_num_pages
Number of pages to transfer.
Definition: clone0snapshot.h:1030
~Clone_Snapshot()
Release contexts and free heap.
Definition: clone0snapshot.cc:83
int wait_trx_end(THD *thd, trx_id_t trx_id)
Wait for a transaction to end.
Definition: clone0copy.cc:401
Wait_type
Various wait types related to snapshot state.
Definition: clone0snapshot.h:588
Clone_file_ctx * get_file_ctx_by_index(uint index)
Get clone file context by index for current state.
Definition: clone0snapshot.cc:289
uint m_chunk_size_pow2
Chunk size in power of 2.
Definition: clone0snapshot.h:990
int synchronize_binlog_gtid(Clone_Alert_Func cbk)
Synchronize snapshot with binary log and GTID.
Definition: clone0copy.cc:331
bool update_deleted_state(Clone_file_ctx *file_ctx)
Update deleted state of a file if not yet done.
Definition: clone0snapshot.cc:1606
byte * m_redo_header
Redo header block.
Definition: clone0snapshot.h:1047
uint64_t m_snapshot_id
Unique snapshot ID.
Definition: clone0snapshot.h:956
int iterate_data_files(File_Cbk_Func &&func)
Iterate through all data files.
Definition: clone0snapshot.cc:327
bool m_enable_pfs
Enable PFS monitoring.
Definition: clone0snapshot.h:1068
int fix_ddl_extension(const char *data_dir, Clone_file_ctx *file_ctx)
Fix files renamed with ddl extension.
Definition: clone0apply.cc:94
uint m_redo_trailer_size
Redo trailer size.
Definition: clone0snapshot.h:1056
Clone_file_ctx * build_file(const char *file_name, uint64_t file_size, uint64_t file_offset, uint &num_chunks)
Build file metadata entry.
Definition: clone0copy.cc:621
void end_transit()
End state transition.
Definition: clone0snapshot.h:734
bool blocks_clone(const Clone_file_ctx *file_ctx)
Check if DDL needs to block clone operation.
Definition: clone0snapshot.cc:1468
uint64_t m_redo_trailer_offset
Redo trailer block offset.
Definition: clone0snapshot.h:1059
Clone_file_ctx * get_redo_file_ctx(uint32_t chunk_num, uint32_t hint_index)
Get clone redo file context by chunk number.
Definition: clone0snapshot.cc:1025
void end_ddl_state(Clone_notify::Type type, space_id_t space)
DDL notification after the operation.
Definition: clone0snapshot.cc:1201
Type
Notification type.
Definition: clone0api.h:181
Redo Log archiver client context.
Definition: arch0log.h:47
os_offset_t current_physical_capacity() const
Provides maximum limitation for space occupied on disk.
Definition: log0files_capacity.cc:528
Dirty page archiver client context.
Definition: arch0page.h:169
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
Page identifier.
Definition: buf0types.h:206
Page size descriptor.
Definition: page0size.h:49
Innodb Clone Interface.
Innodb clone descriptors.
Snapshot_State
Snapshot state transfer during clone.
Definition: clone0desc.h:92
@ CLONE_SNAPSHOT_DONE
Snapshot state at end after finishing transfer.
Definition: clone0desc.h:109
@ CLONE_SNAPSHOT_NONE
Invalid state.
Definition: clone0desc.h:94
Performance Schema stage instrumentation to monitor clone progress.
std::function< int()> Clone_Alert_Func
Function to alert caller for long wait.
Definition: clone0monitor.h:42
std::vector< Clone_file_ctx * > Clone_File_Vec
Vector type for storing clone files.
Definition: clone0snapshot.h:197
std::vector< Clone_Page > Clone_Page_Vec
Vector type for storing clone page IDs.
Definition: clone0snapshot.h:232
const uint SNAPSHOT_MAX_BLOCK_SIZE_POW2
Maximum block size in power of 2 in unit of pages.
Definition: clone0snapshot.h:259
const uint SNAPSHOT_DEF_CHUNK_SIZE_POW2
Default chunk size in power of 2 in unit of pages.
Definition: clone0snapshot.h:249
Clone_Handle_Type
Clone handle type.
Definition: clone0snapshot.h:238
@ CLONE_HDL_APPLY
Clone Handle for APPLY.
Definition: clone0snapshot.h:243
@ CLONE_HDL_COPY
Clone Handle for COPY.
Definition: clone0snapshot.h:240
std::set< Clone_Page, Less_Clone_Page > Clone_Page_Set
Set for storing unique page IDs.
Definition: clone0snapshot.h:235
std::map< space_id_t, uint > Clone_File_Map
Map type for mapping space ID to clone file index.
Definition: clone0snapshot.h:200
const uint SNAPSHOT_DEF_BLOCK_SIZE_POW2
Default block size in power of 2 in unit of pages.
Definition: clone0snapshot.h:255
dberr_t
Definition: db0err.h:38
The low-level file system.
log_t * log_sys
Redo log system (singleton).
Definition: log0log.cc:434
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:62
static size_t file_size
Definition: mysql_config_editor.cc:70
Log info(cout, "NOTE")
static bool replace
Definition: mysqlimport.cc:65
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
wait_type
Definition: socket_constants.h:85
required string type
Definition: replication_group_member_actions.proto:33
Ha_clone_type
Clone operation types.
Definition: handler.h:958
@ HA_CLONE_BLOCKING
Caller must block all write operation to the SE.
Definition: handler.h:960
case opt name
Definition: sslopt-case.h:32
CLONE_DESC_STATE: Descriptor for current snapshot state.
Definition: clone0desc.h:438
Clone file information.
Definition: clone0desc.h:485
void init()
Definition: clone0desc.cc:1071
Page identified by space and page number.
Definition: clone0snapshot.h:203
uint32_t m_page_no
Page number within tablespace.
Definition: clone0snapshot.h:208
uint32_t m_space_id
Tablespace ID.
Definition: clone0snapshot.h:205
Definition: clone0snapshot.h:48
void end_wait()
Finish waiting for DDL.
Definition: clone0snapshot.h:120
void set_ddl(Snapshot_State next_state)
Mark file added by DDL.
Definition: clone0snapshot.h:105
bool is_waiting() const
Definition: clone0snapshot.h:126
bool modifying() const
Definition: clone0snapshot.h:141
void unpin()
Unpin the file.
Definition: clone0snapshot.h:132
const Clone_File_Meta * get_file_meta_read() const
Definition: clone0snapshot.h:168
Extension
File extension to use with name.
Definition: clone0snapshot.h:75
bool deleting() const
Definition: clone0snapshot.h:147
uint32_t m_waiting
Waiting count incremented and decremented by clone tasks while waiting DDL file operation in progress...
Definition: clone0snapshot.h:184
std::atomic< uint32_t > m_pin
Pin count incremented and decremented by clone tasks to synchronize with concurrent DDL.
Definition: clone0snapshot.h:180
bool renamed() const
Definition: clone0snapshot.h:159
void pin()
Pin the file.
Definition: clone0snapshot.h:129
bool deleted() const
Definition: clone0snapshot.h:153
Clone_File_Meta m_meta
File metadata.
Definition: clone0snapshot.h:193
bool by_ddl(Snapshot_State state) const
Definition: clone0snapshot.h:112
void get_file_name(std::string &name) const
Get file name with extension.
Definition: clone0snapshot.cc:1076
Snapshot_State m_next_state
Next state when ddl last modified file.
Definition: clone0snapshot.h:190
Clone_File_Meta * get_file_meta()
Definition: clone0snapshot.h:165
State
File state: [CREATED] ----------—> [DROPPING] --> [DROPPED] --> [DROPPED_HANDLED] | ^ | | -—> [RENAMI...
Definition: clone0snapshot.h:57
std::atomic< State > m_state
File metadata state.
Definition: clone0snapshot.h:172
void init(Extension extn)
Initialize file state.
Definition: clone0snapshot.h:86
Extension m_extension
File name extension.
Definition: clone0snapshot.h:175
void begin_wait()
Start waiting for DDL.
Definition: clone0snapshot.h:117
bool m_modified_ddl
true, if file created or modified after clone is started.
Definition: clone0snapshot.h:187
bool is_pinned() const
Definition: clone0snapshot.h:138
Definition: ut0mutex.h:127
Comparator for storing sorted page ID.
Definition: clone0snapshot.h:212
bool operator()(const Clone_Page &page1, const Clone_Page &page2) const
Less than operator for page ID.
Definition: clone0snapshot.h:217
File node of a tablespace or the log data space.
Definition: fil0fil.h:149
ib_mutex_t limits_mutex
Mutex which protects fields: available_for_checkpoint_lsn, requested_checkpoint_lsn.
Definition: log0sys.h:588
Log_files_capacity m_capacity
Capacity limits for the redo log.
Definition: log0sys.h:417
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:299
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:137
unsigned int uint
Definition: uca-dump.cc:29
Version control for database, common definitions, and include files.
#define UNIV_PAGE_SIZE
The universal page size of the database.
Definition: univ.i:295
#define UT_LOCATION_HERE
Definition: ut0core.h:46
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:56
#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_enter(M)
Definition: ut0mutex.h:116
static uint32_t ut_2_exp(uint32_t n)
Calculates 2 to power n.