Skip to content

Commit 272f380

Browse files
committed
Fix options and handling
1 parent fcfcb4c commit 272f380

File tree

6 files changed

+81
-69
lines changed

6 files changed

+81
-69
lines changed

client/innodb_log.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "log0test.h"
1515
#include "./mylog0recv.h"
1616

17+
uint opt_verbose_output = 0;
18+
1719
// read file containts to innodb_log.buf
1820
int innodb_log::read_file(std::string filepath) {
1921
std::ifstream file(filepath, std::ios::binary | std::ios::ate);
@@ -38,7 +40,6 @@ int innodb_log::read_file(std::string filepath) {
3840

3941
file_size = size;
4042
buf = (byte *)buffer;
41-
std::cout << "Read file Size: " << size << "\n";
4243

4344
return 0;
4445
}

client/innodb_log.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "log0types.h"
88
#include "log0files_io.h"
99

10+
extern uint opt_verbose_output;
11+
1012
class innodb_log {
1113
public:
1214
byte *buf;

client/mylog0recv.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,11 @@ static bool recv_single_rec(byte *ptr, byte *end_ptr) {
15291529
page_no_t page_no;
15301530
space_id_t space_id;
15311531

1532-
std::cout << "- recv_single_rec()" << std::endl;
1532+
std::cout << "- recv_single_rec()";
1533+
if(opt_verbose_output) {
1534+
std::cout << ", lsn: " << recv_sys->recovered_lsn;
1535+
}
1536+
std::cout << std::endl;
15331537

15341538
ulint len =
15351539
recv_parse_log_rec(&type, ptr, end_ptr, &space_id, &page_no, &body);
@@ -1626,7 +1630,11 @@ static bool recv_multi_rec(byte *ptr, byte *end_ptr) {
16261630
ulint n_recs = 0;
16271631
ulint total_len = 0;
16281632

1629-
std::cout << "- recv_multi_rec()" << std::endl;
1633+
std::cout << "- recv_multi_rec()";
1634+
if(opt_verbose_output) {
1635+
std::cout << ", lsn: " << recv_sys->recovered_lsn;
1636+
}
1637+
std::cout << std::endl;
16301638

16311639
for (;;) {
16321640
mlog_id_t type = MLOG_BIGGEST_TYPE;
@@ -1759,27 +1767,10 @@ ulint offset_limit = 50;
17591767
hash table to wait merging to file pages. */
17601768
void recv_parse_log_recs() {
17611769
ut_ad(recv_sys->parse_start_lsn != 0);
1762-
std::streambuf* original_stream = std::cout.rdbuf();
1763-
NullStream null_stream;
1764-
bool is_dummy_stream = false;
17651770

17661771
for (;;) {
1767-
if(!is_dummy_stream && recv_sys->parse_start_lsn + recv_sys->recovered_offset < recv_sys->start_lsn) {
1768-
// set cout stream to null_stream
1769-
std::cout.rdbuf(&null_stream);
1770-
is_dummy_stream = true;
1771-
} else if(is_dummy_stream && recv_sys->parse_start_lsn + recv_sys->recovered_offset >= recv_sys->start_lsn) {
1772-
// reset stream
1773-
std::cout.rdbuf(original_stream);
1774-
is_dummy_stream = false;
1775-
}
1776-
if(recv_sys->parse_start_lsn + recv_sys->recovered_offset >= recv_sys->stop_lsn) {
1777-
if(is_dummy_stream) {
1778-
// reset stream
1779-
std::cout.rdbuf(original_stream);
1780-
is_dummy_stream = false;
1781-
}
1782-
break;
1772+
if(recv_sys->recovered_lsn > recv_sys->stop_lsn) {
1773+
return;
17831774
}
17841775
byte *ptr = recv_sys->buf + recv_sys->recovered_offset;
17851776

client/mysqlredo.cc

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@
2727
#include "mylog0log.h"
2828

2929
static char *filepath = nullptr;
30-
static uint opt_verbose = 0;
31-
bool opt_header_only = false;
32-
ulong opt_stop_lsn = 0;
33-
ulong opt_start_lsn = 0;
30+
bool opt_with_header = false, opt_header_only = false;
31+
ulong opt_stop_lsn = 0, opt_start_lsn = 0;
3432

3533
static void get_options(int *argc, char ***argv);
3634

3735
static const char *load_default_groups[] = {"mysqlredo", "client", nullptr};
3836

3937
static struct my_option my_long_options[] = {
4038
{"help", '?', "Display this help and exit.", nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
41-
{"header-only", 'h', "Display redo log file's header info only.", nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
39+
{"header", 'h', "Display redo log file's header info.", nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
40+
{"header-only", 'H', "Display redo log file's header info only.", nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
4241
{"verbose", 'v', "More verbose output; (you can use this multiple times to get even more verbose output.)",
4342
nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
4443
{"start-lsn", 'b', "Set start lsn to print",
@@ -66,10 +65,13 @@ static bool get_one_option(int optid, const struct my_option *opt,
6665
char *argument) {
6766
switch (optid) {
6867
case 'h':
68+
opt_with_header = true;
69+
break;
70+
case 'H':
6971
opt_header_only = true;
7072
break;
7173
case 'v':
72-
opt_verbose++;
74+
opt_verbose_output++;
7375
break;
7476
case 'V':
7577
print_version();
@@ -98,6 +100,11 @@ int main(int argc, char **argv) {
98100
if (load_defaults("my", load_default_groups, &argc, &argv, &alloc)) exit(1);
99101
my_getopt_use_args_separator = false;
100102

103+
Log_checkpoint_header chpt_header;
104+
lsn_t checkpoint_lsn1 = 0, checkpoint_lsn2 = 0;
105+
lsn_t max_chpt_lsn = 0, start_chpt_lsn = 0;
106+
uint64_t start_chpt_offset, first_block_offset;
107+
101108
get_options(&argc, &argv);
102109

103110
/* Need to call ut_crc32 functions in log_file_header_deserialize() */
@@ -112,7 +119,7 @@ int main(int argc, char **argv) {
112119
}
113120

114121
filepath = argv[0];
115-
if(opt_verbose) {
122+
if(opt_verbose_output > 1) {
116123
std::cout << "filepath: " << filepath << std::endl;
117124
}
118125

@@ -126,43 +133,57 @@ int main(int argc, char **argv) {
126133
}
127134

128135
/* Deserialize header block */
129-
std::cout << "-- Header block" << std::endl;
130136
ret = iblog->deserialize_header();
131137
if(ret) {
132138
std::cerr << "Error: Failed to parse header." << std::endl;
133139
}
134140

135-
std::cout << "filesize: " << iblog->file_size << std::endl;
136-
std::cout << "m_format: " << iblog->header.m_format << std::endl;
137-
std::cout << "m_start_lsn: " << iblog->header.m_start_lsn << std::endl;
138-
std::cout << "m_creater_name: " << iblog->header.m_creator_name << std::endl;
139-
140-
std::cout << "-- Checkpoint blocks" << std::endl;
141-
Log_checkpoint_header chpt_header;
142-
lsn_t max_chpt_lsn = 0;
141+
/* Print header block info */
142+
if(opt_with_header || opt_header_only) {
143+
std::cout << "-- Header block" << std::endl;
144+
std::cout << "filesize: " << iblog->file_size << std::endl;
145+
std::cout << "m_format: " << iblog->header.m_format << std::endl;
146+
std::cout << "m_start_lsn: " << iblog->header.m_start_lsn << std::endl;
147+
std::cout << "m_creater_name: " << iblog->header.m_creator_name << std::endl;
148+
}
143149

144150
/* Deserialize checkpoint block 1 */
145151
if (!log_checkpoint_header_deserialize(iblog->buf + OS_FILE_LOG_BLOCK_SIZE, chpt_header)) {
146152
std::cout << "Error: redo log corrupted." << std::endl;
147153
}
148-
std::cout << "checkpoint 1: " << chpt_header.m_checkpoint_lsn << std::endl;
149-
if(max_chpt_lsn < chpt_header.m_checkpoint_lsn) {
150-
max_chpt_lsn = chpt_header.m_checkpoint_lsn;
151-
}
154+
checkpoint_lsn1 = chpt_header.m_checkpoint_lsn;
152155

153156
/* Deserialize checkpoint block 2 */
154157
if (!log_checkpoint_header_deserialize(iblog->buf + OS_FILE_LOG_BLOCK_SIZE*3, chpt_header)) {
155158
std::cout << "Error: redo log corrupted." << std::endl;
156159
}
157-
std::cout << "checkpoint 2: " << chpt_header.m_checkpoint_lsn << std::endl;
158-
if(max_chpt_lsn < chpt_header.m_checkpoint_lsn) {
159-
max_chpt_lsn = chpt_header.m_checkpoint_lsn;
160+
checkpoint_lsn2 = chpt_header.m_checkpoint_lsn;
161+
162+
// max_checkpoint_lsn
163+
if(checkpoint_lsn1 > checkpoint_lsn2) {
164+
max_chpt_lsn = checkpoint_lsn1;
165+
} else {
166+
max_chpt_lsn = checkpoint_lsn2;
160167
}
161168

162169
/* Calculate start_lsn offset */
163-
uint64_t first_block_offset = iblog->get_offset(ut_uint64_align_down(max_chpt_lsn, OS_FILE_LOG_BLOCK_SIZE), iblog->header.m_start_lsn);
164-
uint64_t max_chpt_offset = iblog->get_offset(max_chpt_lsn, iblog->header.m_start_lsn);
165-
std::cout << "first_block_offset: " << first_block_offset << std::endl;
170+
first_block_offset = iblog->get_offset(ut_uint64_align_down(max_chpt_lsn, OS_FILE_LOG_BLOCK_SIZE), iblog->header.m_start_lsn);
171+
172+
/* Print checkpoint blocks info */
173+
if(opt_with_header || opt_header_only) {
174+
std::cout << "-- Checkpoint blocks" << std::endl;
175+
std::cout << "checkpoint 1: " << checkpoint_lsn1 << std::endl;
176+
std::cout << "checkpoint 2: " << checkpoint_lsn2 << std::endl;
177+
std::cout << "first_block_offset: " << first_block_offset << std::endl;
178+
}
179+
if(opt_header_only) {
180+
return 0;
181+
}
182+
183+
/* overwrite first_block_offset */
184+
if(opt_start_lsn) {
185+
first_block_offset = iblog->get_offset(ut_uint64_align_down(opt_start_lsn, OS_FILE_LOG_BLOCK_SIZE), iblog->header.m_start_lsn);
186+
}
166187

167188
/* Read the block including checkpoint lsn */
168189
Log_data_block_header block_header;
@@ -176,21 +197,11 @@ int main(int argc, char **argv) {
176197
recv_sys_init(); /* initialize recv_sys */
177198
dict_persist_init();
178199

179-
/* set start/stop_lsn */
180-
if(opt_start_lsn) {
181-
recv_sys->start_lsn = opt_start_lsn;
182-
} else {
183-
recv_sys->start_lsn = ut_uint64_align_down(max_chpt_lsn, OS_FILE_LOG_BLOCK_SIZE) + block_header.m_first_rec_group;
184-
}
185-
if(opt_verbose) {
200+
if(opt_verbose_output > 1) {
186201
std::cout << "recv_sys->parse_start_lsn: " << ut_uint64_align_down(max_chpt_lsn, OS_FILE_LOG_BLOCK_SIZE) + block_header.m_first_rec_group << std::endl;
187202
}
188203
recv_sys->stop_lsn = opt_stop_lsn;
189204

190-
if(opt_header_only) {
191-
return 0;
192-
}
193-
194205
std::cout << "-- Normal blocks" << std::endl;
195206

196207
// initialize recv_sys->buf related by myself
@@ -199,13 +210,24 @@ int main(int argc, char **argv) {
199210
recv_sys->buf = static_cast<byte *>(
200211
ut::malloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, recv_sys->buf_len));
201212

202-
// // copy buf to recv_sys->buf
203-
// ut_memcpy(recv_sys->buf, iblog->buf, iblog->file_size);
204-
205-
206213
srv_log_buffer_size = iblog->file_size;
207214
// modify recv_recovery_begin
208-
bool finished = my_parse_begin(iblog->buf, max_chpt_lsn, max_chpt_lsn + iblog->file_size - max_chpt_offset, first_block_offset);
215+
if(opt_start_lsn != 0) {
216+
start_chpt_lsn = opt_start_lsn;
217+
start_chpt_offset = iblog->get_offset(start_chpt_lsn, iblog->header.m_start_lsn);
218+
} else {
219+
start_chpt_lsn = max_chpt_lsn;
220+
start_chpt_offset = iblog->get_offset(max_chpt_lsn, iblog->header.m_start_lsn);
221+
}
222+
if(opt_verbose_output) {
223+
std::cout << "start parsing from lsn of " << start_chpt_lsn << "(" << (start_chpt_lsn - start_chpt_lsn % 512) << ")";
224+
if(opt_stop_lsn) {
225+
std::cout << " to " << opt_stop_lsn;
226+
}
227+
std::cout << std::endl;
228+
}
229+
230+
bool finished = my_parse_begin(iblog->buf, start_chpt_lsn, start_chpt_lsn + iblog->file_size - start_chpt_offset, first_block_offset);
209231
if(!finished) {
210232
std::cerr << "Parse finished in the middle of file."<< std::endl;
211233
}

client/mysqlshow.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ static void get_options(int *argc, char ***argv) {
392392
We need to set verbose to 2 as we need to change the output to include
393393
the number-of-rows column
394394
*/
395-
opt_verbose = 2;
396-
}
395+
}
397396
if (debug_info_flag) my_end_arg = MY_CHECK_ERROR | MY_GIVE_INFO;
398397
if (debug_check_flag) my_end_arg = MY_CHECK_ERROR;
399398
return;

storage/innobase/include/log0recv.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,6 @@ struct recv_sys_t {
564564
start point not found yet */
565565
lsn_t parse_start_lsn;
566566

567-
/* start printing lsn */
568-
lsn_t start_lsn;
569-
570567
/* to end parse */
571568
lsn_t stop_lsn;
572569

0 commit comments

Comments
 (0)