Skip to content

Commit

Permalink
update userinfo every 10s (baidu#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgqss authored Apr 15, 2024
1 parent 0394fbd commit 2e210e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/session/network_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ struct NetworkSocket {
std::string charset_name; // Client charset name.

std::string username;
TimeCost last_update_user; // update userinfo every 10s
std::shared_ptr<UserInfo> user_info; // userinfo for current connection
std::shared_ptr<QueryContext> query_ctx; // Current query.
SmartBinlogContext binlog_ctx; // for binlog
Expand Down
9 changes: 9 additions & 0 deletions src/protocol/state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ int StateMachine::_auth_read(SmartSocket sock) {
//需要修改成权限类
SchemaFactory* factory = SchemaFactory::get_instance();
sock->user_info = factory->get_user_info(username);
sock->last_update_user.reset();

if (sock->user_info == nullptr) {
sock->user_info.reset(new UserInfo);
Expand Down Expand Up @@ -1001,6 +1002,14 @@ int StateMachine::_query_read_stmt_execute(SmartSocket sock) {
}

bool StateMachine::_query_process(SmartSocket client) {
if (client->last_update_user.get_time() > 10 * 1000 * 1000LL) {
SchemaFactory* factory = SchemaFactory::get_instance();
auto user_info = factory->get_user_info(client->username);
if (user_info != nullptr && user_info->version > client->user_info->version) {
client->user_info = user_info;
}
client->last_update_user.reset();
}
TimeCost cost;
//gettimeofday(&(client->query_ctx->stat_info.start_stamp), NULL);

Expand Down

0 comments on commit 2e210e5

Please sign in to comment.