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: add StandAloneClusterSDK #501

Merged
merged 11 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions hybridse/tools/hybridse_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ set -eE
# goto toplevel directory
cd "$(dirname "$0")/.."

# install thirdparty hybrise
# install thirdparty hybridse
HYBRIDSE_THIRDPARTY="$(pwd)/thirdparty"
../steps/setup_thirdparty.sh ${HYBRIDSE_THIRDPARTY}
../steps/setup_thirdparty.sh "${HYBRIDSE_THIRDPARTY}"

if uname -a | grep -q Darwin; then
# in case coreutils not install on mac
Expand Down
2 changes: 1 addition & 1 deletion src/apiserver/api_server_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool APIServerImpl::Init(const sdk::ClusterOptions& options) {
return Init(cluster_sdk);
}

bool APIServerImpl::Init(::openmldb::sdk::ClusterSDK* cluster) {
bool APIServerImpl::Init(::openmldb::sdk::DBSDK* cluster) {
// If cluster sdk is needed, use ptr, don't own it. SQLClusterRouter owns it.
cluster_sdk_ = cluster;
auto router = std::make_shared<::openmldb::sdk::SQLClusterRouter>(cluster_sdk_);
Expand Down
6 changes: 3 additions & 3 deletions src/apiserver/api_server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#ifndef SRC_APISERVER_API_SERVER_IMPL_H_
#define SRC_APISERVER_API_SERVER_IMPL_H_

#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

#include "apiserver/interface_provider.h"
#include "apiserver/json_helper.h"
Expand All @@ -46,7 +46,7 @@ class APIServerImpl : public APIServer {
APIServerImpl() = default;
~APIServerImpl() override;
bool Init(const sdk::ClusterOptions& options);
bool Init(::openmldb::sdk::ClusterSDK* cluster);
bool Init(::openmldb::sdk::DBSDK* cluster);
void Process(google::protobuf::RpcController* cntl_base, const HttpRequest*, HttpResponse*,
google::protobuf::Closure* done) override;
static std::string InnerTypeTransform(const std::string& s);
Expand All @@ -72,7 +72,7 @@ class APIServerImpl : public APIServer {
std::shared_ptr<sdk::SQLRouter> sql_router_;
InterfaceProvider provider_;
// cluster_sdk_ is not owned by this class.
::openmldb::sdk::ClusterSDK* cluster_sdk_;
::openmldb::sdk::DBSDK* cluster_sdk_ = nullptr;
};

struct PutResp {
Expand Down
31 changes: 15 additions & 16 deletions src/apiserver/api_server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "apiserver/api_server_impl.h"
#include "brpc/channel.h"
#include "memory"
#include "brpc/restful.h"
#include "brpc/server.h"
#include "butil/logging.h"
Expand All @@ -24,21 +25,20 @@
#include "json2pb/rapidjson.h"
#include "sdk/mini_cluster.h"

namespace openmldb {
namespace apiserver {
namespace openmldb::apiserver {

class APIServerTestEnv : public testing::Environment {
public:
static APIServerTestEnv* Instance() {
static APIServerTestEnv* instance = new APIServerTestEnv;
static auto* instance = new APIServerTestEnv;
return instance;
}
virtual void SetUp() {
void SetUp() override {
std::cout << "Environment SetUp!" << std::endl;
::hybridse::vm::Engine::InitializeGlobalLLVM();
FLAGS_zk_session_timeout = 100000;

mc.reset(new sdk::MiniCluster(6181));
mc = std::make_shared<sdk::MiniCluster>(6181);
ASSERT_TRUE(mc->SetUp()) << "Fail to set up mini cluster";

sdk::ClusterOptions cluster_options;
Expand All @@ -47,7 +47,7 @@ class APIServerTestEnv : public testing::Environment {
// Owned by queue_svc
cluster_sdk = new ::openmldb::sdk::ClusterSDK(cluster_options);
ASSERT_TRUE(cluster_sdk->Init()) << "Fail to connect to db";
queue_svc.reset(new APIServerImpl);
queue_svc = std::make_shared<APIServerImpl>();
ASSERT_TRUE(queue_svc->Init(cluster_sdk));

sdk::SQLRouterOptions sql_opt;
Expand Down Expand Up @@ -85,7 +85,7 @@ class APIServerTestEnv : public testing::Environment {
<< "Fail to initialize http channel";
}

virtual void TearDown() {
void TearDown() override {
std::cout << "Environment TearDown!" << std::endl;
hybridse::sdk::Status status;
cluster_remote->DropDB(db, &status);
Expand All @@ -95,7 +95,7 @@ class APIServerTestEnv : public testing::Environment {
}

std::string db;
::openmldb::sdk::ClusterSDK* cluster_sdk;
::openmldb::sdk::DBSDK* cluster_sdk = nullptr;
std::shared_ptr<sdk::MiniCluster> mc;
std::shared_ptr<APIServerImpl> queue_svc;
brpc::Server server;
Expand All @@ -109,11 +109,11 @@ class APIServerTestEnv : public testing::Environment {

class APIServerTest : public ::testing::Test {
public:
APIServerTest() {}
~APIServerTest() {}
APIServerTest() = default;
~APIServerTest() override {}
};

TEST_F(APIServerTest, json_format) {
TEST_F(APIServerTest, jsonFormat) {
butil::rapidjson::Document document;

// Check the format of put request
Expand Down Expand Up @@ -142,7 +142,7 @@ TEST_F(APIServerTest, json_format) {
ASSERT_EQ(butil::rapidjson::kNullType, arr[6].GetType());
}

TEST_F(APIServerTest, invalid_put) {
TEST_F(APIServerTest, invalidPut) {
const auto env = APIServerTestEnv::Instance();
brpc::Controller cntl;
cntl.http_request().set_method(brpc::HTTP_METHOD_PUT);
Expand Down Expand Up @@ -202,7 +202,7 @@ TEST_F(APIServerTest, invalid_put) {
LOG(INFO) << resp.msg;
}

TEST_F(APIServerTest, valid_put) {
TEST_F(APIServerTest, validPut) {
const auto env = APIServerTestEnv::Instance();

// create table
Expand Down Expand Up @@ -258,7 +258,7 @@ TEST_F(APIServerTest, valid_put) {
ASSERT_TRUE(env->cluster_remote->ExecuteDDL(env->db, "drop table " + table + ";", &status)) << status.msg;
}

TEST_F(APIServerTest, put_case1) {
TEST_F(APIServerTest, putCase1) {
const auto env = APIServerTestEnv::Instance();

// create table
Expand Down Expand Up @@ -651,8 +651,7 @@ TEST_F(APIServerTest, getTables) {
}
}

} // namespace apiserver
} // namespace openmldb
} // namespace openmldb::apiserver

int main(int argc, char* argv[]) {
testing::AddGlobalTestEnvironment(openmldb::apiserver::APIServerTestEnv::Instance());
Expand Down
17 changes: 6 additions & 11 deletions src/cmd/openmldb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
#include <gflags/gflags.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
#include <sched.h>
#include <snappy.h>
#include <unistd.h>

#include <csignal>
#include <iostream>
#include <memory>
#include <random>
Expand All @@ -48,18 +46,15 @@
#include "cmd/display.h"
#include "cmd/sdk_iterator.h"
#include "cmd/sql_cmd.h"
#include "codec/row_codec.h"
#include "codec/schema_codec.h"
#include "codec/sdk_codec.h"
#include "common/timer.h"
#include "common/tprinter.h"
#include "config.h" // NOLINT
#include "proto/client.pb.h"
#include "proto/name_server.pb.h"
#include "proto/tablet.pb.h"
#include "proto/type.pb.h"
#include "version.h" // NOLINT
#include "vm/engine.h"

using Schema = ::google::protobuf::RepeatedPtrField<::openmldb::common::ColumnDesc>;
using TabletClient = openmldb::client::TabletClient;
Expand Down Expand Up @@ -120,6 +115,7 @@ void GetRealEndpoint(std::string* real_endpoint) {
if (real_endpoint == nullptr) {
return;
}
// TODO(hw): only endpoint
if (FLAGS_endpoint.empty() && FLAGS_port > 0) {
std::string ip;
if (::openmldb::base::GetLocalIp(&ip)) {
Expand Down Expand Up @@ -4851,17 +4847,17 @@ void StartAPIServer() {
exit(1);
}
PDLOG(INFO, "start apiserver on endpoint %s with version %s", real_endpoint.c_str(), OPENMLDB_VERSION.c_str());
server.set_version(OPENMLDB_VERSION.c_str());
server.set_version(OPENMLDB_VERSION);
server.RunUntilAskedToQuit();
}

int main(int argc, char* argv[]) {
::google::SetVersionString(OPENMLDB_VERSION.c_str());
::google::SetVersionString(OPENMLDB_VERSION);
::google::ParseCommandLineFlags(&argc, &argv, true);
if (FLAGS_role == "ns_client") {
StartNsClient();
} else if (FLAGS_role == "sql_client") {
::openmldb::cmd::HandleCli();
::openmldb::cmd::ClusterSQLClient();
#if defined(__linux__) || defined(__mac_tablet__)
} else if (FLAGS_role == "tablet") {
StartTablet();
Expand All @@ -4873,9 +4869,8 @@ int main(int argc, char* argv[]) {
StartAPIServer();
#endif
} else {
std::cout << "Start failed! FLAGS_role must be tablet, client, "
"nameserver, ns_client, apiserver"
<< std::endl;
std::cout << "client start in stand-alone mode" << std::endl;
::openmldb::cmd::StandAloneSQLClient();
}
return 0;
}
Loading