Skip to content

Fix parse time and add timeouts. #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions percona_playback/mysql_client/mysql_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ bool MySQLDBThread::connect()
do {
num_tries++;
mysql_init(&handle);
// Set a timeout. for various operations
uint32_t mysql_connect_timeout = 300;
uint32_t mysql_timeout = 5;
if (mysql_options(&handle, MYSQL_OPT_CONNECT_TIMEOUT, &mysql_connect_timeout)) {
fprintf(stderr, "Failed to set MYSQL_OPT_CONNECT_TIMEOUT");
abort();
}
if (mysql_options(&handle, MYSQL_OPT_READ_TIMEOUT, &mysql_timeout)) {
fprintf(stderr, "Failed to set MYSQL_OPT_READ_TIMEOUT");
abort();
}
if (mysql_options(&handle, MYSQL_OPT_WRITE_TIMEOUT, &mysql_timeout)) {
fprintf(stderr, "Failed to set MYSQL_OPT_WRITE_TIMEOUT");
abort();
}

had_too_many_connections = false;
if (!mysql_real_connect(&handle,
options->host.c_str(),
Expand Down
14 changes: 8 additions & 6 deletions percona_playback/query_log/query_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,24 @@ static boost::string_ref trim(boost::string_ref str, boost::string_ref chars = "

static bool parse_time(boost::string_ref s, QueryLogData::TimePoint& start_time) {
// Time can look like this
// # Time: 090402 9:23:36
// or like this if microseconds granularity is configured.
// # Time: 090402 9:23:36.123456
// # Time: 2023-10-19T19:07:56.494508Z
long long msecs = 0;
std::tm td;
memset(&td, 0, sizeof(td));
std::string line(s.begin(), s.end());
int num_read = sscanf(line.c_str(), "# Time: %02d%02d%02d %2d:%02d:%02d.%06lld",
int num_read = sscanf(line.c_str(), "# Time: %04d-%02d-%02dT%2d:%02d:%02d.%06lldZ",
&td.tm_year, &td.tm_mon, &td.tm_mday, &td.tm_hour, &td.tm_min, &td.tm_sec, &msecs);
if (num_read < 6)
if (num_read < 7) {
printf("Failed to parse ts\n");
return false;
}

// months [0, 11]
td.tm_mon -= 1;
// years since 1900
td.tm_year += td.tm_year < 70 ? 100 : 0;
td.tm_year -= 1900;

// std::cout << std::asctime(&td) << " " << msecs << std::flush;
start_time = boost::chrono::system_clock::from_time_t(std::mktime(&td));
start_time += boost::chrono::microseconds(msecs);

Expand Down