Skip to content

Commit

Permalink
fix gtid check
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcchen committed Jan 4, 2017
1 parent 2813721 commit 138e883
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
12 changes: 2 additions & 10 deletions phxbinlogsvr/core/handler/event_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,14 @@ int EventMonitor::CheckRunningStatus() {
int ret = OK;
vector < string > gtid_list;
if (option_->GetBinLogSvrConfig()->IsForceMakingCheckPoint()) {
ret = MasterMonitor::GetMySQLMaxGTIDList(option_, &gtid_list);
ret = MasterMonitor::GetMySQLMaxGTIDList(option_, &gtid_list,master_manager_->IsMaster());
} else {
vector < string > member_iplist;
master_manager_->GetMemberIPList(&member_iplist);

ret = MasterMonitor::GetGlobalMySQLMaxGTIDList(option_, member_iplist, &gtid_list);
}

if(master_manager_->IsMaster()) {
for (auto &gtid : gtid_list) {
gtid = MySqlManager::ReduceGtidByOne(gtid);
LogVerbose("%s master get new gtid %s",__func__, gtid.c_str());
}
}

LogVerbose("%s get gtid list ret %d", __func__, ret);
if (ret == OK) {
ret = storage_manager_->MakeCheckPoint(gtid_list);
Expand Down Expand Up @@ -98,5 +91,4 @@ int EventMonitor::Process() {
return OK;
}

}

}
30 changes: 17 additions & 13 deletions phxbinlogsvr/core/monitor/agent_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/


#include "agent_monitor.h"

#include "event_manager.h"
Expand Down Expand Up @@ -264,7 +263,7 @@ int AgentMonitor::CheckMasterInit() {
if (is_master) {
// get the current gtid in master binlog
vector < string > gtid_list;
int ret = MasterMonitor::GetMySQLMaxGTIDList(option_, &gtid_list);
int ret = MasterMonitor::GetMySQLMaxGTIDList(option_, &gtid_list, false);
if (ret)
return false;

Expand Down Expand Up @@ -308,7 +307,7 @@ int AgentMonitor::CheckMasterInit() {

int AgentMonitor::IsGTIDCompleted(const Option *option, EventManager *event_manager) {
vector < string > gtid_list;
int ret = MasterMonitor::GetMySQLMaxGTIDList(option, &gtid_list);
int ret = MasterMonitor::GetMySQLMaxGTIDList(option, &gtid_list, false);
if (ret) {
ColorLogWarning("%s get sql info fail, skip", __func__);
return SVR_FAIL;
Expand All @@ -320,18 +319,24 @@ int AgentMonitor::IsGTIDCompleted(const Option *option, EventManager *event_mana
return DATA_EMPTY;
}

if (AgentExternalMonitor::IsHealthy()) {
return OK;
}
ColorLogWarning("%s external monitor not healthy", __func__);
return SVR_FAIL;
return OK;
}

int AgentMonitor::CheckMasterTimeOut() {
int ret = IsGTIDCompleted(option_, event_manager_);
if (ret < 0) {
return ret;
bool is_master = master_manager_->CheckMasterBySvrID(option_->GetBinLogSvrConfig()->GetEngineSvrID());
int ret = OK;
if(!is_master) {
ret=IsGTIDCompleted(option_, event_manager_);
if (ret < 0) {
return ret;
}
}

if (!AgentExternalMonitor::IsHealthy()) {
ColorLogWarning("%s external monitor not healthy", __func__);
return SVR_FAIL;
}

if (ret == OK) {
int ret = master_agent_->SetMaster(option_->GetBinLogSvrConfig()->GetEngineIP());
if (ret == MASTER_CONFLICT) {
Expand All @@ -357,7 +362,7 @@ int AgentMonitor::CheckSlaveRunningStatus() {
bool AgentMonitor::IsSlaveReady() {

vector < string > gtid_list;
int ret = MasterMonitor::GetMySQLMaxGTIDList(option_, &gtid_list);
int ret = MasterMonitor::GetMySQLMaxGTIDList(option_, &gtid_list, false);
if (ret) {
ColorLogError("%s get sql info fail", __func__);
return false;
Expand All @@ -381,4 +386,3 @@ void AgentMonitor::CheckCheckPointFiles() {
}

}

14 changes: 10 additions & 4 deletions phxbinlogsvr/core/monitor/base/master_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ int MasterMonitor::MasterStart(const Option *option) {
return OK;
}

int MasterMonitor::GetMySQLMaxGTIDList(const Option *option, vector<string> *gtid_list) {
return MonitorComm::GetMySQLMaxGTIDList(option, "gtid_executed", gtid_list);
int MasterMonitor::GetMySQLMaxGTIDList(const Option *option, vector<string> *gtid_list, bool is_master) {
int ret = MonitorComm::GetMySQLMaxGTIDList(option, "gtid_executed", gtid_list);
if(ret==0&&is_master) {
for (auto &gtid : *gtid_list) {
gtid = MySqlManager::ReduceGtidByOne(gtid);
LogVerbose("%s master get new gtid %s",__func__, gtid.c_str());
}
}
return ret;
}

int MasterMonitor::GetGlobalMySQLMaxGTIDList(const Option *option, const vector<string> &iplist,
Expand Down Expand Up @@ -174,5 +181,4 @@ int MasterMonitor::CheckMasterPermisstion(const Option *option, const std::vecto
return MySqlManager::GetGlobalMySqlManager(option)->CheckAdminPermission(member_list);
}

}

}
3 changes: 1 addition & 2 deletions phxbinlogsvr/core/monitor/base/master_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

#pragma once

#include <string>
Expand All @@ -21,7 +20,7 @@ class MasterMonitor {
public:
static int GetGlobalMySQLMaxGTIDList(const Option *option, const std::vector<std::string> &iplist,
std::vector<std::string> *gtid_list);
static int GetMySQLMaxGTIDList(const Option *option, std::vector<std::string> *gtid_list);
static int GetMySQLMaxGTIDList(const Option *option, std::vector<std::string> *gtid_list, bool is_master);

static int MasterStart(const Option *option);

Expand Down
2 changes: 1 addition & 1 deletion phxbinlogsvr/core/mysql/mysql_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int MySqlManager::CheckUserGrantExist(const string &username, const string &pwd,
mysql_option.port = option_->GetMySqlConfig()->GetMySQLPort();
mysql_option.username = username;
mysql_option.pwd = pwd;
LogVerbose("%s username %s pwd %s", __func__, mysql_option.username.c_str(), mysql_option.pwd.c_str());
//LogVerbose("%s username %s pwd %s", __func__, mysql_option.username.c_str(), mysql_option.pwd.c_str());

vector < vector < string >> results;
int ret = MySQLCommand(&mysql_option).GetQueryResults(grant_string, &results);
Expand Down
10 changes: 5 additions & 5 deletions phxbinlogsvr/core/paxos/event_executer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/


#include "event_executer.h"

#include "storage_manager.h"
Expand Down Expand Up @@ -90,17 +91,17 @@ int EventExecuter::SMExecute(const uint64_t &instance_id, const string &paxos_va
return GTID_CONFLICT;
}
}

uint64_t old_checksum = 0;
int ret = event_manager_->GetNowCheckSum(&old_checksum);
if (ret) {
ColorLogError("%s get now check sum fail ret %d", __func__, ret);
return ret;
}

LogVerbose("%s current gtid %s event gtid %s sm gtid %s old checksum %llu run %u ms", __func__,
data.current_gtid().c_str(), data.event_gtid().c_str(), newest_gtid.c_str(), old_checksum,
timer.GetTime() / 1000);
//LogVerbose("%s current gtid %s event gtid %s sm gtid %s old checksum %llu run %u ms", __func__,
// data.current_gtid().c_str(), data.event_gtid().c_str(), newest_gtid.c_str(), old_checksum,
// timer.GetTime() / 1000);

uint64_t new_checksum = Utils::GetCheckSum(old_checksum, data.buffer().c_str(), data.buffer().size());
if (new_checksum != data.checksum()) {
Expand Down Expand Up @@ -158,4 +159,3 @@ int EventExecuter::LoadCheckpointState(const int group_idx, const string &checkp
}

}

10 changes: 5 additions & 5 deletions phxbinlogsvr/core/storage/event_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ event_index_status EventIndex::SetGTIDIndex(const string &gtid, const ::google::
return event_index_status::DATA_ERROR;
}

LogVerbose("%s gtid %s", __func__, gtid.c_str());
//LogVerbose("%s gtid %s", __func__, gtid.c_str());
leveldb::Status status = level_db_->Put(leveldb::WriteOptions(), gtid, buffer);
return status.ok() ? event_index_status::OK : event_index_status::DB_ERROR;
}

event_index_status EventIndex::GetGTID(const string &gtid, ::google::protobuf::Message *data_info) {
return GetGTIDIndex(gtid, data_info, false);
return GetGTIDIndex(gtid, data_info, false );
}

event_index_status EventIndex::GetLowerBoundGTID(const string &gtid, ::google::protobuf::Message *data_info) {
event_index_status EventIndex::GetLowerBoundGTID(const string &gtid,
::google::protobuf::Message *data_info) {
return GetGTIDIndex(gtid, data_info, true);
}

Expand Down Expand Up @@ -137,5 +138,4 @@ event_index_status EventIndex::DeleteGTIDIndex(const string &gtid) {
return event_index_status::DB_ERROR;
}

}

}
7 changes: 3 additions & 4 deletions phxbinlogsvr/core/storage/event_uuid_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/


#include "event_uuid_handler.h"

#include "event_file_manager.h"
Expand All @@ -27,7 +28,6 @@ using phxsql::ColorLogError;
namespace phxbinlog {

bool operator <(const EventDataInfo &info1, const EventDataInfo &info2) {
LogVerbose("%s instance id %llu %llu", __func__, info1.instance_id(), info2.instance_id());
return info1.instance_id() < info2.instance_id();
}

Expand Down Expand Up @@ -157,8 +157,8 @@ int EventUUIDHandler::UpdateEventUUIDInfoByGTID(const string &gtid, const EventD
}

int EventUUIDHandler::UpdateEventUUIDInfoByUUID(const string &uuid, const EventDataInfo &data_info) {
LogVerbose("%s update gtid uuid %s-%s instance id %llu", __func__, uuid.c_str(), data_info.gtid().c_str(),
data_info.instance_id());
//LogVerbose("%s update gtid uuid %s-%s instance id %llu", __func__, uuid.c_str(), data_info.gtid().c_str(),
// data_info.instance_id());
map_uuid_[uuid] = data_info;
newest_info_ = data_info;
return OK;
Expand Down Expand Up @@ -251,4 +251,3 @@ int EventUUIDHandler::ParseFromString(const string &buffer) {
}

}

0 comments on commit 138e883

Please sign in to comment.