Skip to content

Commit 354bcda

Browse files
authored
fix: fix deploy (#3503)
1 parent 9e03d53 commit 354bcda

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

src/client/ns_client.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,18 +612,26 @@ bool NsClient::UpdateTableAliveStatus(const std::string& endpoint, std::string&
612612

613613
bool NsClient::UpdateTTL(const std::string& name, const ::openmldb::type::TTLType& type, uint64_t abs_ttl,
614614
uint64_t lat_ttl, const std::string& index_name, std::string& msg) {
615+
return UpdateTTL(GetDb(), name, type, abs_ttl, lat_ttl, index_name, msg);
616+
}
617+
618+
bool NsClient::UpdateTTL(const std::string& db, const std::string& name, const ::openmldb::type::TTLType& type,
619+
uint64_t abs_ttl, uint64_t lat_ttl, const std::string& index_name, std::string& msg) {
615620
::openmldb::nameserver::UpdateTTLRequest request;
616621
::openmldb::nameserver::UpdateTTLResponse response;
617622
request.set_name(name);
618-
request.set_db(GetDb());
623+
if (db.empty()) {
624+
request.set_db(GetDb());
625+
} else {
626+
request.set_db(db);
627+
}
619628
::openmldb::common::TTLSt* ttl_desc = request.mutable_ttl_desc();
620629
ttl_desc->set_ttl_type(type);
621630
ttl_desc->set_abs_ttl(abs_ttl);
622631
ttl_desc->set_lat_ttl(lat_ttl);
623632
if (!index_name.empty()) {
624633
request.set_index_name(index_name);
625634
}
626-
request.set_db(GetDb());
627635
bool ok = client_.SendRequest(&::openmldb::nameserver::NameServer_Stub::UpdateTTL, &request, &response,
628636
FLAGS_request_timeout_ms, 1);
629637
msg = response.msg();

src/client/ns_client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ class NsClient : public Client {
193193
bool UpdateTTL(const std::string& name, const ::openmldb::type::TTLType& type, uint64_t abs_ttl, uint64_t lat_ttl,
194194
const std::string& ts_name, std::string& msg); // NOLINT
195195

196+
bool UpdateTTL(const std::string& db, const std::string& name, const ::openmldb::type::TTLType& type,
197+
uint64_t abs_ttl, uint64_t lat_ttl, const std::string& ts_name, std::string& msg); // NOLINT
198+
196199
bool AddReplicaClusterByNs(const std::string& alias, const std::string& name, uint64_t term,
197200
std::string& msg); // NOLINT
198201

src/sdk/sql_cluster_router.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3798,8 +3798,8 @@ hybridse::sdk::Status SQLClusterRouter::GetNewIndex(const TableInfoMap& table_ma
37983798
// update ttl
37993799
auto ns_ptr = cluster_sdk_->GetNsClient();
38003800
std::string err;
3801-
if (!ns_ptr->UpdateTTL(table_name, result.ttl_type(), result.abs_ttl(), result.lat_ttl(),
3802-
old_column_key.index_name(), err)) {
3801+
if (!ns_ptr->UpdateTTL(db_name, table_name, result.ttl_type(),
3802+
result.abs_ttl(), result.lat_ttl(), old_column_key.index_name(), err)) {
38033803
return {StatusCode::kCmdError, "update ttl failed"};
38043804
}
38053805
}

src/sdk/sql_cluster_test.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,40 @@ TEST_F(SQLSDKQueryTest, GetTabletClient) {
646646
ASSERT_TRUE(router->DropDB(db, &status));
647647
}
648648

649+
TEST_F(SQLClusterTest, DeployWithMultiDB) {
650+
SQLRouterOptions sql_opt;
651+
sql_opt.zk_cluster = mc_->GetZkCluster();
652+
sql_opt.zk_path = mc_->GetZkPath();
653+
auto router = NewClusterSQLRouter(sql_opt);
654+
SetOnlineMode(router);
655+
ASSERT_TRUE(router != nullptr);
656+
std::string base_table = "test" + GenRand();
657+
std::string db1 = "db1";
658+
std::string db2 = "db2";
659+
::hybridse::sdk::Status status;
660+
ASSERT_TRUE(router->ExecuteDDL(db1, "drop table if exists db1.t1;", &status));
661+
ASSERT_TRUE(router->ExecuteDDL(db2, "drop table if exists db2.t1;", &status));
662+
ASSERT_TRUE(router->ExecuteDDL(db1, "drop database if exists db1;", &status));
663+
ASSERT_TRUE(router->ExecuteDDL(db2, "drop database if exists db2;", &status));
664+
ASSERT_TRUE(router->CreateDB(db1, &status));
665+
ASSERT_TRUE(router->CreateDB(db2, &status));
666+
std::string sql1 = "create table db1.t1 (c1 string, c2 int, c3 bigint, c4 timestamp, index(key=c1, ts=c4));";
667+
std::string sql2 = "create table db2.t1 (c1 string, c2 int, c3 bigint, c4 timestamp, index(key=c1, ts=c3));";
668+
ASSERT_TRUE(router->ExecuteDDL(db1, sql1, &status));
669+
ASSERT_TRUE(router->ExecuteDDL(db2, sql2, &status));
670+
ASSERT_TRUE(router->ExecuteDDL(db1, "use " + db1 + ";", &status));
671+
std::string sql = "deploy demo select db1.t1.c1,db1.t1.c2,db2.t1.c3,db2.t1.c4 from db1.t1 "
672+
"last join db2.t1 ORDER BY db2.t1.c3 on db1.t1.c1=db2.t1.c1;";
673+
ASSERT_TRUE(router->RefreshCatalog());
674+
router->ExecuteSQL(sql, &status);
675+
ASSERT_TRUE(status.IsOK());
676+
ASSERT_TRUE(router->ExecuteDDL(db1, "drop deployment demo;", &status));
677+
ASSERT_TRUE(router->ExecuteDDL(db1, "drop table t1;", &status));
678+
ASSERT_TRUE(router->ExecuteDDL(db2, "drop table t1;", &status));
679+
ASSERT_TRUE(router->DropDB(db1, &status));
680+
ASSERT_TRUE(router->DropDB(db2, &status));
681+
}
682+
649683
TEST_F(SQLClusterTest, CreatePreAggrTable) {
650684
SQLRouterOptions sql_opt;
651685
sql_opt.zk_cluster = mc_->GetZkCluster();

0 commit comments

Comments
 (0)