Skip to content

Commit 92200ed

Browse files
committed
fix leveldb bug
1 parent 1da3381 commit 92200ed

6 files changed

Lines changed: 57 additions & 21 deletions

File tree

phxbinlogsvr/core/monitor/agent_monitor.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
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.
99
*/
1010

11-
1211
#include "agent_monitor.h"
1312

1413
#include "event_manager.h"
@@ -143,9 +142,11 @@ int AgentMonitor::Process() {
143142
MasterMonitor::CheckMySqlUserInfo(option_);
144143
uint32_t now = time(NULL);
145144
if (check_master && now - last_check >= option_->GetBinLogSvrConfig()->GetMonitorCheckStatusPeriod()) {
146-
CheckMasterTimeOut();
145+
int ret = CheckMasterTimeOut();
147146
CheckCheckPointFiles();
148-
last_check = now;
147+
if(ret == 0) {
148+
last_check = now;
149+
}
149150
}
150151
}
151152
return OK;
@@ -266,7 +267,7 @@ int AgentMonitor::CheckMasterInit() {
266267
vector < string > gtid_list;
267268
int ret = MasterMonitor::GetMySQLMaxGTIDList(option_, &gtid_list);
268269
if (ret)
269-
return false;
270+
return ret;
270271

271272
//get the max gtid in agent
272273
string last_gtid = event_manager_->GetNewestGTID();
@@ -354,11 +355,7 @@ int AgentMonitor::CheckMasterTimeOut() {
354355
}
355356

356357
int AgentMonitor::CheckSlaveRunningStatus() {
357-
if (IsSlaveReady()) {
358-
return SlaveMonitor::CheckSlaveRunningStatus(option_);
359-
}
360-
return MYSQL_FAIL;
361-
}
358+
return SlaveMonitor::CheckSlaveRunningStatus(option_);}
362359

