Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle slow search in pika #2040

Closed
AlexStocks opened this issue Sep 26, 2023 · 0 comments
Closed

handle slow search in pika #2040

AlexStocks opened this issue Sep 26, 2023 · 0 comments

Comments

@AlexStocks
Copy link
Collaborator

目的: 目标是出现慢查询的key执行compactRange
方式: 增加keyCompact的任务

1、先在blackwidow.h增加命令和类型的对应关系。
vim include/blackwidow/blackwidow.h

void DealSlowKey(std::vectorstd::string argv); //声明
std::map<std::string, DataType> mapCommand = { //命令和类型的对应关系,比如ZADD 对应zset类型
{"HGETALL", DataType::kHashes},
{"ZREVRANGEBYSCORE", DataType::kZSets},
{"ZREVRANGEBYSCORE", DataType::kZSets},
{"ZREVRANGE", DataType::kZSets},
{"ZINCRBY", DataType::kZSets},
{"ZREM", DataType::kZSets},
{"ZREMRANGEBYRANK", DataType::kZSets},
{"ZADD", DataType::kZSets},
{"LPUSH", DataType::kLists},
{"RPUSH", DataType::kLists},
{"LRANGE", DataType::kLists},
{"LTRIM", DataType::kLists},
{"HMGET", DataType::kHashes},
{"HMSET", DataType::kHashes},
{"HGET", DataType::kHashes},
{"HSET", DataType::kHashes},
{"HDEL", DataType::kHashes},
{"HINCRBY", DataType::kHashes},
{"SMEMBERS", DataType::kSets},
{"SADD", DataType::kSets}
};

2、blackwidow.cc增加DealSlowKey函数把keyCompact加到后台任务队列中。

vim src/blackwidow.cc

void BlackWidow::DealSlowKey(std::vectorstd::string argv){
if (bg_tasks_queue_.size() > 0){
return;
}
std::map<std::string, blackwidow::DataType>::iterator iter;
std::string cmd = argv[0]; //命令
std::transform(cmd.begin(), cmd.end(),cmd.begin(), ::toupper); //转大写
iter = mapCommand.find(cmd);
if(iter != mapCommand.end()){
LOG(WARNING) << "begin to deal slowlog : " << argv[0] << " " << argv[1];
AddBGTask({iter->second,Operation::kCompactKey,argv[1]}); //加到后台任务队列里
}
}

4、在命令的入口函数PikaClientConn::DoCmd、和binlog的执行入口函数 增加调用命令

vim src/pika_client_conn.cc
PikaClientConn::DoCmd
在这个位置

229 if (argv.size() > 1 && argv.size() < 10){
230 g_pika_server->db()->DealSlowKey(argv);
231 }

vim src/pika_binlog_bgworker.cc

109 if (argv.size() > 1 && argv.size() < 10){
110 g_pika_server->db()->DealSlowKey(argv);
111 }

后面调用DealSlowKey在这个位置

image

具体可以参考下我们这边版本代码的拷贝
https://github.com/guangkun123/pika-3-0-16/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant