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

update userinfo every 10s #235

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading