Skip to content

Commit

Permalink
Merge pull request ClickHouse#65332 from ClickHouse/minimal-changes
Browse files Browse the repository at this point in the history
Fix bad code in `system.session_log`
  • Loading branch information
alexey-milovidov authored Jun 18, 2024
2 parents 03f7ac2 + fff6860 commit 3ada99c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
32 changes: 10 additions & 22 deletions src/Access/SettingsProfilesInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,8 @@ namespace ErrorCodes

bool operator==(const SettingsProfilesInfo & lhs, const SettingsProfilesInfo & rhs)
{
if (lhs.settings != rhs.settings)
return false;

if (lhs.constraints != rhs.constraints)
return false;

if (lhs.profiles != rhs.profiles)
return false;

if (lhs.profiles_with_implicit != rhs.profiles_with_implicit)
return false;

if (lhs.names_of_profiles != rhs.names_of_profiles)
return false;

return true;
return std::tie(lhs.settings, lhs.constraints, lhs.profiles, lhs.profiles_with_implicit, lhs.names_of_profiles)
== std::tie(rhs.settings, rhs.constraints, rhs.profiles, rhs.profiles_with_implicit, rhs.names_of_profiles);
}

std::shared_ptr<const SettingsConstraintsAndProfileIDs>
Expand Down Expand Up @@ -66,18 +52,20 @@ Strings SettingsProfilesInfo::getProfileNames() const
{
Strings result;
result.reserve(profiles.size());
for (const auto & profile_id : profiles)
for (const UUID & profile_uuid : profiles)
{
const auto p = names_of_profiles.find(profile_id);
if (p != names_of_profiles.end())
result.push_back(p->second);
const auto names_it = names_of_profiles.find(profile_uuid);
if (names_it != names_of_profiles.end())
{
result.push_back(names_it->second);
}
else
{
if (const auto name = access_control.tryReadName(profile_id))
if (const auto name = access_control.tryReadName(profile_uuid))
// We could've updated cache here, but it is a very rare case, so don't bother.
result.push_back(*name);
else
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unable to get profile name for {}", toString(profile_id));
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unable to get profile name for {}", toString(profile_uuid));
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/Access/SettingsProfilesInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ struct SettingsProfilesInfo
/// Names of all the profiles in `profiles`.
std::unordered_map<UUID, String> names_of_profiles;

explicit SettingsProfilesInfo(const AccessControl & access_control_) : constraints(access_control_), access_control(access_control_) {}
explicit SettingsProfilesInfo(const AccessControl & access_control_)
: constraints(access_control_), access_control(access_control_)
{
}

std::shared_ptr<const SettingsConstraintsAndProfileIDs> getConstraintsAndProfileIDs(
const std::shared_ptr<const SettingsConstraintsAndProfileIDs> & previous = nullptr) const;

Expand Down
8 changes: 4 additions & 4 deletions src/Interpreters/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ ContextMutablePtr Session::makeSessionContext()
session_context->checkSettingsConstraints(settings_from_auth_server, SettingSource::QUERY);
session_context->applySettingsChanges(settings_from_auth_server);

recordLoginSucess(session_context);
recordLoginSuccess(session_context);

return session_context;
}
Expand Down Expand Up @@ -596,7 +596,7 @@ ContextMutablePtr Session::makeSessionContext(const String & session_name_, std:
{ session_name_ },
max_sessions_for_user);

recordLoginSucess(session_context);
recordLoginSuccess(session_context);

return session_context;
}
Expand Down Expand Up @@ -672,13 +672,13 @@ ContextMutablePtr Session::makeQueryContextImpl(const ClientInfo * client_info_t
user = query_context->getUser();

/// Interserver does not create session context
recordLoginSucess(query_context);
recordLoginSuccess(query_context);

return query_context;
}


void Session::recordLoginSucess(ContextPtr login_context) const
void Session::recordLoginSuccess(ContextPtr login_context) const
{
if (notified_session_log_about_login)
return;
Expand Down
3 changes: 1 addition & 2 deletions src/Interpreters/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class Session
private:
std::shared_ptr<SessionLog> getSessionLog() const;
ContextMutablePtr makeQueryContextImpl(const ClientInfo * client_info_to_copy, ClientInfo * client_info_to_move) const;
void recordLoginSucess(ContextPtr login_context) const;

void recordLoginSuccess(ContextPtr login_context) const;

mutable bool notified_session_log_about_login = false;
const UUID auth_id;
Expand Down
2 changes: 1 addition & 1 deletion src/Interpreters/SessionLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void SessionLog::addLoginSuccess(const UUID & auth_id,
const ClientInfo & client_info,
const UserPtr & login_user)
{
DB::SessionLogElement log_entry(auth_id, SESSION_LOGIN_SUCCESS);
SessionLogElement log_entry(auth_id, SESSION_LOGIN_SUCCESS);
log_entry.client_info = client_info;

if (login_user)
Expand Down

0 comments on commit 3ada99c

Please sign in to comment.