Skip to content

Commit 7aa9c9c

Browse files
committed
update log info
1 parent 2c7333b commit 7aa9c9c

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.associations": {
3+
"center_head": "cpp",
4+
"common_head": "cpp"
5+
}
6+
}

Src/Center/Center.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ void center::read_config()
7676
//交换主副配置指针
7777
swap(telemeter::setting_copy, telemeter::setting); //atomic operation
7878

79+
LOG_INFO << "read config, interval: " << next_read_interval * 1000 << "s, current setting:";
80+
LOG_INFO << "load record interval: " << telemeter::setting->mir_load_record_interval_;
81+
LOG_INFO << "load database interval: " << telemeter::setting->mir_dblog_interval_;
82+
LOG_INFO << "load balance interval: " << telemeter::setting->load_balance_interval_;
83+
LOG_INFO << "max disbeat interval: " << telemeter::setting->mir_max_disbeat_time_;
84+
LOG_INFO << "clear mirs data time: " << telemeter::setting->clear_mirs_data_time_;
85+
LOG_INFO << "login cache time: " << telemeter::setting->cli_login_cache_time_;
7986
//挂起该进程
8087
sleep(next_read_interval * 1000);
8188
}
@@ -92,6 +99,7 @@ void center::wait_cli_login()
9299

93100
//纠正树形结构中cli信息的任务, 将交给线程池异步执行
94101
auto correct_tree_structure = [&](uuid cli_id){
102+
LOG_INFO << "correct info in tree-like structure of client id: " << cli_id;
95103
for(auto& kvp : mirs_data_)
96104
{
97105
if(kvp.second.contains(cli_id))
@@ -196,6 +204,7 @@ void center::wait_cli_login()
196204

197205
//数据库记录日志
198206
//dblog(cli_login, uid);
207+
LOG_INFO << "client login, uid: " << uid << ", reply mirs ip: " << available_mir.to_string();
199208
if(this->all_cli_.count(uid) == 0)
200209
this->all_cli_.insert(uid);
201210
else
@@ -220,8 +229,10 @@ void center::wait_cli_login()
220229
if(atom_mutex_ == false)
221230
{
222231
atom_mutex_ = true;
232+
uuid id = cookie_.front();
223233
cookie_.pop_front();
224234
atom_mutex_ = false;
235+
LOG_INFO << "erase login cache of client: " << id;
225236
}
226237
else
227238
continue;
@@ -314,6 +325,7 @@ void center::listen_mir_beat()
314325
int i = 3; //占位避免编译器报warning
315326
//dblog(MIR_DISCONECT);
316327
mirs_data_.erase(kvp.first);
328+
LOG_INFO << "mirror disconnect: " << const_cast<IP*>(&kvp.first)->to_string();
317329
}
318330
}
319331
}
@@ -324,16 +336,28 @@ void center::listen_mir_beat()
324336

325337
void center::clear_mirs_data()
326338
{
327-
//while(true)
339+
auto get_next_zeropoint = [](){
340+
time_t t = time(NULL);
341+
struct tm * tm= localtime(&t);
342+
tm->tm_mday += 1;
343+
tm->tm_hour = 0;
344+
tm->tm_min = 0;
345+
tm->tm_sec = 0;
346+
return mktime(tm);
347+
};
348+
349+
while(true)
328350
{
329-
//sleep(nowtime - nextzeropoint + setting->clear_mirsdata_time);
330-
//mirs_data_.clear();
331-
//all_cli_.clear();
351+
sleep(get_next_zeropoint() - time(NULL) + telemeter::setting->clear_mirs_data_time_);
352+
mirs_data_.clear();
353+
all_cli_.clear();
354+
LOG_INFO << "clear mirrors data successfully";
332355
}
333356
}
334357

335358
IP center::load_balance()
336359
{
360+
LOG_INFO << "load balance occurs";
337361
//暂时不优化
338362
for(auto& kvp : mirs_data_)
339363
{
@@ -379,7 +403,7 @@ void center::log_info(std::exception& e, const char* crush_file)
379403
log << "Mirrors & dispatched client:\n";
380404
for(auto& kvp : mirs_data_)
381405
{
382-
log << "ip: " << kvp.first
406+
log << "ip: " << const_cast<IP*>(&kvp.first)->to_string()
383407
<< " load state: " << tostring(kvp.second.get_load_level()) << '\n';
384408
log << "dispatched client: \n";
385409
for(auto uid : kvp.second.get_dispatched_cli())

include/Common/Udp.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ struct IP {
6464
this->seg2 = res[2];
6565
this->seg3 = res[3];
6666
}
67+
68+
std::string to_string()
69+
{
70+
return std::to_string(this->seg0) + '.' + std::to_string(this->seg1) + '.' + std::to_string(this->seg2) + '.' + std::to_string(this->seg3);
71+
}
6772
};
6873

6974
bool GetHostInfo(std::string& hostName, std::string& Ip) {

include/center/center.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <thread>
1717

1818
#include <muduo/base/ThreadPool.h>
19+
#include <muduo/base/Logging.h>
1920

2021
#include <common_head>
2122

0 commit comments

Comments
 (0)