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

Optimize the code of meta session manager and remove the session lock #5762

Merged
merged 7 commits into from
Dec 11, 2023

Conversation

flymysql
Copy link
Contributor

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number:

#5760

Description:

https://discuss.nebula-graph.com.cn/t/topic/14340/6

The session management operation in the meta service will increase the delay in the highly concurrent session write request scenario due to the existence of locks.

How do you solve it?

Now rewrite the code using the atomic operations of rocksdb

Special notes for your reviewer, ex. impact of this fix, design document, etc:

Checklist:

Tests:

  • Unit test(positive and negative cases)
  • Function test
  • Performance test
  • N/A

Affects:

  • Documentation affected (Please add the label if documentation needs to be modified.)
  • Incompatibility (If it breaks the compatibility, please describe it and add the label.)
  • If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
  • Performance impacted: Consumes more CPU/Memory

Release notes:

Please confirm whether to be reflected in release notes and how to describe:

ex. Fixed the bug .....

https://discuss.nebula-graph.com.cn/t/topic/14340/6

vesoft-inc#5760

The session management operation in the meta service will increase the delay in the highly concurrent session write request scenario due to the existence of locks.


Now rewrite the code using the atomic operations of rocksdb
@wey-gu
Copy link
Contributor

wey-gu commented Nov 16, 2023

Thanks @flymysql !

Kindly take a look at this change @critical27 @SuperYoko ?

critical27
critical27 previously approved these changes Nov 24, 2023
Copy link
Contributor

@critical27 critical27 left a comment

Choose a reason for hiding this comment

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

Good job, thx~~

SuperYoko
SuperYoko previously approved these changes Nov 24, 2023
@critical27 critical27 added ready-for-testing PR: ready for the CI test ready for review labels Dec 4, 2023
@flymysql flymysql dismissed stale reviews from SuperYoko and critical27 via e9d7ab8 December 6, 2023 12:24
critical27
critical27 previously approved these changes Dec 8, 2023
@wey-gu
Copy link
Contributor

wey-gu commented Dec 8, 2023

Kindly check build errors :-D

