Skip to content

Commit

Permalink
remove trimmed gtid from retrieved gtid set
Browse files Browse the repository at this point in the history
Summary: When raft logs are trimmed as part of TruncateOpsAfter(), the gtid of the trimmed trxs are also removed from executed/logged gtids. However, when binlog files are rotated, the previous gtid written to the new file depends on what files are rotated. During  binlog rotation the prev gtid are the logged/executed gtids of the instance. During relay log rotation prev gtids are the retrieved gtids of the instance. Hence, in addition to trimming logged gtids/executed gtids, we should also trim retrieved gtids. This prevents creation of holes in the instances executed_gtid set as the replicaset goes through multiple promotions over its lifetime.

Reviewed By: anirbanr-fb

Differential Revision: D21375044

fbshipit-source-id: 96fb274cca7
  • Loading branch information
bhatvinay authored and facebook-github-bot committed Oct 6, 2020
1 parent f082948 commit 7fc9eaa
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
15 changes: 15 additions & 0 deletions sql/binlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12577,6 +12577,21 @@ int trim_logged_gtid(const std::vector<std::string>& trimmed_gtids)

int error = gtid_state->remove_logged_gtid_on_trim(trimmed_gtids);

#ifdef HAVE_REPLICATION
if (active_mi && active_mi->rli)
{
// Remove rli logged gtids. Note that retrieved gtid is not cleared here
// since it is going to be updated when the next gtid is fetched
error = active_mi->rli->remove_logged_gtids(trimmed_gtids);
}
else
{
// NO_LINT_DEBUG
sql_print_information("active_mi or rli is not set. Hence not trimming "
"logged gtids from rli");
}
#endif

global_sid_lock->unlock();

return error;
Expand Down
17 changes: 15 additions & 2 deletions sql/rpl_gtid_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,26 @@ enum_return_status Gtid_state::remove_logged_gtid_on_trim(
const auto& first_gtid= trimmed_gtids.front();

Gtid gtid;
gtid.parse(global_sid_map, first_gtid.c_str());
if (gtid.parse(global_sid_map, first_gtid.c_str()) != RETURN_STATUS_OK)
{
// NO_LINT_DEBUG
sql_print_error("Failed to parse gtid %s", first_gtid.c_str());
RETURN_REPORTED_ERROR;
}

rpl_sidno first_sidno= gtid.sidno;
sid_locks.lock(first_sidno);

for (const auto& trimmed_gtid : trimmed_gtids)
{
gtid.parse(global_sid_map, trimmed_gtid.c_str());
if (gtid.parse(global_sid_map, trimmed_gtid.c_str()) != RETURN_STATUS_OK)
{
// NO_LINT_DEBUG
sql_print_error("Failed to parse gtid %s", trimmed_gtid.c_str());
sid_locks.unlock(first_sidno);
RETURN_REPORTED_ERROR;
}

DBUG_ASSERT(first_sidno == gtid.sidno);
if (gtid.sidno > 0)
{
Expand Down
41 changes: 41 additions & 0 deletions sql/rpl_rli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,47 @@ a file name for --relay-log-index option.", opt_relaylog_index_name);
DBUG_RETURN(error);
}

int Relay_log_info::remove_logged_gtids(
const std::vector<std::string>& trimmed_gtids)
{
DBUG_ENTER("Relay_log_info::remove_logged_gtid");
global_sid_lock->assert_some_lock();

if (trimmed_gtids.empty())
RETURN_OK;


Gtid gtid;
for (const auto& trimmed_gtid : trimmed_gtids)
{
if (gtid.parse(global_sid_map, trimmed_gtid.c_str()) != RETURN_STATUS_OK)
{
// NO_LINT_DEBUG
sql_print_error("Failed to parse gtid %s", trimmed_gtid.c_str());
RETURN_REPORTED_ERROR;
}

if (gtid.sidno > 0)
{
/* Remove Gtid from logged_gtid set. */
DBUG_PRINT(
"info", ("Removing gtid(sidno:%d, gno:%lld) from rli logged gtids",
gtid.sidno, gtid.gno));

if (gtid_set._remove_gtid(gtid) != RETURN_STATUS_OK)
{
// NO_LINT_DEBUG
sql_print_error("Failed to remove gtid(sidno:%d, gno: %lld) from "
"rli logged gtids. ", gtid.sidno, gtid.gno);
RETURN_REPORTED_ERROR;

}
}
}

RETURN_OK;
}

void Relay_log_info::end_info()
{
DBUG_ENTER("Relay_log_info::end_info");
Expand Down
3 changes: 3 additions & 0 deletions sql/rpl_rli.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ class Relay_log_info : public Rpl_info
ret= 1;
return ret;
}

int remove_logged_gtids(const std::vector<std::string>& trimmed_gtids);

const Gtid_set *get_gtid_set() const { return &gtid_set; }

Gtid_set *get_gtid_set_nc() { return &gtid_set; }
Expand Down

0 comments on commit 7fc9eaa

Please sign in to comment.