-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add session pool example. * Fix typo. * Fix compile. * Expose session pool symbols.
- Loading branch information
1 parent
26979b8
commit dad0939
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2022 vesoft inc. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
#include <common/Init.h> | ||
#include <nebula/client/SessionPool.h> | ||
|
||
#include <atomic> | ||
#include <chrono> | ||
#include <thread> | ||
#include "nebula/client/Config.h" | ||
|
||
int main(int argc, char* argv[]) { | ||
nebula::init(&argc, &argv); | ||
{ | ||
// Create space | ||
nebula::ConnectionPool pool; | ||
auto config = nebula::Config{}; | ||
config.maxConnectionPoolSize_ = 1; | ||
pool.init({"127.0.0.1:9669"}, config); | ||
auto session = pool.getSession("root", "nebula"); | ||
assert(session.valid()); | ||
|
||
auto resp = session.execute( | ||
"CREATE SPACE IF NOT EXISTS session_pool_test(vid_type = FIXED_STRING(16));"); | ||
assert(resp.errorCode == nebula::ErrorCode::SUCCEEDED); | ||
} | ||
|
||
nebula::SessionPoolConfig config; | ||
config.username_ = "root"; | ||
config.password_ = "nebula"; | ||
config.addrs_ = {"127.0.0.1:9669"}; | ||
config.spaceName_ = "session_pool_test"; | ||
config.maxSize_ = 10; | ||
nebula::SessionPool pool(config); | ||
pool.init(); | ||
|
||
std::vector<std::thread> threads; | ||
for (std::size_t i = 0; i < config.maxSize_; ++i) { | ||
threads.emplace_back([&pool]() { | ||
auto resp = pool.execute("YIELD 1"); | ||
assert(resp.errorCode == nebula::ErrorCode::SUCCEEDED); | ||
std::cout << "Result: " << *resp.data << std::endl; | ||
}); | ||
} | ||
for (auto& t : threads) { | ||
t.join(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters