Skip to content

Commit

Permalink
[feat][sdk] Support init log when build client
Browse files Browse the repository at this point in the history
  • Loading branch information
wchuande authored and ketor committed May 11, 2024
1 parent dcab021 commit 3bcfaee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/pysdk/dingosdk.swg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ using namespace dingodb::sdk;
namespace dingodb {
namespace sdk {

%feature("docstring") Client::BuildAndInitLog "return Status, Client"
%feature("docstring") Client::Build "return Status, Client"
%feature("docstring") Client::NewRawKV "return Status, RawKV"
%feature("docstring") Client::NewTransaction "return Status, Transaction"
Expand Down
2 changes: 1 addition & 1 deletion src/pysdk/examples/pysdk_vector_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
g_flat_param = dingosdk.FlatParam(g_dimension, dingosdk.kL2)
g_vector_ids = []

s, g_client = dingosdk.Client.Build(args.coordinator_url)
s, g_client = dingosdk.Client.BuildAndInitLog(args.coordinator_url)
assert s.ok(), f"client build fail, {s.ToString()}"

s, g_vector_client = g_client.NewVectorClient()
Expand Down
2 changes: 1 addition & 1 deletion src/pysdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""
setuptools.setup(
name="dingosdk",
version="0.1rc3",
version="0.1rc5",
description="dingo-store python sdk",
license="Apache License 2.0",
long_description=long_description,
Expand Down
18 changes: 18 additions & 0 deletions src/sdk/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@
namespace dingodb {
namespace sdk {

Status Client::BuildAndInitLog(std::string naming_service_url, Client** client) {
if (naming_service_url.empty()) {
return Status::InvalidArgument("naming_service_url is empty");
};

Client* tmp = new Client();
Status s = tmp->Init(std::move(naming_service_url));
if (!s.ok()) {
delete tmp;
return s;
}

google::InitGoogleLogging("dingo_sdk");

*client = tmp;
return s;
}

Status Client::Build(std::string naming_service_url, Client** client) {
if (naming_service_url.empty()) {
return Status::InvalidArgument("naming_service_url is empty");
Expand Down
4 changes: 4 additions & 0 deletions src/sdk/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class Client {

~Client();

// NOTE:: Caller must delete *client when it is no longer needed.
// TODO: add client builder if we have more options
static Status BuildAndInitLog(std::string naming_service_url, Client** client);

// NOTE:: Caller must delete *client when it is no longer needed.
static Status Build(std::string naming_service_url, Client** client);

Expand Down

0 comments on commit 3bcfaee

Please sign in to comment.