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

moving role_cache_manager to session manager #5605

Merged
merged 1 commit into from
May 26, 2022
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
4 changes: 1 addition & 3 deletions query/src/sessions/query_ctx_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub struct QueryContextShared {
pub(in crate::sessions) dal_ctx: Arc<DalContext>,
pub(in crate::sessions) user_manager: Arc<UserApiProvider>,
pub(in crate::sessions) auth_manager: Arc<AuthMgr>,
pub(in crate::sessions) role_cache_manager: Arc<RoleCacheMgr>,
}

impl QueryContextShared {
Expand Down Expand Up @@ -107,7 +106,6 @@ impl QueryContextShared {
dal_ctx: Arc::new(Default::default()),
user_manager: user_manager.clone(),
auth_manager: Arc::new(AuthMgr::create(conf, user_manager.clone()).await?),
role_cache_manager: Arc::new(RoleCacheMgr::new(user_manager)),
}))
}

Expand Down Expand Up @@ -172,7 +170,7 @@ impl QueryContextShared {
}

pub fn get_role_cache_manager(&self) -> Arc<RoleCacheMgr> {
self.role_cache_manager.clone()
self.session.get_role_cache_manager()
}

pub fn get_settings(&self) -> Arc<Settings> {
Expand Down
5 changes: 5 additions & 0 deletions query/src/sessions/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use crate::sessions::SessionManager;
use crate::sessions::SessionStatus;
use crate::sessions::SessionType;
use crate::sessions::Settings;
use crate::users::RoleCacheMgr;
use crate::Config;

#[derive(MallocSizeOf)]
Expand Down Expand Up @@ -255,4 +256,8 @@ impl Session {
pub fn get_status(self: &Arc<Self>) -> Arc<RwLock<SessionStatus>> {
self.status.clone()
}

pub fn get_role_cache_manager(self: &Arc<Self>) -> Arc<RoleCacheMgr> {
self.session_mgr.get_role_cache_manager()
}
}
18 changes: 15 additions & 3 deletions query/src/sessions/session_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use crate::sessions::ProcessInfo;
use crate::sessions::SessionManagerStatus;
use crate::sessions::SessionType;
use crate::storages::cache::CacheManager;
use crate::users::RoleCacheMgr;
use crate::users::UserApiProvider;
use crate::Config;

Expand All @@ -65,6 +66,7 @@ pub struct SessionManager {
_guards: Vec<WorkerGuard>,

user_api_provider: RwLock<Arc<UserApiProvider>>,
role_cache_manager: RwLock<Arc<RoleCacheMgr>>,
// When typ is MySQL, insert into this map, key is id, val is MySQL connection id.
pub(crate) mysql_conn_map: Arc<RwLock<HashMap<Option<u32>, String>>>,
pub(in crate::sessions) mysql_basic_conn_id: AtomicU32,
Expand Down Expand Up @@ -105,9 +107,11 @@ impl SessionManager {
(Vec::new(), None)
};
let mysql_conn_map = Arc::new(RwLock::new(HashMap::with_capacity(max_sessions)));
let user_api_provider = UserApiProvider::create_global(conf.clone()).await?;
let role_cache_manager = Arc::new(RoleCacheMgr::new(user_api_provider.clone()));

Ok(Arc::new(SessionManager {
conf: RwLock::new(conf.clone()),
conf: RwLock::new(conf),
catalogs: RwLock::new(catalogs),
discovery: RwLock::new(discovery),
http_query_manager,
Expand All @@ -119,7 +123,8 @@ impl SessionManager {
storage_operator: RwLock::new(storage_operator),
storage_runtime: Arc::new(storage_runtime),
_guards,
user_api_provider: RwLock::new(UserApiProvider::create_global(conf).await?),
user_api_provider: RwLock::new(user_api_provider),
role_cache_manager: RwLock::new(role_cache_manager),
mysql_conn_map,
mysql_basic_conn_id: AtomicU32::new(9_u32.to_le() as u32),
}))
Expand Down Expand Up @@ -157,6 +162,10 @@ impl SessionManager {
self.user_api_provider.read().clone()
}

pub fn get_role_cache_manager(&self) -> Arc<RoleCacheMgr> {
self.role_cache_manager.read().clone()
}

pub async fn create_session(self: &Arc<Self>, typ: SessionType) -> Result<SessionRef> {
// TODO: maybe deadlock
let config = self.get_conf();
Expand Down Expand Up @@ -394,7 +403,10 @@ impl SessionManager {

{
let x = UserApiProvider::create_global(config).await?;
*self.user_api_provider.write() = x;
*self.user_api_provider.write() = x.clone();

let role_cache_manager = RoleCacheMgr::new(x);
*self.role_cache_manager.write() = Arc::new(role_cache_manager);
}

Ok(())
Expand Down