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

bugfix: Global MetaGrpcClient cause dispatch drop error #4361

Merged
merged 10 commits into from Mar 11, 2022

Conversation

ariesdevil
Copy link
Member

@ariesdevil ariesdevil commented Mar 8, 2022

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

Bugfix: Global MetaGrpcClient cause dispatch drop error.

  • move MetaGrpcClient from SessionManager to Session to avoid cross-runtime client clone.

NOTE
The current implementation leaves two issues

  1. the Drop trait that impl by SessionRef using block_on to call async fn.
  2. As of current existing query processing logic of HTTP handler is different from others(MySQL, ClickHouse), so the SessionManager still has a Client that provides HTTP handler to use.

Changelog

  • Bug Fix

Related Issues

Fixes #4347

Test Plan

Unit Tests

Stateless Tests

@vercel
Copy link

vercel bot commented Mar 8, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/databend/databend/7c3JkV9riAtfm8dyWkEgJjSYZiWq
✅ Preview: Canceled

[Deployment for 157ff97 canceled]

@mergify
Copy link
Contributor

mergify bot commented Mar 8, 2022

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@youngsofun
Copy link
Member

youngsofun commented Mar 9, 2022

GLOBAL_META_EMBEDDED not inited
MetaEmbedded::new_temp() called mutli times.

https://github.com/youngsofun/databend/commits/zyj_dev

test passed after it is inited

@youngsofun
Copy link
Member

youngsofun commented Mar 9, 2022

@ariesdevil

block_on inside async block may lead to dead lock, is this the case here?

seanmonstar/reqwest#1215 (comment)

cc @zhang2014 is this the reason for https://github.com/datafuselabs/databend/pull/4317/files? authenticate() is called in an async fn init()

@ariesdevil
Copy link
Member Author

ariesdevil commented Mar 9, 2022

GLOBAL_META_EMBEDDED not inited MetaEmbedded::new_temp() called mutli times.

youngsofun/databend@zyj_dev (commits)

test passed after it is inited

Previously We using session_mgr to create KVApi that only one tmp meta_store will created.

Now we change to create KVApi by session, so each session will create it's own tmp meta_store
and this will cause first query insert first tmp meta_store and second query read it's own store
then cannot fetch the previous result.

When using global init here it can be passed if we just run this test only, but if we run with make test, it will failed with following error msg:

thread 'servers::http::http_query_handlers::test_auth_basic' panicked at 'sled db is already initialized with temp dir: /tmp/.tmpOyUpf9, can not re-init with path __global_meta',

@youngsofun
Copy link
Member

try to run globalinit only once in tests?

including

1.utils like once staic
1.check and call in sessionmgr builder for all tests
1.hack global init itself,afterall embed is mainly for test?

@ariesdevil
Copy link
Member Author

try to run globalinit only once in tests?

including

1.utils like once staic 1.check and call in sessionmgr builder for all tests 1.hack global init itself,afterall embed is mainly for test?

We should avoid using global init in unit tests, global init is just used when query node init and no meta node is configured in the config file. Let's find a way solve it.

@@ -201,7 +201,8 @@ impl SessionManager {
&self.conf.query.cluster_id,
);

self.active_sessions.write().remove(session_id);
let mut sessions = futures::executor::block_on(self.active_sessions.write());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is eventually called by drop function that impl Drop trait, async drop still in rust roadmap...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make active_sessions an std::sync::Mutex?
Then the await can be get rid of.

But using a sync-mode mutex introduces some retry-loops when inserting items into it.
Because it can not be held across an await.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess std::sync::Mutex is ok in this case, but we should be careful NOT to introduce any async/await point inside the mutex guard.

  1. sync mutex lock
  2. await yield out to another coroutine
  3. another coroutine tries to acquire the lock, and dead lock

however, it's a good practise to not do any blocking operations (includes logging) inside a mutex guard

@youngsofun
Copy link
Member

@ariesdevil

We should avoid using global init in unit tests,

got it.

so we need:

  1. diff test case use diff MetaEmbedded.
  2. multi session in a test case should use the same one. todo.

@youngsofun
Copy link
Member

@ariesdevil wrt http handler, I prefer to retain global auth_mgr/user_mgr. when not related to diff runtimes, it is safe and efficient to have a global conn pool, we can add some comment avoid miss using it.


multi session in a test case should use the same MetaEmbedded

I think of 2 ways

  1. keep an the instance in session_manager, need refactor
  2. a global dict to hold MetaEmbedded instance (bad), assign a uniq id to some field of config when build session_manager, get_or_create(uniq id) instead of new_temp(),

Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me.
But I'm not familiar with the underlying logic around session.
So let experts approve.

@BohuTANG BohuTANG merged commit ccb7f4c into datafuselabs:main Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-review pr-bugfix this PR patches a bug in codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Global MetaGrpcClient cause dispatch drop error
8 participants