Skip to content

Commit 7e0141c

Browse files
Mixficsolwuxianrong
andauthored
fix: fix exit core (OpenAtomFoundation#3050)
* fix exit core --------- Co-authored-by: wuxianrong <[email protected]>
1 parent bfd8cf8 commit 7e0141c

5 files changed

Lines changed: 18 additions & 12 deletions

File tree

conf/pika.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ admin-thread-pool-size : 2
4545
slow-cmd-list :
4646

4747
# List of commands considered as administrative. These commands will be handled by the admin thread pool. Modify this list as needed.
48-
# Default commands: info, ping, monitor
48+
# Default commands: info, ping, monitor, auth
4949
# This parameter is only supported by the CONFIG GET command and not by CONFIG SET.
50-
admin-cmd-list : info, ping, monitor
50+
admin-cmd-list : info, ping, monitor, auth
5151

5252
# The number of threads to write DB in slaveNode when replicating.
5353
# It's preferable to set slave's sync-thread-num value close to master's thread-pool-size.

include/pika_cmd_table_manager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class PikaCmdTableManager {
7373
*/
7474
std::unordered_map<std::string, CommandStatistics> cmdstat_map_;
7575
std::unordered_map<std::string, CommandStatistics> slow_command_count_;
76-
std::thread reset_thread_;
7776
std::mutex command_mutex_;
7877
std::shared_mutex histograms_mutex_;
7978
std::shared_mutex slow_command_mutex_;

include/pika_server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class PikaServer : public pstd::noncopyable {
259259
void ResetStat();
260260
void incr_accumulative_connections();
261261
void ResetLastSecQuerynum();
262+
void ResetCommandCount();
262263
void UpdateQueryNumAndExecCountDB(const std::string& db_name, const std::string& command, bool is_write);
263264
std::unordered_map<std::string, uint64_t> ServerExecCountDB();
264265
std::unordered_map<std::string, QpsStatistic> ServerAllDBStat();

src/pika_cmd_table_manager.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@
1515
extern std::unique_ptr<PikaConf> g_pika_conf;
1616

1717
void PikaCmdTableManager::ResetCommandCount() {
18-
while (true) {
19-
std::this_thread::sleep_for(std::chrono::minutes(1));
20-
{
21-
std::lock_guard<std::mutex> lock(command_mutex_);
22-
slow_command_count_.clear();
23-
InitHistograms();
24-
}
25-
}
18+
std::lock_guard<std::mutex> lock(command_mutex_);
19+
slow_command_count_.clear();
20+
InitHistograms();
2621
}
2722

2823
void PikaCmdTableManager::InitHistograms() {
@@ -38,7 +33,6 @@ PikaCmdTableManager::PikaCmdTableManager() {
3833
cmds_ = std::make_unique<CmdTable>();
3934
cmds_->reserve(300);
4035
InitHistograms();
41-
reset_thread_ = std::thread(&PikaCmdTableManager::ResetCommandCount, this);
4236
}
4337

4438
void PikaCmdTableManager::InitCmdTable(void) {

src/pika_server.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,16 @@ void PikaServer::ResetLastSecQuerynum() {
10331033
statistic_.ResetDBLastSecQuerynum();
10341034
}
10351035

1036+
void PikaServer::ResetCommandCount() {
1037+
thread_local uint64_t last_reset_time = 0;
1038+
auto current_time = pstd::NowMicros();
1039+
if (current_time - last_reset_time < 60 * 1000 * 1000) {
1040+
return;
1041+
}
1042+
last_reset_time = current_time;
1043+
g_pika_cmd_table_manager->ResetCommandCount();
1044+
}
1045+
10361046
void PikaServer::UpdateQueryNumAndExecCountDB(const std::string& db_name, const std::string& command, bool is_write) {
10371047
std::string cmd(command);
10381048
statistic_.server_stat.qps.querynum++;
@@ -1139,6 +1149,8 @@ void PikaServer::DoTimingTask() {
11391149
ResetLastSecQuerynum();
11401150
// Auto update network instantaneous metric
11411151
AutoUpdateNetworkMetric();
1152+
// Reset command statistics
1153+
ResetCommandCount();
11421154
ProcessCronTask();
11431155
UpdateCacheInfo();
11441156
// Print the queue status periodically

0 commit comments

Comments
 (0)