FAILED: src/meta/CMakeFiles/meta_service_handler.dir/processors/session/SessionManagerProcessor.cpp.o 
/usr/local/bin/ccache /opt/vesoft/toolset/gcc/9.3.0/bin/g++  -DENABLE_JEMALLOC -DENABLE_MEMORY_TRACKER -DNEBULA_HOME=/__w/nebula/nebula -DS2_USE_GFLAGS -DS2_USE_GLOG -D_FORTIFY_SOURCE=2 -D__STDC_FORMAT_MACROS -I../src -Isrc -isystem /opt/vesoft/third-party/3.3/include -O3 -DNDEBUG   -Wall -Wextra -Wpedantic -Wunused-parameter -Wshadow -Wnon-virtual-dtor -Woverloaded-virtual -Wignored-qualifiers -Werror -Wno-attributes -fno-strict-aliasing -fomit-frame-pointer -std=c++17 -MD -MT src/meta/CMakeFiles/meta_service_handler.dir/processors/session/SessionManagerProcessor.cpp.o -MF src/meta/CMakeFiles/meta_service_handler.dir/processors/session/SessionManagerProcessor.cpp.o.d -o src/meta/CMakeFiles/meta_service_handler.dir/processors/session/SessionManagerProcessor.cpp.o -c ../src/meta/processors/session/SessionManagerProcessor.cpp
../src/meta/processors/session/SessionManagerProcessor.cpp:11:6: error: 'CreateSessionprocessor' has not been declared
   11 | void CreateSessionprocessor::process(const cpp2::CreateSessionReq &req) {
      |      ^~~~~~~~~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::CreateSessionReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:21:3: error: 'resp_' was not declared in this scope
   21 |   resp_.session_ref() = session;
      |   ^~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:24:23: error: invalid use of 'this' in non-member function
   24 |   auto getAtomicOp = [this, session = std::move(session), user = std::move(user)]() mutable {
      |                       ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In lambda function:
../src/meta/processors/session/SessionManagerProcessor.cpp:28:16: error: 'userExist' was not declared in this scope
   28 |     auto ret = userExist(user);
      |                ^~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::CreateSessionReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:44:14: error: invalid use of 'this' in non-member function
   44 |   auto cb = [this](nebula::cpp2::ErrorCode ec) {
      |              ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In lambda function:
../src/meta/processors/session/SessionManagerProcessor.cpp:49:5: error: 'handleErrorCode' was not declared in this scope
   49 |     handleErrorCode(ec);
      |     ^~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:50:5: error: 'onFinished' was not declared in this scope
   50 |     onFinished();
      |     ^~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::CreateSessionReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:53:3: error: 'kvstore_' was not declared in this scope; did you mean 'kvstore'?
   53 |   kvstore_->asyncAtomicOp(kDefaultSpaceId, kDefaultPartId, std::move(getAtomicOp), std::move(cb));
      |   ^~~~~~~~
      |   kvstore
../src/meta/processors/session/SessionManagerProcessor.cpp: At global scope:
../src/meta/processors/session/SessionManagerProcessor.cpp:56:6: error: 'UpdateSessionsprocessor' has not been declared
   56 | void UpdateSessionsprocessor::process(const cpp2::UpdateSessionsReq &req) {
      |      ^~~~~~~~~~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::UpdateSessionsReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:58:23: error: invalid use of 'this' in non-member function
   58 |   auto getAtomicOp = [this, req]() mutable {
      |                       ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In lambda function:
../src/meta/processors/session/SessionManagerProcessor.cpp:70:18: error: 'doGet' was not declared in this scope
   70 |       auto ret = doGet(sessionKey);
      |                  ^~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:113:5: error: 'resp_' was not declared in this scope
  113 |     resp_.killed_queries_ref() = std::move(killedQueries);
      |     ^~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::UpdateSessionsReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:121:14: error: invalid use of 'this' in non-member function
  121 |   auto cb = [this](nebula::cpp2::ErrorCode ec) {
      |              ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In lambda function:
../src/meta/processors/session/SessionManagerProcessor.cpp:126:5: error: 'handleErrorCode' was not declared in this scope
  126 |     handleErrorCode(ec);
      |     ^~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:127:5: error: 'onFinished' was not declared in this scope
  127 |     onFinished();
      |     ^~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::UpdateSessionsReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:130:3: error: 'kvstore_' was not declared in this scope; did you mean 'kvstore'?
  130 |   kvstore_->asyncAtomicOp(kDefaultSpaceId, kDefaultPartId, std::move(getAtomicOp), std::move(cb));
      |   ^~~~~~~~
      |   kvstore
../src/meta/processors/session/SessionManagerProcessor.cpp: At global scope:
../src/meta/processors/session/SessionManagerProcessor.cpp:177:6: error: 'RemoveSessionprocessor' has not been declared
  177 | void RemoveSessionprocessor::process(const cpp2::RemoveSessionReq &req) {
      |      ^~~~~~~~~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::RemoveSessionReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:183:25: error: invalid use of 'this' in non-member function
  183 |     auto getAtomicOp = [this, sessionId] {
      |                         ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In lambda function:
../src/meta/processors/session/SessionManagerProcessor.cpp:188:18: error: 'doGet' was not declared in this scope
  188 |       auto ret = doGet(sessionKey);
      |                  ^~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::RemoveSessionReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:203:5: error: 'kvstore_' was not declared in this scope; did you mean 'kvstore'?
  203 |     kvstore_->asyncAtomicOp(kDefaultSpaceId,
      |     ^~~~~~~~
      |     kvstore
../src/meta/processors/session/SessionManagerProcessor.cpp:206:30: error: invalid use of 'this' in non-member function
  206 |                             [this, &baton, &errorCode](nebula::cpp2::ErrorCode code) {
      |                              ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In lambda function:
../src/meta/processors/session/SessionManagerProcessor.cpp:207:31: error: 'this' was not captured for this lambda function
  207 |                               this->handleErrorCode(code);
      |                               ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::RemoveSessionReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:220:9: error: 'handleErrorCode' was not declared in this scope
  220 |         handleErrorCode(errorCode);
      |         ^~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:221:9: error: 'onFinished' was not declared in this scope
  221 |         onFinished();
      |         ^~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:230:3: error: 'handleErrorCode' was not declared in this scope
  230 |   handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED);
      |   ^~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:231:3: error: 'resp_' was not declared in this scope
  231 |   resp_.removed_session_ids_ref() = std::move(killedSessions);
      |   ^~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:232:3: error: 'onFinished' was not declared in this scope
  232 |   onFinished();
      |   ^~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: At global scope:
../src/meta/processors/session/SessionManagerProcessor.cpp:235:6: error: 'KillQueryprocessor' has not been declared
  235 | void KillQueryprocessor::process(const cpp2::KillQueryReq &req) {
      |      ^~~~~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::KillQueryReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:237:23: error: invalid use of 'this' in non-member function
  237 |   auto getAtomicOp = [this, killQueries] {
      |                       ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In lambda function:
../src/meta/processors/session/SessionManagerProcessor.cpp:244:18: error: 'doGet' was not declared in this scope
  244 |       auto ret = doGet(sessionKey);
      |                  ^~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::KillQueryReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:273:14: error: invalid use of 'this' in non-member function
  273 |   auto cb = [this](nebula::cpp2::ErrorCode ec) {
      |              ^~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In lambda function:
../src/meta/processors/session/SessionManagerProcessor.cpp:278:5: error: 'handleErrorCode' was not declared in this scope
  278 |     handleErrorCode(ec);
      |     ^~~~~~~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp:279:5: error: 'onFinished' was not declared in this scope
  279 |     onFinished();
      |     ^~~~~~~~~~
../src/meta/processors/session/SessionManagerProcessor.cpp: In function 'void nebula::meta::process(const nebula::meta::cpp2::KillQueryReq&)':
../src/meta/processors/session/SessionManagerProcessor.cpp:282:3: error: 'kvstore_' was not declared in this scope; did you mean 'kvstore'?
  282 |   kvstore_->asyncAtomicOp(kDefaultSpaceId, kDefaultPartId, std::move(getAtomicOp), std::move(cb));
      |   ^~~~~~~~
      |   kvstore

@critical27 critical27 merged commit 82565cd into vesoft-inc:master Dec 11, 2023
@wey-gu
Copy link
Contributor

wey-gu commented Dec 11, 2023

Thanks a lot again @flymysql ~~🎉!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants