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

feat: support tablet auth and flag to disable auth #3885

Merged
merged 83 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
f7fc985
add brpc authenticator
oh2024 Mar 20, 2024
9950ffa
fix: add auth library
oh2024 Mar 21, 2024
c4ab632
fix: make authenticator lifetime same as channel
oh2024 Mar 21, 2024
d402fd3
refactor: use global variables to pass auth tokens
oh2024 Mar 22, 2024
3769917
feat: added basic server auth backwards compatible with user = root a…
oh2024 Mar 26, 2024
7f19ade
chore: remove debug log
oh2024 Mar 26, 2024
5569b90
chore: apply lint style fixes
oh2024 Mar 26, 2024
466a5c4
feat: encrypt password before sending
oh2024 Mar 26, 2024
269220e
fix: add namespace for Authenticator class
oh2024 Mar 26, 2024
8f2a779
chore: add newline
oh2024 Mar 26, 2024
f210a9b
feat: add user verification logic
oh2024 Mar 27, 2024
3fb9819
feat: add nameserver server side auth
zhangziheng01233 Apr 2, 2024
cb76d88
chore: remove unneccessary logs
zhangziheng01233 Apr 2, 2024
e21fb53
chore: lint
zhangziheng01233 Apr 2, 2024
d368ab0
chore: make refreshable map header only
zhangziheng01233 Apr 2, 2024
bdf8af6
chore: remove old refreshable map file
zhangziheng01233 Apr 2, 2024
b84d32b
chore: lint
zhangziheng01233 Apr 2, 2024
faf6f08
chore: lint
zhangziheng01233 Apr 2, 2024
816409f
chore: lint
zhangziheng01233 Apr 2, 2024
e11bdb4
sync with db in user access manager constructor
zhangziheng01233 Apr 2, 2024
a4c9b30
chore: add license
oh2024 Apr 7, 2024
51dd42b
chore: add license
oh2024 Apr 7, 2024
70621a2
feat: default g_auth_token user to root if not provided
oh2024 Apr 7, 2024
64ed7bd
fix: user table start in cluster mode
oh2024 Apr 7, 2024
c98b20b
feat: sync user data every 100ms
oh2024 Apr 7, 2024
93d38d1
fix: add auth library for linking
oh2024 Apr 7, 2024
ad01ac9
fix: refreshable map test
oh2024 Apr 7, 2024
197450c
Merge remote-tracking branch 'upstream/main' into feat/server-auth
oh2024 Apr 7, 2024
007c237
fix: add main method to refreshable map test
oh2024 Apr 8, 2024
fb75477
fix: add auth to sdk
oh2024 Apr 8, 2024
bb2a332
eaat: treat omitted host as localhost
oh2024 Apr 8, 2024
ae7dc86
feat: treat % as all hosts
oh2024 Apr 8, 2024
0d2c030
fix: minicluster auth
oh2024 Apr 9, 2024
bc17c64
fix: remove api server auth
oh2024 Apr 9, 2024
fb69095
Merge remote-tracking branch 'upstream/main' into feat/server-auth
oh2024 Apr 10, 2024
e912794
feat: add minicluster tablet auth
oh2024 Apr 10, 2024
e61751f
fix: change scala test password
oh2024 Apr 10, 2024
fe88685
fix: default root as user in python sdk
oh2024 Apr 10, 2024
44aec00
fix: wait for nameservers to pick up auth data before starting api se…
oh2024 Apr 10, 2024
1b00199
fix: wait 5 seconds after nameserver launch for auth data to be picke…
oh2024 Apr 10, 2024
6af6756
fix: minicluster options scope
oh2024 Apr 10, 2024
d926903
test: cat host file
oh2024 Apr 10, 2024
3de4089
fix: remove cat
oh2024 Apr 11, 2024
335b55e
fix: Init should finish after user table is available
oh2024 Apr 11, 2024
36f362c
fix: always create user table
oh2024 Apr 11, 2024
a6aab82
fix: create user table after internal db create
oh2024 Apr 11, 2024
47c1e53
fix: add partition info setting for user table create
oh2024 Apr 12, 2024
e5abb0c
Merge remote-tracking branch 'upstream/main' into feat/server-auth
oh2024 Apr 15, 2024
2270869
fix: auth related tests
oh2024 Apr 15, 2024
78e2c3f
fix: support multiple nameservers
oh2024 Apr 16, 2024
35b1167
fix: recover db and table only for cluster mode
oh2024 Apr 16, 2024
806051f
fix: remote test ns tablet start order
oh2024 Apr 16, 2024
1e07e5d
fix: set root as default user in python sdk
oh2024 Apr 16, 2024
cb17484
fix: SyncTableReplicaCluster and AddAndRemoveReplicaCluster tests
oh2024 Apr 17, 2024
93317c8
fix: remove user root
oh2024 Apr 17, 2024
0a817a5
Merge remote-tracking branch 'upstream/main' into feat/server-auth
oh2024 Apr 17, 2024
790094e
fix: add erver stops to name_server_test cases and spilt sql availabi…
oh2024 Apr 17, 2024
9307f12
fix: nameserver test scope
oh2024 Apr 17, 2024
d434ed2
chore: merge with server auth branch
oh2024 Apr 17, 2024
28810cc
test: add bad tablet server option
oh2024 Apr 17, 2024
c3cb35a
fix: brpc authenticator destruction before nameserver
oh2024 Apr 17, 2024
951afbf
Merge remote-tracking branch 'upstream/main' into feat/server-auth
oh2024 Apr 18, 2024
836fd1e
Merge remote-tracking branch 'origin/feat/server-auth' into feat/tabl…
oh2024 Apr 18, 2024
a90b463
feat: add user auth_str to tablet client
oh2024 Apr 18, 2024
5f79ed9
Merge remote-tracking branch 'upstream/main' into feat/server-auth
oh2024 Apr 18, 2024
c31a208
Merge branch 'feat/server-auth' into feat/tablet-authn
oh2024 Apr 18, 2024
4d41224
feat: add tablet system table iterator
oh2024 Apr 18, 2024
bc48503
fix: refactor to better system table iterator
oh2024 Apr 18, 2024
5969cf7
fix: sqlcmdtest pass
oh2024 Apr 19, 2024
07e12bc
fix: merge with main
oh2024 Apr 22, 2024
0746ffe
fix: remove unneccessary test
oh2024 Apr 22, 2024
fac2b88
test: sql_cmd_test should expect 2 user table replicas in cluster mode
oh2024 Apr 22, 2024
f9fee5c
chore: lint
oh2024 Apr 22, 2024
7b0f091
feat: add skip auth flag
oh2024 Apr 23, 2024
24f276a
Merge remote-tracking branch 'upstream/main' into feat/tablet-authn
oh2024 Apr 23, 2024
cad2000
fix: skip while wait in nameserver start if auth disabled
oh2024 Apr 23, 2024
72e3858
test: enable auth for system table test
oh2024 Apr 23, 2024
f35afb3
fix: tablets read user from local
oh2024 Apr 23, 2024
6932cc0
fix: authenticator scope
oh2024 Apr 23, 2024
42a92bb
chore: add auth docs
oh2024 Apr 24, 2024
dece628
Merge remote-tracking branch 'upstream/main' into feat/tablet-authn
oh2024 Apr 24, 2024
fd63a04
chore: more docs
oh2024 Apr 24, 2024
6962c8e
chore: add 0.8.5 clarification
oh2024 Apr 24, 2024
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
2 changes: 2 additions & 0 deletions src/auth/refreshable_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace openmldb::auth {
template <typename Key, typename Value>
class RefreshableMap {
public:
RefreshableMap() : map_(std::make_shared<std::unordered_map<Key, Value>>()) {}

std::optional<Value> Get(const Key& key) const {
std::shared_lock<std::shared_mutex> lock(mutex_);
if (auto it = map_->find(key); it != map_->end()) {
Expand Down
44 changes: 23 additions & 21 deletions src/auth/user_access_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include "nameserver/system_table.h"

namespace openmldb::auth {
UserAccessManager::UserAccessManager(IteratorFactory iterator_factory,
std::shared_ptr<nameserver::TableInfo> user_table_info)
: user_table_iterator_factory_(std::move(iterator_factory)), user_table_info_(user_table_info) {

UserAccessManager::UserAccessManager(IteratorFactory iterator_factory)
: user_table_iterator_factory_(std::move(iterator_factory)) {
StartSyncTask();
}

Expand All @@ -49,26 +49,28 @@ void UserAccessManager::StopSyncTask() {
}

void UserAccessManager::SyncWithDB() {
auto new_user_map = std::make_unique<std::unordered_map<std::string, std::string>>();
auto it = user_table_iterator_factory_(::openmldb::nameserver::USER_INFO_NAME);
it->SeekToFirst();
while (it->Valid()) {
auto row = it->GetValue();
auto buf = it->GetValue().buf();
auto size = it->GetValue().size();
codec::RowView row_view(user_table_info_->column_desc(), buf, size);
std::string host, user, password;
row_view.GetStrValue(0, &host);
row_view.GetStrValue(1, &user);
row_view.GetStrValue(2, &password);
if (host == "%") {
new_user_map->emplace(user, password);
} else {
new_user_map->emplace(FormUserHost(user, host), password);
if (auto it_pair = user_table_iterator_factory_(::openmldb::nameserver::USER_INFO_NAME); it_pair) {
auto new_user_map = std::make_unique<std::unordered_map<std::string, std::string>>();
auto it = it_pair->first.get();
it->SeekToFirst();
while (it->Valid()) {
auto row = it->GetValue();
auto buf = it->GetValue().buf();
auto size = it->GetValue().size();
codec::RowView row_view(*it_pair->second.get(), buf, size);
std::string host, user, password;
row_view.GetStrValue(0, &host);
row_view.GetStrValue(1, &user);
row_view.GetStrValue(2, &password);
if (host == "%") {
new_user_map->emplace(user, password);
} else {
new_user_map->emplace(FormUserHost(user, host), password);
}
it->Next();
}
it->Next();
user_map_.Refresh(std::move(new_user_map));
}
user_map_.Refresh(std::move(new_user_map));
}

bool UserAccessManager::IsAuthenticated(const std::string& host, const std::string& user, const std::string& password) {
Expand Down
10 changes: 6 additions & 4 deletions src/auth/user_access_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,25 @@
#include <memory>
#include <string>
#include <thread>
#include <utility>

#include "catalog/distribute_iterator.h"
#include "refreshable_map.h"

namespace openmldb::auth {
class UserAccessManager {
public:
using IteratorFactory =
std::function<std::unique_ptr<::openmldb::catalog::FullTableIterator>(const std::string& table_name)>;
using IteratorFactory = std::function<std::optional<
std::pair<std::unique_ptr<::openmldb::catalog::FullTableIterator>, std::unique_ptr<openmldb::codec::Schema>>>(
const std::string& table_name)>;

explicit UserAccessManager(IteratorFactory iterator_factory);

UserAccessManager(IteratorFactory iterator_factory, std::shared_ptr<nameserver::TableInfo> user_table_info);
~UserAccessManager();
bool IsAuthenticated(const std::string& host, const std::string& username, const std::string& password);

private:
IteratorFactory user_table_iterator_factory_;
std::shared_ptr<nameserver::TableInfo> user_table_info_;
RefreshableMap<std::string, std::string> user_map_;
std::atomic<bool> sync_task_running_{false};
std::thread sync_task_thread_;
Expand Down
4 changes: 2 additions & 2 deletions src/catalog/client_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ bool ClientManager::UpdateClient(const std::map<std::string, std::string>& endpo
for (const auto& kv : endpoint_map) {
auto it = real_endpoint_map_.find(kv.first);
if (it == real_endpoint_map_.end()) {
auto wrapper = std::make_shared<TabletAccessor>(kv.first);
auto wrapper = std::make_shared<TabletAccessor>(kv.first, auth_token_);
if (!wrapper->UpdateClient(kv.second)) {
LOG(WARNING) << "add client failed. name " << kv.first << ", endpoint " << kv.second;
continue;
Expand Down Expand Up @@ -583,7 +583,7 @@ bool ClientManager::UpdateClient(
for (const auto& kv : tablet_clients) {
auto it = real_endpoint_map_.find(kv.first);
if (it == real_endpoint_map_.end()) {
auto wrapper = std::make_shared<TabletAccessor>(kv.first, kv.second);
auto wrapper = std::make_shared<TabletAccessor>(kv.first, kv.second, auth_token_);
DLOG(INFO) << "add client. name " << kv.first << ", endpoint " << kv.second->GetRealEndpoint();
clients_.emplace(kv.first, wrapper);
real_endpoint_map_.emplace(kv.first, kv.second->GetRealEndpoint());
Expand Down
16 changes: 11 additions & 5 deletions src/catalog/client_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,20 @@ class AsyncTablesHandler : public ::hybridse::vm::MemTableHandler {

class TabletAccessor : public ::hybridse::vm::Tablet {
public:
explicit TabletAccessor(const std::string& name) : name_(name), tablet_client_() {}
explicit TabletAccessor(const std::string& name,
const openmldb::authn::AuthToken auth_token = openmldb::authn::ServiceToken{"default"})
: name_(name), tablet_client_(), auth_token_(auth_token) {}

TabletAccessor(const std::string& name, const std::shared_ptr<::openmldb::client::TabletClient>& client)
: name_(name), tablet_client_(client) {}
TabletAccessor(const std::string& name, const std::shared_ptr<::openmldb::client::TabletClient>& client,
const openmldb::authn::AuthToken auth_token = openmldb::authn::ServiceToken{"default"})
: name_(name), tablet_client_(client), auth_token_(auth_token) {}

std::shared_ptr<::openmldb::client::TabletClient> GetClient() {
return std::atomic_load_explicit(&tablet_client_, std::memory_order_relaxed);
}

bool UpdateClient(const std::string& endpoint) {
auto client = std::make_shared<::openmldb::client::TabletClient>(name_, endpoint);
auto client = std::make_shared<::openmldb::client::TabletClient>(name_, endpoint, auth_token_);
if (client->Init() != 0) {
return false;
}
Expand Down Expand Up @@ -170,6 +173,7 @@ class TabletAccessor : public ::hybridse::vm::Tablet {
private:
std::string name_;
std::shared_ptr<::openmldb::client::TabletClient> tablet_client_;
const openmldb::authn::AuthToken auth_token_;
};

class TabletsAccessor : public ::hybridse::vm::Tablet {
Expand Down Expand Up @@ -243,7 +247,8 @@ class TableClientManager {

class ClientManager {
public:
ClientManager() : real_endpoint_map_(), clients_(), mu_(), rand_(0xdeadbeef) {}
explicit ClientManager(const openmldb::authn::AuthToken auth_token = openmldb::authn::ServiceToken{"default"})
: real_endpoint_map_(), clients_(), mu_(), rand_(0xdeadbeef), auth_token_(auth_token) {}
std::shared_ptr<TabletAccessor> GetTablet(const std::string& name) const;
std::shared_ptr<TabletAccessor> GetTablet() const;
std::vector<std::shared_ptr<TabletAccessor>> GetAllTablet() const;
Expand All @@ -257,6 +262,7 @@ class ClientManager {
std::unordered_map<std::string, std::shared_ptr<TabletAccessor>> clients_;
mutable ::openmldb::base::SpinMutex mu_;
mutable ::openmldb::base::Random rand_;
const openmldb::authn::AuthToken auth_token_;
};

} // namespace catalog
Expand Down
13 changes: 8 additions & 5 deletions src/client/tablet_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ DECLARE_uint32(absolute_ttl_max);
namespace openmldb {
namespace client {

TabletClient::TabletClient(const std::string& endpoint, const std::string& real_endpoint)
: Client(endpoint, real_endpoint), client_(real_endpoint.empty() ? endpoint : real_endpoint) {}

TabletClient::TabletClient(const std::string& endpoint, const std::string& real_endpoint, bool use_sleep_policy)
: Client(endpoint, real_endpoint), client_(real_endpoint.empty() ? endpoint : real_endpoint, use_sleep_policy) {}
TabletClient::TabletClient(const std::string& endpoint, const std::string& real_endpoint,
const openmldb::authn::AuthToken auth_token)
: Client(endpoint, real_endpoint), client_(real_endpoint.empty() ? endpoint : real_endpoint, auth_token) {}

TabletClient::TabletClient(const std::string& endpoint, const std::string& real_endpoint, bool use_sleep_policy,
const openmldb::authn::AuthToken auth_token)
: Client(endpoint, real_endpoint),
client_(real_endpoint.empty() ? endpoint : real_endpoint, use_sleep_policy, auth_token) {}

TabletClient::~TabletClient() {}

Expand Down
6 changes: 4 additions & 2 deletions src/client/tablet_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ const uint32_t INVALID_REMOTE_TID = UINT32_MAX;

class TabletClient : public Client {
public:
TabletClient(const std::string& endpoint, const std::string& real_endpoint);
TabletClient(const std::string& endpoint, const std::string& real_endpoint,
const openmldb::authn::AuthToken auth_token = openmldb::authn::ServiceToken{"default"});

TabletClient(const std::string& endpoint, const std::string& real_endpoint, bool use_sleep_policy);
TabletClient(const std::string& endpoint, const std::string& real_endpoint, bool use_sleep_policy,
const openmldb::authn::AuthToken auth_token = openmldb::authn::ServiceToken{"default"});

~TabletClient();

Expand Down
37 changes: 23 additions & 14 deletions src/cmd/openmldb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,19 @@ void StartNameServer() {
PDLOG(WARNING, "Fail to register name");
exit(1);
}
std::shared_ptr<::openmldb::nameserver::TableInfo> table_info;
if (!name_server->GetTableInfo(::openmldb::nameserver::USER_INFO_NAME, ::openmldb::nameserver::INTERNAL_DB,
&table_info)) {
PDLOG(WARNING, "Failed to get table info for user table");
exit(1);
}
openmldb::auth::UserAccessManager user_access_manager(name_server->GetSystemTableIterator(), table_info);

brpc::ServerOptions options;
openmldb::authn::BRPCAuthenticator server_authenticator(
[&user_access_manager](const std::string& host, const std::string& username, const std::string& password) {
return user_access_manager.IsAuthenticated(host, username, password);
});
options.auth = &server_authenticator;
std::unique_ptr<openmldb::auth::UserAccessManager> user_access_manager;
std::unique_ptr<openmldb::authn::BRPCAuthenticator> server_authenticator;
if (!FLAGS_skip_grant_tables) {
user_access_manager =
std::make_unique<openmldb::auth::UserAccessManager>(name_server->GetSystemTableIterator());
server_authenticator = std::make_unique<openmldb::authn::BRPCAuthenticator>(
[&user_access_manager](const std::string& host, const std::string& username, const std::string& password) {
return user_access_manager->IsAuthenticated(host, username, password);
});
options.auth = server_authenticator.get();
}

options.num_threads = FLAGS_thread_pool_size;
brpc::Server server;
Expand Down Expand Up @@ -256,8 +256,17 @@ void StartTablet() {
exit(1);
}
brpc::ServerOptions options;
openmldb::authn::BRPCAuthenticator server_authenticator;
options.auth = &server_authenticator;
std::unique_ptr<openmldb::auth::UserAccessManager> user_access_manager;
std::unique_ptr<openmldb::authn::BRPCAuthenticator> server_authenticator;

if (!FLAGS_skip_grant_tables) {
user_access_manager = std::make_unique<openmldb::auth::UserAccessManager>(tablet->GetSystemTableIterator());
server_authenticator = std::make_unique<openmldb::authn::BRPCAuthenticator>(
[&user_access_manager](const std::string& host, const std::string& username, const std::string& password) {
return user_access_manager->IsAuthenticated(host, username, password);
});
options.auth = server_authenticator.get();
}
options.num_threads = FLAGS_thread_pool_size;
brpc::Server server;
if (server.AddService(tablet, brpc::SERVER_DOESNT_OWN_SERVICE) != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/sql_cmd_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3545,7 +3545,7 @@ TEST_P(DBSDKTest, ShowComponents) {
void ExpectShowTableStatusResult(const std::vector<std::vector<test::CellExpectInfo>>& expect,
hybridse::sdk::ResultSet* rs, bool all_db = false, bool is_cluster = false) {
static const std::vector<std::vector<test::CellExpectInfo>> SystemClusterTableStatus = {
{{}, "USER", "__INTERNAL_DB", "memory", {}, {}, {}, "1", "0", "1", "NULL", "NULL", "NULL", ""},
{{}, "USER", "__INTERNAL_DB", "memory", {}, {}, {}, "1", "0", "2", "NULL", "NULL", "NULL", ""},
{{}, "PRE_AGG_META_INFO", "__INTERNAL_DB", "memory", {}, {}, {}, "1", "0", "1", "NULL", "NULL", "NULL", ""},
{{}, "JOB_INFO", "__INTERNAL_DB", "memory", "0", {}, {}, "1", "0", "1", "NULL", "NULL", "NULL", ""},
{{},
Expand Down
1 change: 1 addition & 0 deletions src/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,4 @@ DEFINE_uint32(keep_log_file_num, 5, "Maximal info log files to be kept");
DEFINE_int32(sync_job_timeout, 30 * 60 * 1000,
"sync job timeout, unit is milliseconds, should <= server.channel_keep_alive_time in TaskManager");
DEFINE_int32(deploy_job_max_wait_time_ms, 30 * 60 * 1000, "the max wait time of waiting deploy job");
DEFINE_bool(skip_grant_tables, true, "skip the grant tables");
aceforeverd marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 22 additions & 12 deletions src/nameserver/name_server_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,12 @@ bool NameServerImpl::Init(const std::string& zk_cluster, const std::string& zk_p
task_vec_.resize(FLAGS_name_server_task_max_concurrency + FLAGS_name_server_task_concurrency_for_replica_cluster);
task_thread_pool_.DelayTask(FLAGS_make_snapshot_check_interval,
boost::bind(&NameServerImpl::SchedMakeSnapshot, this));
std::shared_ptr<::openmldb::nameserver::TableInfo> table_info;
while (!GetTableInfo(::openmldb::nameserver::USER_INFO_NAME, ::openmldb::nameserver::INTERNAL_DB, &table_info)) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (!FLAGS_skip_grant_tables) {
std::shared_ptr<::openmldb::nameserver::TableInfo> table_info;
while (
!GetTableInfo(::openmldb::nameserver::USER_INFO_NAME, ::openmldb::nameserver::INTERNAL_DB, &table_info)) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
return true;
}
Expand Down Expand Up @@ -5590,9 +5593,9 @@ void NameServerImpl::OnLocked() {
PDLOG(WARNING, "recover failed");
}
CreateDatabaseOrExit(INTERNAL_DB);
if (db_table_info_[INTERNAL_DB].count(USER_INFO_NAME) == 0) {
if (!FLAGS_skip_grant_tables && db_table_info_[INTERNAL_DB].count(USER_INFO_NAME) == 0) {
auto temp = FLAGS_system_table_replica_num;
FLAGS_system_table_replica_num = temp == 0 ? 1 : temp;
FLAGS_system_table_replica_num = tablets_.size();
CreateSystemTableOrExit(SystemTableType::kUser);
FLAGS_system_table_replica_num = temp;
InsertUserRecord("%", "root", "1e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
Expand Down Expand Up @@ -9585,26 +9588,33 @@ void NameServerImpl::DropProcedure(RpcController* controller, const api::DropPro
response->set_msg("ok");
}

std::function<std::unique_ptr<::openmldb::catalog::FullTableIterator>(const std::string& table_name)>
std::function<std::optional<std::pair<std::unique_ptr<::openmldb::catalog::FullTableIterator>,
std::unique_ptr<openmldb::codec::Schema>>>(const std::string& table_name)>
NameServerImpl::GetSystemTableIterator() {
return [this](const std::string& table_name) -> std::unique_ptr<::openmldb::catalog::FullTableIterator> {
return [this](const std::string& table_name)
-> std::optional<std::pair<std::unique_ptr<::openmldb::catalog::FullTableIterator>,
std::unique_ptr<openmldb::codec::Schema>>> {
std::shared_ptr<TableInfo> table_info;
if (!GetTableInfo(table_name, INTERNAL_DB, &table_info)) {
return nullptr;
return std::nullopt;
}
auto tid = table_info->tid();
auto table_partition = table_info->table_partition(0); // only one partition for system table
for (int meta_idx = 0; meta_idx < table_partition.partition_meta_size(); meta_idx++) {
if (table_partition.partition_meta(meta_idx).is_leader() &&
table_partition.partition_meta(meta_idx).is_alive()) {
auto endpoint = table_partition.partition_meta(meta_idx).endpoint();
auto table_ptr = GetTablet(endpoint);
auto tablet_ptr = GetTablet(endpoint);
if (tablet_ptr == nullptr) {
return std::nullopt;
}
std::map<uint32_t, std::shared_ptr<::openmldb::client::TabletClient>> tablet_clients = {
{0, table_ptr->client_}};
return std::make_unique<catalog::FullTableIterator>(tid, nullptr, tablet_clients);
{0, tablet_ptr->client_}};
return {{std::make_unique<catalog::FullTableIterator>(tid, nullptr, tablet_clients),
std::make_unique<::openmldb::codec::Schema>(table_info->column_desc())}};
}
}
return nullptr;
return std::nullopt;
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/nameserver/name_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ class NameServerImpl : public NameServer {
void DropProcedure(RpcController* controller, const api::DropProcedureRequest* request, GeneralResponse* response,
Closure* done);

std::function<std::unique_ptr<::openmldb::catalog::FullTableIterator>(const std::string& table_name)>
std::function<std::optional<std::pair<std::unique_ptr<::openmldb::catalog::FullTableIterator>,
std::unique_ptr<openmldb::codec::Schema>>>(const std::string& table_name)>
GetSystemTableIterator();

bool GetTableInfo(const std::string& table_name, const std::string& db_name,
Expand Down
2 changes: 0 additions & 2 deletions src/nameserver/name_server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,6 @@ TEST_F(NameServerImplTest, AddAndRemoveReplicaCluster) {
vector<shared_ptr<NameServerImpl>*> ns_vector = {&m1_ns1, &m1_ns2};
vector<shared_ptr<TabletImpl>*> tb_vector = {&m1_t1, &m1_t2};
vector<string*> endpoints = {&m1_t1_ep, &m1_t2_ep};
;

int port = 9632;

Expand Down Expand Up @@ -1028,7 +1027,6 @@ TEST_F(NameServerImplTest, SyncTableReplicaCluster) {
vector<shared_ptr<NameServerImpl>*> ns_vector = {&m1_ns1, &m1_ns2};
vector<shared_ptr<TabletImpl>*> tb_vector = {&m1_t1, &m1_t2};
vector<string*> endpoints = {&m1_t1_ep, &m1_t2_ep};
;

int port = 9632;

Expand Down
1 change: 1 addition & 0 deletions src/nameserver/system_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "proto/name_server.pb.h"

DECLARE_uint32(system_table_replica_num);
DECLARE_bool(skip_grant_tables);

namespace openmldb {
namespace nameserver {
Expand Down
4 changes: 2 additions & 2 deletions src/nameserver/system_table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class MockClosure : public ::google::protobuf::Closure {
};
class SystemTableTest : public ::testing::Test {
public:
SystemTableTest() {}
~SystemTableTest() {}
SystemTableTest() { FLAGS_skip_grant_tables = false; }
~SystemTableTest() { FLAGS_skip_grant_tables = true; }
};

TEST_F(SystemTableTest, SystemTable) {
Expand Down
Loading
Loading