Skip to content

Commit a359bce

Browse files
author
Maitrayi Sabaratnam
committed
Enh 34110068 - Request to get more timestamps into the output of ndb_restore
Prefix the ndb_restore outputs with a timestamp, managed by the new bool option : "--timestamp_printouts". By default, it is 'false' in in 7.5/7.6. So there is no changes to tests. However, one test (ndb_restore_print_sql_log) is changed to use the option to 'true' in order to test that it is working. The test is also changed to mask timestamps from the restore output with 'X' to avoid tests running on different dates give 'Result content mismatch'. Reviewed by: Martin Skold <Martin.Skold@oracle.com> Change-Id: Ic183206e4d0f1d065d6448d03172a04217d4f4a0
1 parent db483dd commit a359bce

File tree

5 files changed

+63
-34
lines changed

5 files changed

+63
-34
lines changed

mysql-test/suite/ndb/r/ndb_restore_print_sql_log.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ insert into t7 values(1,'a');
8181
drop table t8;
8282

8383
"Restore with --print-sql-log option"
84-
Found column of type blob with print-sql-log option set. Exiting...
84+
XXXX-XX-XX XX:XX:XX Found column of type blob with print-sql-log option set. Exiting...
8585
drop table t7;
8686
drop table if exists t8;

mysql-test/suite/ndb/t/ndb_restore_print_sql_log.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,15 @@ while ($mysql_errno)
238238
--echo
239239
--echo "Restore with --print-sql-log option"
240240
--let ndb_restore_opts= --print-sql-log --verbose=0 --core-file=0
241+
242+
# ndb_restore should now fail with
243+
# "Found column of type blob with print-sql-log option set. Exiting..."
244+
# By using option '-t', the error msg will be prefixed with the timestamp.
245+
# Mask the digits of the timestamp with 'X's to avoid mtr test failing with
246+
# 'Result content mismatch'.
247+
--replace_regex /[0-9]*-[0-9]*-[0-9]* [0-9]*:[0-9]*:[0-9]*/XXXX-XX-XX XX:XX:XX/
241248
--error 1
242-
--exec $NDB_RESTORE --no-defaults $ndb_restore_opts -b $the_backup_id -n 1 $NDB_BACKUPS-$the_backup_id 2>&1
249+
--exec $NDB_RESTORE --no-defaults $ndb_restore_opts -b $the_backup_id --timestamp_printouts=true -n 1 $NDB_BACKUPS-$the_backup_id 2>&1
243250

244251
drop table t7;
245252
--disable_warnings

storage/ndb/tools/restore/Restore.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,8 @@ LogEntry::printSqlLog() const {
23162316
ndbout << ";";
23172317
}
23182318

2319+
RestoreLogger::RestoreLogger():print_timestamp(false) {}
2320+
23192321
void RestoreLogger::log_error(const char* fmt, ...)
23202322
{
23212323
va_list ap;
@@ -2324,6 +2326,10 @@ void RestoreLogger::log_error(const char* fmt, ...)
23242326
vsnprintf(buf, sizeof(buf), fmt, ap);
23252327
va_end(ap);
23262328

2329+
if (print_timestamp) {
2330+
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
2331+
err << timestamp << " ";
2332+
}
23272333
err << buf << endl;
23282334
}
23292335

@@ -2335,6 +2341,10 @@ void RestoreLogger::log_info(const char* fmt, ...)
23352341
vsnprintf(buf, sizeof(buf), fmt, ap);
23362342
va_end(ap);
23372343

2344+
if (print_timestamp) {
2345+
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
2346+
info << timestamp << " ";
2347+
}
23382348
info << buf << endl;
23392349
}
23402350

@@ -2346,9 +2356,23 @@ void RestoreLogger::log_debug(const char* fmt, ...)
23462356
vsnprintf(buf, sizeof(buf), fmt, ap);
23472357
va_end(ap);
23482358

2359+
if (print_timestamp) {
2360+
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
2361+
debug << timestamp << " ";
2362+
}
23492363
debug << buf << endl;
23502364
}
23512365

2366+
void
2367+
RestoreLogger::set_print_timestamp(bool print_TS) {
2368+
print_timestamp = print_TS;
2369+
}
2370+
2371+
bool
2372+
RestoreLogger::get_print_timestamp() {
2373+
return print_timestamp;
2374+
}
2375+
23522376
NdbOut &
23532377
operator<<(NdbOut& ndbout, const TableS & table)
23542378
{

storage/ndb/tools/restore/Restore.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,18 @@ class RestoreLogIterator : public BackupFile {
526526

527527
class RestoreLogger {
528528
public:
529+
RestoreLogger();
529530
void log_info(const char* fmt, ...)
530531
ATTRIBUTE_FORMAT(printf, 2, 3);
531532
void log_debug(const char* fmt, ...)
532533
ATTRIBUTE_FORMAT(printf, 2, 3);
533534
void log_error(const char* fmt, ...)
534535
ATTRIBUTE_FORMAT(printf, 2, 3);
536+
void set_print_timestamp(bool print_TS);
537+
bool get_print_timestamp();
538+
private:
539+
char timestamp[64];
540+
bool print_timestamp;
535541
};
536542

537543
NdbOut& operator<<(NdbOut& ndbout, const TableS&);

storage/ndb/tools/restore/restore_main.cpp

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Vector<BaseString> g_include_databases, g_exclude_databases;
7777
Properties g_rewrite_databases;
7878
NdbRecordPrintFormat g_ndbrecord_print_format;
7979
unsigned int opt_no_binlog;
80+
static bool opt_timestamp_printouts;
8081

8182
class RestoreOption
8283
{
@@ -146,6 +147,10 @@ static bool opt_restore_privilege_tables = false;
146147
static struct my_option my_long_options[] =
147148
{
148149
NDB_STD_OPTS("ndb_restore"),
150+
{ "timestamp_printouts", NDB_OPT_NOSHORT,
151+
"Add a timestamp to the logger messages info, error and debug",
152+
(uchar**) &opt_timestamp_printouts, (uchar**) &opt_timestamp_printouts, 0,
153+
GET_BOOL, NO_ARG, false, 0, 0, 0, 0, 0 },
149154
{ "connect", 'c', "same as --connect-string",
150155
(uchar**) &opt_ndb_connectstring, (uchar**) &opt_ndb_connectstring, 0,
151156
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
@@ -603,6 +608,9 @@ readArguments(int *pargc, char*** pargv)
603608
{
604609
exit(NdbRestoreStatus::WrongArgs);
605610
}
611+
if (opt_timestamp_printouts) {
612+
restoreLogger.set_print_timestamp(true);
613+
}
606614
if (ga_nodeId == 0)
607615
{
608616
err << "Backup file node ID not specified, please provide --nodeid" << endl;
@@ -1320,8 +1328,6 @@ main(int argc, char** argv)
13201328

13211329
init_progress();
13221330

1323-
char timestamp[64];
1324-
13251331
/**
13261332
* we must always load meta data, even if we will only print it to stdout
13271333
*/
@@ -1336,8 +1342,7 @@ main(int argc, char** argv)
13361342
}
13371343
#endif
13381344

1339-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1340-
restoreLogger.log_info("%s [restore_metadata] Read meta data file header", timestamp);
1345+
restoreLogger.log_info("[restore_metadata] Read meta data file header");
13411346

13421347
if (!metaData.readHeader())
13431348
{
@@ -1390,8 +1395,7 @@ main(int argc, char** argv)
13901395
}
13911396

13921397
restoreLogger.log_debug("Load content");
1393-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1394-
restoreLogger.log_info("%s [restore_metadata] Load content", timestamp);
1398+
restoreLogger.log_info("[restore_metadata] Load content");
13951399

13961400
int res = metaData.loadContent();
13971401

@@ -1404,8 +1408,7 @@ main(int argc, char** argv)
14041408
exitHandler(NdbRestoreStatus::Failed);
14051409
}
14061410
restoreLogger.log_debug("Get number of Tables");
1407-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1408-
restoreLogger.log_info("%s [restore_metadata] Get number of Tables", timestamp);
1411+
restoreLogger.log_info("[restore_metadata] Get number of Tables");
14091412
if (metaData.getNoOfTables() == 0)
14101413
{
14111414
restoreLogger.log_error("The backup contains no tables");
@@ -1453,8 +1456,7 @@ main(int argc, char** argv)
14531456
}
14541457

14551458
restoreLogger.log_debug("Validate Footer");
1456-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1457-
restoreLogger.log_info("%s [restore_metadata] Validate Footer", timestamp);
1459+
restoreLogger.log_info("[restore_metadata] Validate Footer");
14581460

14591461
if (!metaData.validateFooter())
14601462
{
@@ -1481,8 +1483,7 @@ main(int argc, char** argv)
14811483
g_consumers[i]->report_started(ga_backupId, ga_nodeId);
14821484

14831485
restoreLogger.log_debug("Restore objects (tablespaces, ..)");
1484-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1485-
restoreLogger.log_info("%s [restore_metadata] Restore objects (tablespaces, ..)", timestamp);
1486+
restoreLogger.log_info("[restore_metadata] Restore objects (tablespaces, ..)");
14861487
for(i = 0; i<metaData.getNoOfObjects(); i++)
14871488
{
14881489
for(Uint32 j= 0; j < g_consumers.size(); j++)
@@ -1504,8 +1505,7 @@ main(int argc, char** argv)
15041505

15051506
Vector<OutputStream *> table_output(metaData.getNoOfTables());
15061507
restoreLogger.log_debug("Restoring tables");
1507-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1508-
restoreLogger.log_info("%s [restore_metadata] Restoring tables", timestamp);
1508+
restoreLogger.log_info("[restore_metadata] Restoring tables");
15091509

15101510
for(i = 0; i<metaData.getNoOfTables(); i++)
15111511
{
@@ -1573,8 +1573,7 @@ main(int argc, char** argv)
15731573
}
15741574

15751575
restoreLogger.log_debug("Save foreign key info");
1576-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1577-
restoreLogger.log_info("%s [restore_metadata] Save foreign key info", timestamp);
1576+
restoreLogger.log_info("[restore_metadata] Save foreign key info");
15781577
for(i = 0; i<metaData.getNoOfObjects(); i++)
15791578
{
15801579
for(Uint32 j= 0; j < g_consumers.size(); j++)
@@ -1608,8 +1607,7 @@ main(int argc, char** argv)
16081607
g_consumers[i]->report_meta_data(ga_backupId, ga_nodeId);
16091608
}
16101609
restoreLogger.log_debug("Iterate over data");
1611-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1612-
restoreLogger.log_info("%s [restore_data] Start restoring table data", timestamp);
1610+
restoreLogger.log_info("[restore_data] Start restoring table data");
16131611
if (ga_restore || ga_print)
16141612
{
16151613
if(_restore_data || _print_data)
@@ -1675,9 +1673,8 @@ main(int argc, char** argv)
16751673
restoreLogger.log_error("Unable to allocate memory for RestoreDataIterator constructor");
16761674
exitHandler(NdbRestoreStatus::Failed);
16771675
}
1678-
1679-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1680-
restoreLogger.log_info("%s [restore_data] Read data file header", timestamp);
1676+
1677+
restoreLogger.log_info("[restore_data] Read data file header");
16811678

16821679
// Read data file header
16831680
if (!dataIter.readHeader())
@@ -1686,9 +1683,8 @@ main(int argc, char** argv)
16861683
"Failed to read header of data file. Exiting...");
16871684
exitHandler(NdbRestoreStatus::Failed);
16881685
}
1689-
1690-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1691-
restoreLogger.log_info("%s [restore_data] Restore fragments", timestamp);
1686+
1687+
restoreLogger.log_info("[restore_data] Restore fragments");
16921688

16931689
Uint32 fragmentId;
16941690
while (dataIter.readFragmentHeader(res= 0, &fragmentId))
@@ -1759,8 +1755,7 @@ main(int argc, char** argv)
17591755
{
17601756
RestoreLogIterator logIter(metaData);
17611757

1762-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1763-
restoreLogger.log_info("%s [restore_log] Read log file header", timestamp);
1758+
restoreLogger.log_info("[restore_log] Read log file header");
17641759

17651760
if (!logIter.readHeader())
17661761
{
@@ -1771,8 +1766,7 @@ main(int argc, char** argv)
17711766

17721767
const LogEntry * logEntry = 0;
17731768

1774-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1775-
restoreLogger.log_info("%s [restore_log] Restore log entries", timestamp);
1769+
restoreLogger.log_info("[restore_log] Restore log entries");
17761770

17771771
while ((logEntry = logIter.getNextLogEntry(res= 0)) != 0)
17781772
{
@@ -1848,8 +1842,7 @@ main(int argc, char** argv)
18481842
}
18491843
if (ga_restore_epoch)
18501844
{
1851-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1852-
restoreLogger.log_info("%s [restore_epoch] Restoring epoch", timestamp);
1845+
restoreLogger.log_info("[restore_epoch] Restoring epoch");
18531846
RestoreLogIterator logIter(metaData);
18541847

18551848
if (!logIter.readHeader())
@@ -1882,8 +1875,7 @@ main(int argc, char** argv)
18821875
if (ga_rebuild_indexes)
18831876
{
18841877
restoreLogger.log_debug("Rebuilding indexes");
1885-
Logger::format_timestamp(time(NULL), timestamp, sizeof(timestamp));
1886-
restoreLogger.log_info("%s [rebuild_indexes] Rebuilding indexes", timestamp);
1878+
restoreLogger.log_info("[rebuild_indexes] Rebuilding indexes");
18871879

18881880
for(i = 0; i<metaData.getNoOfTables(); i++)
18891881
{

0 commit comments

Comments
 (0)