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: tablets get user table remotely #3918

Merged
merged 8 commits into from
May 8, 2024
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", "2", "NULL", "NULL", "NULL", ""},
{{}, "USER", "__INTERNAL_DB", "memory", {}, {}, {}, "1", "0", "1", "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: 0 additions & 1 deletion src/nameserver/name_server_create_remote_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,5 @@ int main(int argc, char** argv) {
::openmldb::base::SetLogLevel(INFO);
::google::ParseCommandLineFlags(&argc, &argv, true);
::openmldb::test::InitRandomDiskFlags("name_server_create_remote_test");
FLAGS_system_table_replica_num = 0;
return RUN_ALL_TESTS();
}
3 changes: 0 additions & 3 deletions src/nameserver/name_server_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5592,10 +5592,7 @@ void NameServerImpl::OnLocked() {
}
CreateDatabaseOrExit(INTERNAL_DB);
if (db_table_info_[INTERNAL_DB].count(USER_INFO_NAME) == 0) {
auto temp = FLAGS_system_table_replica_num;
FLAGS_system_table_replica_num = tablets_.size();
CreateSystemTableOrExit(SystemTableType::kUser);
FLAGS_system_table_replica_num = temp;
InsertUserRecord("%", "root", "1e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
}
if (IsClusterMode()) {
Expand Down
1 change: 0 additions & 1 deletion src/nameserver/new_server_env_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,5 @@ int main(int argc, char** argv) {
::openmldb::base::SetLogLevel(INFO);
::google::ParseCommandLineFlags(&argc, &argv, true);
::openmldb::test::InitRandomDiskFlags("new_server_env_test");
FLAGS_system_table_replica_num = 0;
return RUN_ALL_TESTS();
}
1 change: 1 addition & 0 deletions src/sdk/sql_cluster_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ std::shared_ptr<SQLCache> SQLClusterRouter::GetSQLCache(const std::string& db, c
}
return router_cache;
}

std::shared_ptr<::openmldb::client::TabletClient> SQLClusterRouter::GetTabletClient(
const std::string& db, const std::string& sql, const ::hybridse::vm::EngineMode engine_mode,
const std::shared_ptr<SQLRequestRow>& row, hybridse::sdk::Status* status) {
Expand Down
1 change: 0 additions & 1 deletion src/tablet/procedure_drop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,5 @@ int main(int argc, char** argv) {
::openmldb::base::SetLogLevel(INFO);
::google::ParseCommandLineFlags(&argc, &argv, true);
::openmldb::test::InitRandomDiskFlags("procedure_recover_test");
FLAGS_system_table_replica_num = 0;
return RUN_ALL_TESTS();
}
1 change: 0 additions & 1 deletion src/tablet/procedure_recover_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,5 @@ int main(int argc, char** argv) {
::openmldb::base::SetLogLevel(INFO);
::google::ParseCommandLineFlags(&argc, &argv, true);
::openmldb::test::InitRandomDiskFlags("recover_procedure_test");
FLAGS_system_table_replica_num = 0;
return RUN_ALL_TESTS();
}
43 changes: 31 additions & 12 deletions src/tablet/tablet_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5819,19 +5819,38 @@ TabletImpl::GetSystemTableIterator() {
return [this](const std::string& table_name)
-> std::optional<std::pair<std::unique_ptr<::openmldb::catalog::FullTableIterator>,
std::unique_ptr<openmldb::codec::Schema>>> {
for (const auto& [tid, tables] : tables_) {
for (const auto& [pid, table] : tables) {
if (table->GetName() == table_name) {
std::map<uint32_t, std::shared_ptr<::openmldb::client::TabletClient>> empty_tablet_clients;
auto user_table = std::make_shared<std::map<uint32_t, std::shared_ptr<::openmldb::storage::Table>>>(
std::map<uint32_t, std::shared_ptr<::openmldb::storage::Table>>{{pid, table}});
return {{std::make_unique<::openmldb::catalog::FullTableIterator>(table->GetId(), user_table,
empty_tablet_clients),
std::make_unique<::openmldb::codec::Schema>(table->GetTableMeta()->column_desc())}};
}
}
auto handler = catalog_->GetTable(::openmldb::nameserver::INTERNAL_DB, ::openmldb::nameserver::USER_INFO_NAME);
if (!handler) {
PDLOG(WARNING, "no user table tablehandler");
return std::nullopt;
}
auto tablet_table_handler = std::dynamic_pointer_cast<catalog::TabletTableHandler>(handler);
if (!tablet_table_handler) {
PDLOG(WARNING, "convert user table tablehandler failed");
return std::nullopt;
}
auto table_client_manager = tablet_table_handler->GetTableClientManager();
if (table_client_manager == nullptr) {
return std::nullopt;
}
auto tablet = table_client_manager->GetTablet(0);
if (tablet == nullptr) {
return std::nullopt;
}
auto client = tablet->GetClient();
if (client == nullptr) {
return std::nullopt;
}

auto schema = std::make_unique<::openmldb::codec::Schema>();

if (openmldb::schema::SchemaAdapter::ConvertSchema(*tablet_table_handler->GetSchema(), schema.get())) {
std::map<uint32_t, std::shared_ptr<::openmldb::client::TabletClient>> tablet_clients = {{0, client}};
return {{std::make_unique<catalog::FullTableIterator>(tablet_table_handler->GetTid(), nullptr, tablet_clients),
std::move(schema)}};
} else {
return std::nullopt;
}
return std::nullopt;
};
}

Expand Down
Loading