363360
bool AgentMonitor::IsSlaveReady() {
364361

phxbinlogsvr/core/repl/replication_transfer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int ReplicationTransfer::Process() {
6363

6464
int ret = OK;
6565
//init the gtid to get the data pos
66-
while (1) {
66+
while (!ctx_->IsClose()) {
6767
vector < string > recv_buff;
6868
ret = ReadDataFromDC(&recv_buff);
6969
if (ret != OK && ret != DATA_EMPTY)

phxbinlogsvr/core/storage/event_storage.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int EventStorage::AddEvent(const string &gtid, const EventData &event_data, bool
223223
}
224224
ColorLogInfo("%s write data gtid %s instance id %llu checksum %llu ret %d file %s run %u ms",
225225
__func__, event_data.gtid().c_str(), event_data.instance_id(), event_data.checksum(), ret,
226-
data_info.file_name().c_str(), timer.GetTime()/1000 );
226+
data_info.file_name().c_str(), timer.GetTime()/1000 );
227227
return ret;
228228
}
229229

@@ -271,14 +271,15 @@ int EventStorage::GetEvent(EventData *data, bool wait) {
271271
}
272272

273273
int EventStorage::GetGTIDInfo(const string &gtid, EventDataInfo *data_info, bool lower_bound) {
274+
274275
if (lower_bound) {
275276
int ret = OK;
276277
{
277278
LockManager lock(&mutex_);
278279
ret = RealGetLowerBoundGTIDInfo(gtid, data_info);
279280
}
280281
if (ret == OK) {
281-
ret = EventStorage::CheckGtidInData(gtid, *data_info);
282+
ret = EventStorage::CheckGtidInData(gtid, *data_info, option_);
282283
}
283284
return ret;
284285
} else {
@@ -345,6 +346,7 @@ int EventStorage::DelCheckPointFile(const string &maxfilename, const uint32_t &m
345346
if (status != event_index_status::OK) {
346347
return FILE_FAIL;
347348
}
349+
usleep(100);
348350
}
349351
}
350352
RemoveFile(*file_name);
@@ -353,11 +355,11 @@ int EventStorage::DelCheckPointFile(const string &maxfilename, const uint32_t &m
353355
return OK;
354356
}
355357

356-
int EventStorage::CheckGtidInData(const string &gtid, const EventDataInfo &data_info) {
358+
int EventStorage::CheckGtidInData(const string &gtid, const EventDataInfo &data_info, const Option * option) {
357359
int ret = OK;
358360

359361
if (gtid == "" || data_info.gtid() == "" || data_info.file_name() == "") {
360-
EventFileManager eventfilemanager(option_);
362+
EventFileManager eventfilemanager(option);
361363
ret = eventfilemanager.OpenOldestFile();
362364
if (ret) {
363365
return ret;
@@ -373,7 +375,7 @@ int EventStorage::CheckGtidInData(const string &gtid, const EventDataInfo &data_
373375
return DATA_EMPTY;
374376
}
375377

376-
EventFileManager event_file_manager(option_, false);
378+
EventFileManager event_file_manager(option, false);
377379
ret = event_file_manager.SetReadPos(data_info);
378380
if (ret) {
379381
return ret;
@@ -413,7 +415,7 @@ int EventStorage::GetLastGtid(const vector<string> &gtid_list, string *gtid) {
413415
int ret = DATA_EMPTY;
414416
if (gtid_list.empty()) {
415417
EventDataInfo data_info;
416-
int check_ret = CheckGtidInData("", data_info);
418+
int check_ret = EventStorage::CheckGtidInData("", data_info, option_);
417419
if (check_ret == 0) {
418420
LogVerbose("%s check empty gtid from file_name %s offset %d", __func__,
419421
data_info.file_name().c_str(), data_info.offset());
@@ -438,7 +440,7 @@ int EventStorage::GetLastGtid(const vector<string> &gtid_list, string *gtid) {
438440
//LogVerbose("%s get gtid info %s file_name %s offset %d", __func__, data_info.gtid().c_str(),
439441
// data_info.file_name().c_str(), data_info.offset());
440442
if (max_data_info < data_info) {
441-
int check_ret = CheckGtidInData(gtid_list[i], data_info);
443+
int check_ret = EventStorage::CheckGtidInData(gtid_list[i], data_info, option_);
442444
if (check_ret == 0) {
443445
max_data_info = data_info;
444446
lastest_gtid = gtid_list[i];
@@ -483,6 +485,17 @@ int EventStorage::RealCheckGTID(const string &gtid, EventDataInfo *info) {
483485
}
484486

485487
int EventStorage::RealGetGTIDInfo(const string &gtid, EventDataInfo *data_info) {
488+
489+
int ret = uuid_handler_->GetLastestGTIDEventByGTID(gtid, data_info);
490+
if(ret==OK) {
491+
if(data_info->gtid()==gtid) {
492+
LogVerbose("%s mysql gtid %s, current lastest gtid %s, return competed from uuid, file %s",
493+
__func__, gtid.c_str(), data_info->gtid().c_str(),
494+
data_info->file_name().c_str());
495+
return OK;
496+
}
497+
}
498+
486499
event_index_status status = event_index_->GetGTID(gtid, data_info);
487500
LogVerbose("%s get gtid info %s ret %d, file %s", __func__, gtid.c_str(), status,
488501
data_info->file_name().c_str());
@@ -495,6 +508,17 @@ int EventStorage::RealGetGTIDInfo(const string &gtid, EventDataInfo *data_info)
495508
}
496509

497510
int EventStorage::RealGetLowerBoundGTIDInfo(const string &gtid, EventDataInfo *data_info) {
511+
512+
int ret = uuid_handler_->GetLastestGTIDEventByGTID(gtid, data_info);
513+
if(ret==OK) {
514+
if(data_info->gtid()==gtid) {
515+
LogVerbose("%s mysql gtid %s, current lastest gtid %s, return competed from uuid, file %s",
516+
__func__, gtid.c_str(), data_info->gtid().c_str(),
517+
data_info->file_name().c_str());
518+
return OK;
519+
}
520+
}
521+
498522
event_index_status status = event_index_->GetLowerBoundGTID(gtid, data_info);
499523
LogVerbose("%s get gtid info %s ret %d, file %s", __func__, gtid.c_str(), status,
500524
data_info->file_name().c_str());
@@ -562,7 +586,7 @@ int EventStorage::CheckAndSwitchFile(bool force) {
562586
EventData event_headerdata;
563587
int ret = GetFileHeader(&event_headerdata, &data_info);
564588
if (ret == 0) {
565-
ret = EventStorage::SwitchNewFile(event_headerdata);
589+
ret = SwitchNewFile(event_headerdata);
566590
}
567591
return ret;
568592
}

phxbinlogsvr/core/storage/event_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class EventStorage {
7979
int RealGetLowerBoundGTIDInfo(const std::string &gtid, EventDataInfo *data_info);
8080
int RealCheckGTID(const std::string &gtid, EventDataInfo *info);
8181
void CheckPointDone();
82-
int CheckGtidInData(const std::string &gtid, const EventDataInfo &datainfo);
82+
static int CheckGtidInData(const std::string &gtid, const EventDataInfo &datainfo, const Option *option);
8383

8484
private:
8585
EventFileManager *event_file_manager_;

phxbinlogsvr/core/storage/event_uuid_handler.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
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.
99
*/
1010

11-
1211
#include "event_uuid_handler.h"
1312

1413
#include "event_file_manager.h"
@@ -179,14 +178,27 @@ string EventUUIDHandler::GetLastestGTIDByGTID(const string &gtid) {
179178
return GetLastestGTIDByUUID(uuid);
180179
}
181180

181+
int EventUUIDHandler::GetLastestGTIDEventByGTID(const string &gtid, EventDataInfo *data_info) {
182+
string uuid = GtidHandler::GetUUIDByGTID(gtid);
183+
return GetLastestGTIDEventByUUID(uuid, data_info);
184+
}
185+
182186
string EventUUIDHandler::GetLastestGTIDByUUID(const string &uuid) {
183187
auto it = map_uuid_.find(uuid);
184188
if (it == map_uuid_.end())
185189
return "";
186-
LogVerbose("%s find gtid %s by uuid %s", __func__, it->second.gtid().c_str(), uuid.c_str());
187190
return it->second.gtid();
188191
}
189192

193+
int EventUUIDHandler::GetLastestGTIDEventByUUID(const string &uuid, EventDataInfo *data_info) {
194+
auto it = map_uuid_.find(uuid);
195+
if (it == map_uuid_.end())
196+
return 1;
197+
*data_info=it->second;
198+
return OK;
199+
}
200+
201+
190202
string EventUUIDHandler::GetLastestUpdateGTID() {
191203
return newest_info_.gtid();
192204
}

phxbinlogsvr/core/storage/event_uuid_handler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class EventUUIDHandler {
3939
std::string GetLastestGTIDByUUID(const std::string &uuid);
4040
uint64_t GetLastInstanceID();
4141

42+
int GetLastestGTIDEventByGTID(const std::string &gtid, EventDataInfo *data_info);
43+
int GetLastestGTIDEventByUUID(const std::string &uuid, EventDataInfo *data_info);
44+
4245
int FlushEventUUIDInfo();
4346

4447
std::string GetLastestUpdateGTID();

0 commit comments

Comments
 (0)