Skip to content

Commit 7269141

Browse files
authored
feat: tablets get user table remotely (#3918)
* fix: make clients use auth by default * fix: let skip auth flag only affect verify * feat: tablets get user table remotely * fix: use FLAGS_system_table_replica_num for user table
1 parent 8ce7d72 commit 7269141

8 files changed

Lines changed: 33 additions & 20 deletions

src/cmd/sql_cmd_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3545,7 +3545,7 @@ TEST_P(DBSDKTest, ShowComponents) {
35453545
void ExpectShowTableStatusResult(const std::vector<std::vector<test::CellExpectInfo>>& expect,
35463546
hybridse::sdk::ResultSet* rs, bool all_db = false, bool is_cluster = false) {
35473547
static const std::vector<std::vector<test::CellExpectInfo>> SystemClusterTableStatus = {
3548-
{{}, "USER", "__INTERNAL_DB", "memory", {}, {}, {}, "1", "0", "2", "NULL", "NULL", "NULL", ""},
3548+
{{}, "USER", "__INTERNAL_DB", "memory", {}, {}, {}, "1", "0", "1", "NULL", "NULL", "NULL", ""},
35493549
{{}, "PRE_AGG_META_INFO", "__INTERNAL_DB", "memory", {}, {}, {}, "1", "0", "1", "NULL", "NULL", "NULL", ""},
35503550
{{}, "JOB_INFO", "__INTERNAL_DB", "memory", "0", {}, {}, "1", "0", "1", "NULL", "NULL", "NULL", ""},
35513551
{{},

src/nameserver/name_server_create_remote_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,5 @@ int main(int argc, char** argv) {
13591359
::openmldb::base::SetLogLevel(INFO);
13601360
::google::ParseCommandLineFlags(&argc, &argv, true);
13611361
::openmldb::test::InitRandomDiskFlags("name_server_create_remote_test");
1362-
FLAGS_system_table_replica_num = 0;
13631362
return RUN_ALL_TESTS();
13641363
}

src/nameserver/name_server_impl.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5592,10 +5592,7 @@ void NameServerImpl::OnLocked() {
55925592
}
55935593
CreateDatabaseOrExit(INTERNAL_DB);
55945594
if (db_table_info_[INTERNAL_DB].count(USER_INFO_NAME) == 0) {
5595-
auto temp = FLAGS_system_table_replica_num;
5596-
FLAGS_system_table_replica_num = tablets_.size();
55975595
CreateSystemTableOrExit(SystemTableType::kUser);
5598-
FLAGS_system_table_replica_num = temp;
55995596
InsertUserRecord("%", "root", "1e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
56005597
}
56015598
if (IsClusterMode()) {

src/nameserver/new_server_env_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,5 @@ int main(int argc, char** argv) {
467467
::openmldb::base::SetLogLevel(INFO);
468468
::google::ParseCommandLineFlags(&argc, &argv, true);
469469
::openmldb::test::InitRandomDiskFlags("new_server_env_test");
470-
FLAGS_system_table_replica_num = 0;
471470
return RUN_ALL_TESTS();
472471
}

src/sdk/sql_cluster_router.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ std::shared_ptr<SQLCache> SQLClusterRouter::GetSQLCache(const std::string& db, c
10191019
}
10201020
return router_cache;
10211021
}
1022+
10221023
std::shared_ptr<::openmldb::client::TabletClient> SQLClusterRouter::GetTabletClient(
10231024
const std::string& db, const std::string& sql, const ::hybridse::vm::EngineMode engine_mode,
10241025
const std::shared_ptr<SQLRequestRow>& row, hybridse::sdk::Status* status) {

src/tablet/procedure_drop_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,5 @@ int main(int argc, char** argv) {
297297
::openmldb::base::SetLogLevel(INFO);
298298
::google::ParseCommandLineFlags(&argc, &argv, true);
299299
::openmldb::test::InitRandomDiskFlags("procedure_recover_test");
300-
FLAGS_system_table_replica_num = 0;
301300
return RUN_ALL_TESTS();
302301
}

src/tablet/procedure_recover_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,5 @@ int main(int argc, char** argv) {
270270
::openmldb::base::SetLogLevel(INFO);
271271
::google::ParseCommandLineFlags(&argc, &argv, true);
272272
::openmldb::test::InitRandomDiskFlags("recover_procedure_test");
273-
FLAGS_system_table_replica_num = 0;
274273
return RUN_ALL_TESTS();
275274
}

src/tablet/tablet_impl.cc

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5819,19 +5819,38 @@ TabletImpl::GetSystemTableIterator() {
58195819
return [this](const std::string& table_name)
58205820
-> std::optional<std::pair<std::unique_ptr<::openmldb::catalog::FullTableIterator>,
58215821
std::unique_ptr<openmldb::codec::Schema>>> {
5822-
for (const auto& [tid, tables] : tables_) {
5823-
for (const auto& [pid, table] : tables) {
5824-
if (table->GetName() == table_name) {
5825-
std::map<uint32_t, std::shared_ptr<::openmldb::client::TabletClient>> empty_tablet_clients;
5826-
auto user_table = std::make_shared<std::map<uint32_t, std::shared_ptr<::openmldb::storage::Table>>>(
5827-
std::map<uint32_t, std::shared_ptr<::openmldb::storage::Table>>{{pid, table}});
5828-
return {{std::make_unique<::openmldb::catalog::FullTableIterator>(table->GetId(), user_table,
5829-
empty_tablet_clients),
5830-
std::make_unique<::openmldb::codec::Schema>(table->GetTableMeta()->column_desc())}};
5831-
}
5832-
}
5822+
auto handler = catalog_->GetTable(::openmldb::nameserver::INTERNAL_DB, ::openmldb::nameserver::USER_INFO_NAME);
5823+
if (!handler) {
5824+
PDLOG(WARNING, "no user table tablehandler");
5825+
return std::nullopt;
5826+
}
5827+
auto tablet_table_handler = std::dynamic_pointer_cast<catalog::TabletTableHandler>(handler);
5828+
if (!tablet_table_handler) {
5829+
PDLOG(WARNING, "convert user table tablehandler failed");
5830+
return std::nullopt;
5831+
}
5832+
auto table_client_manager = tablet_table_handler->GetTableClientManager();
5833+
if (table_client_manager == nullptr) {
5834+
return std::nullopt;
5835+
}
5836+
auto tablet = table_client_manager->GetTablet(0);
5837+
if (tablet == nullptr) {
5838+
return std::nullopt;
5839+
}
5840+
auto client = tablet->GetClient();
5841+
if (client == nullptr) {
5842+
return std::nullopt;
5843+
}
5844+
5845+
auto schema = std::make_unique<::openmldb::codec::Schema>();
5846+
5847+
if (openmldb::schema::SchemaAdapter::ConvertSchema(*tablet_table_handler->GetSchema(), schema.get())) {
5848+
std::map<uint32_t, std::shared_ptr<::openmldb::client::TabletClient>> tablet_clients = {{0, client}};
5849+
return {{std::make_unique<catalog::FullTableIterator>(tablet_table_handler->GetTid(), nullptr, tablet_clients),
5850+
std::move(schema)}};
5851+
} else {
5852+
return std::nullopt;
58335853
}
5834-
return std::nullopt;
58355854
};
58365855
}
58375856

0 commit comments

Comments
 (0)