1 /*****************************************************************************
2 
3 Copyright (c) 2017, 2018, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 
25 *****************************************************************************/
26 
27 /** @file include/arch0log.h
28  Innodb interface for log archive
29 
30  *******************************************************/
31 
32 #ifndef ARCH_LOG_INCLUDE
33 #define ARCH_LOG_INCLUDE
34 
35 #include "arch0arch.h"
36 
37 /** File Node Iterator callback
38 @param[in]	file_name	NULL terminated file name
39 @param[in]	file_size	size of file in bytes
40 @param[in]	read_offset	offset to start reading from
41 @param[in]	ctx		context passed by caller
42 @return error code */
43 using Log_Arch_Cbk = int(char *file_name, ib_uint64_t file_size,
44                          ib_uint64_t read_offset, void *ctx);
45 
46 /** Redo Log archiver client context */
47 class Log_Arch_Client_Ctx {
48  public:
49   /** Constructor: Initialize elements */
Log_Arch_Client_Ctx()50   Log_Arch_Client_Ctx()
51       : m_state(ARCH_CLIENT_STATE_INIT),
52         m_group(nullptr),
53         m_begin_lsn(LSN_MAX),
54         m_end_lsn(LSN_MAX) {}
55 
56   /** Get redo file, header and trailer size
57   @param[out]	file_sz		redo file size
58   @param[out]	header_sz	redo header size
59   @param[out]	trailer_sz	redo trailer size */
60   void get_header_size(ib_uint64_t &file_sz, uint &header_sz, uint &trailer_sz);
61 
62   /** Start redo log archiving
63   @param[out]	header	redo header. Caller must allocate buffer.
64   @param[in]	len	buffer length
65   @return error code */
66   int start(byte *header, uint len);
67 
68   /** Stop redo log archiving
69   @param[out]	trailer	redo trailer. Caller must allocate buffer.
70   @param[in,out]	len	buffer length
71   @param[out]	offset	trailer block offset
72   @return error code */
73   int stop(byte *trailer, uint32_t &len, uint64_t &offset);
74 
75   /** Get archived data file details
76   @param[in]	cbk_func	callback called for each file
77   @param[in]	ctx		callback function context
78   @return error code */
79   int get_files(Log_Arch_Cbk *cbk_func, void *ctx);
80 
81   /** Release archived data so that system can purge it */
82   void release();
83 
84  private:
85   /** Archiver client state */
86   Arch_Client_State m_state;
87 
88   /** Archive group the client is attached to */
89   Arch_Group *m_group;
90 
91   /** Start LSN for archived data */
92   lsn_t m_begin_lsn;
93 
94   /** Stop LSN for archived data */
95   lsn_t m_end_lsn;
96 };
97 
98 #endif /* ARCH_LOG_INCLUDE */
99