Skip to content

Commit

Permalink
fix: deny create table with distribution options for standalone DB (4…
Browse files Browse the repository at this point in the history
  • Loading branch information
keyu813 authored Feb 10, 2022
1 parent 059862d commit ef2e6e8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/sdk/sql_cluster_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,8 @@ bool SQLClusterRouter::ShowDB(std::vector<std::string>* dbs, hybridse::sdk::Stat
}

// get all table names in all DB
std::vector<std::string> SQLClusterRouter::GetAllTables() {
return cluster_sdk_->GetAllTables();
}

std::vector<std::string> SQLClusterRouter::GetAllTables() { return cluster_sdk_->GetAllTables(); }

bool SQLClusterRouter::CreateDB(const std::string& db, hybridse::sdk::Status* status) {
if (status == NULL) {
return false;
Expand Down Expand Up @@ -1403,6 +1401,18 @@ base::Status SQLClusterRouter::HandleSQLCreateTable(hybridse::node::CreatePlanNo
}
::openmldb::nameserver::TableInfo table_info;
table_info.set_db(db_name);

if (!cluster_sdk_->IsClusterMode()) {
if (create_node->GetReplicaNum() != 1) {
return base::Status(base::ReturnCode::kSQLCmdRunError,
"Fail to create table with the replica configuration in standalone mode");
}
if (!create_node->GetDistributionList().empty()) {
return base::Status(base::ReturnCode::kSQLCmdRunError,
"Fail to create table with the distribution configuration in standalone mode");
}
}

hybridse::base::Status sql_status;
::openmldb::sdk::NodeAdapter::TransformToTableDef(create_node, true, &table_info, &sql_status);
if (sql_status.code != 0) {
Expand Down Expand Up @@ -1731,9 +1741,7 @@ ::openmldb::base::Status SQLClusterRouter::ExportOfflineData(const std::string&
return taskmanager_client_ptr->ExportOfflineData(sql, config, default_db, job_info);
}

bool SQLClusterRouter::NotifyTableChange() {
return cluster_sdk_->TriggerNotify();
}
bool SQLClusterRouter::NotifyTableChange() { return cluster_sdk_->TriggerNotify(); }

} // namespace sdk
} // namespace openmldb

0 comments on commit ef2e6e8

Please sign in to comment.