lgraph_rpc_client
-
namespace fma_common
-
namespace lgraph_rpc
-
namespace lgraph
Enums
-
class RpcClient
- #include <lgraph_rpc_client.h>
Public Functions
-
explicit RpcClient(const std::string &url, const std::string &user, const std::string &password)
RpcClient Login.
- Parameters
url – Login address.
user – The username.
password – The password.
-
explicit RpcClient(std::vector<std::string> &urls, std::string user, std::string password)
RpcClient Login.
- Parameters
urls – Login address.
user – The username.
password – The password.
-
~RpcClient()
-
bool CallCypher(std::string &result, const std::string &cypher, const std::string &graph = "default", bool json_format = true, double timeout = 0, const std::string &url = "")
Execute a cypher query.
- Parameters
result – [out] The result.
cypher – [in] inquire statement.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
url – [in] (Optional) Node address of calling cypher.
- Returns
True if it succeeds, false if it fails.
-
bool CallProcedure(std::string &result, const std::string &procedure_type, const std::string &procedure_name, const std::string ¶m, double procedure_time_out = 0.0, bool in_process = false, const std::string &graph = "default", bool json_format = true, const std::string &url = "")
Execute a built-in procedure.
- Parameters
result – [out] The result.
procedure_type – [in] the procedure type, currently supported CPP and PY.
procedure_name – [in] procedure name.
param – [in] the execution parameters.
procedure_time_out – [in] (Optional) Maximum execution time, overruns will be interrupted.
in_process – [in] (Optional) support in future.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
url – [in] (Optional) Node address of calling procedure.
- Returns
True if it succeeds, false if it fails.
-
bool LoadProcedure(std::string &result, const std::string &source_file, const std::string &procedure_type, const std::string &procedure_name, const std::string &code_type, const std::string &procedure_description, bool read_only, const std::string &version = "v1", const std::string &graph = "default")
Load a built-in procedure.
- Parameters
result – [out] The result.
source_file – [in] the source_file contain procedure code.
procedure_type – [in] the procedure type, currently supported CPP and PY.
procedure_name – [in] procedure name.
code_type – [in] code type, currently supported PY, SO, CPP, ZIP.
procedure_description – [in] procedure description.
read_only – [in] procedure is read only or not.
version – [in] (Optional) the version of procedure.
graph – [in] (Optional) the graph to query.
- Returns
True if it succeeds, false if it fails.
-
bool ListProcedures(std::string &result, const std::string &procedure_type, const std::string &version = "any", const std::string &graph = "default", const std::string &url = "")
List user-defined procedures.
- Parameters
result – [out] The result.
procedure_type – [in] (Optional) the procedure type, “” for all procedures, CPP and PY for special type.
version – [in] (Optional) the version of procedure.
graph – [in] (Optional) the graph to query.
url – [in] Node address of calling procedure.
- Returns
True if it succeeds, false if it fails.
-
bool DeleteProcedure(std::string &result, const std::string &procedure_type, const std::string &procedure_name, const std::string &graph = "default")
Execute a user-defined procedure.
- Parameters
result – [out] The result.
procedure_type – [in] the procedure type, currently supported CPP and PY.
procedure_name – [in] procedure name.
graph – [in] (Optional) the graph to query.
- Returns
True if it succeeds, false if it fails.
-
bool ImportSchemaFromContent(std::string &result, const std::string &schema, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Import vertex or edge schema from content string.
- Parameters
result – [out] The result.
schema – [in] the schema to be imported.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
bool ImportDataFromContent(std::string &result, const std::string &desc, const std::string &data, const std::string &delimiter, bool continue_on_error = false, int thread_nums = 8, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Import vertex or edge data from content string.
- Parameters
result – [out] The result.
desc – [in] data format description.
data – [in] the data to be imported.
delimiter – [in] data separator.
continue_on_error – [in] (Optional) whether to continue when importing data fails.
thread_nums – [in] (Optional) maximum number of threads.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
bool ImportSchemaFromFile(std::string &result, const std::string &schema_file, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Import vertex or edge schema from file.
- Parameters
result – [out] The result.
schema_file – [in] the schema_file contain schema.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
bool ImportDataFromFile(std::string &result, const std::string &conf_file, const std::string &delimiter, bool continue_on_error = false, int thread_nums = 8, int skip_packages = 0, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Import vertex or edge data from file.
- Parameters
result – [out] The result.
conf_file – [in] data file contain format description and data.
delimiter – [in] data separator.
continue_on_error – [in] (Optional) whether to continue when importing data fails.
thread_nums – [in] (Optional) maximum number of threads.
skip_packages – [in] (Optional) skip packages number.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
int64_t Restore(const std::vector<BackupLogEntry> &requests)
-
void Logout()
Client log out.
Private Functions
-
bool IsReadCypher(const std::string &cypher, const std::string &graph)
Determine whether it is a read-only cypher.
- Parameters
cypher – [in] inquire statement.
graph – [in] (Optional) the graph to query.
- Returns
True if it succeeds, false if it fails.
-
std::shared_ptr<lgraph::RpcClient::RpcSingleClient> GetClient(const std::string &cypher, const std::string &graph)
Return rpc client based on whether it is a read-only query.
- Parameters
cypher – [in] inquire statement.
graph – [in] (Optional) the graph to query.
- Returns
Master rpc client if cypher is not read-only, slaver rpc client if cypher is read-only.
-
std::shared_ptr<lgraph::RpcClient::RpcSingleClient> GetClient(bool isReadQuery)
Return rpc client based on whether it is a read-only query.
- Parameters
isReadQuery – [in] read query or not.
- Returns
Master rpc client if cypher is not read-only, slaver rpc client if cypher is read-only.
-
std::shared_ptr<lgraph::RpcClient::RpcSingleClient> GetClientByNode(const std::string &url)
Get the client according to the node url.
- Parameters
url – [in] Node address of client connection.
- Returns
Rpc client connecting to url.
-
void RefreshUserDefinedProcedure()
Refresh User-defined Procedure.
-
void RefreshBuiltInProcedure()
Refresh Built-in Procedure.
-
void RefreshClientPool()
Refresh the client connection pool according to the cluster status.
-
void LoadBalanceClientPool()
Load balance the client pool.
-
void RefreshConnection()
Refresh client pool, procedure info.
Private Members
-
ClientType client_type
-
fma_common::Logger &logger_
-
std::string user
-
std::string password
-
std::shared_ptr<lgraph::RpcClient::RpcSingleClient> base_client
-
std::vector<std::string> urls
-
std::shared_ptr<lgraph::RpcClient::RpcSingleClient> leader_client
-
std::deque<std::shared_ptr<lgraph::RpcClient::RpcSingleClient>> client_pool
-
nlohmann::json built_in_procedures = {}
-
nlohmann::json user_defined_procedures = {}
-
std::vector<std::string> cypher_constant
-
class RpcSingleClient
Public Functions
-
RpcSingleClient(const std::string &url, const std::string &user, const std::string &password)
RpcSingleClient Login.
- Parameters
url – Login address.
user – The username.
password – The password.
-
~RpcSingleClient()
-
int64_t Restore(const std::vector<BackupLogEntry> &requests)
-
bool LoadProcedure(std::string &result, const std::string &source_file, const std::string &procedure_type, const std::string &procedure_name, const std::string &code_type, const std::string &procedure_description, bool read_only, const std::string &version = "v1", const std::string &graph = "default")
Load a user-defined procedure.
- Parameters
result – [out] The result.
source_file – [in] the source_file contain procedure code.
procedure_type – [in] the procedure type, currently supported CPP and PY.
procedure_name – [in] procedure name.
code_type – [in] code type, currently supported PY, SO, CPP, ZIP.
procedure_description – [in] procedure description.
read_only – [in] procedure is read only or not.
version – [in] (Optional) the version of procedure.
graph – [in] (Optional) the graph to query.
- Returns
True if it succeeds, false if it fails.
-
bool CallProcedure(std::string &result, const std::string &procedure_type, const std::string &procedure_name, const std::string ¶m, double procedure_time_out = 0.0, bool in_process = false, const std::string &graph = "default", bool json_format = true)
Execute a user-defined procedure.
- Parameters
result – [out] The result.
procedure_type – [in] the procedure type, currently supported CPP and PY.
procedure_name – [in] procedure name.
param – [in] the execution parameters.
procedure_time_out – [in] (Optional) Maximum execution time, overruns will be interrupted.
in_process – [in] (Optional) support in future.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json, Otherwise, binary format.
- Returns
True if it succeeds, false if it fails.
-
bool ListProcedures(std::string &result, const std::string &procedure_type, const std::string &version = "any", const std::string &graph = "default")
List user-defined procedures.
- Parameters
result – [out] The result.
procedure_type – [in] (Optional) the procedure type, “” for all procedures, CPP and PY for special type.
version – [in] (Optional) the version of procedure.
graph – [in] (Optional) the graph to query.
- Returns
True if it succeeds, false if it fails.
-
bool DeleteProcedure(std::string &result, const std::string &procedure_type, const std::string &procedure_name, const std::string &graph = "default")
Execute a user-defined procedure.
- Parameters
result – [out] The result.
procedure_type – [in] the procedure type, currently supported CPP and PY.
procedure_name – [in] procedure name.
graph – [in] (Optional) the graph to query.
- Returns
True if it succeeds, false if it fails.
-
bool ImportSchemaFromFile(std::string &result, const std::string &schema_file, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Import vertex or edge schema from file.
- Parameters
result – [out] The result.
schema_file – [in] the schema_file contain schema.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
bool ImportDataFromFile(std::string &result, const std::string &conf_file, const std::string &delimiter, bool continue_on_error = false, int thread_nums = 8, int skip_packages = 0, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Import vertex or edge data from file.
- Parameters
result – [out] The result.
conf_file – [in] data file contain format description and data.
delimiter – [in] data separator.
continue_on_error – [in] (Optional) whether to continue when importing data fails.
thread_nums – [in] (Optional) maximum number of threads.
skip_packages – [in] (Optional) skip packages number.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
bool ImportSchemaFromContent(std::string &result, const std::string &schema, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Import vertex or edge schema from content string.
- Parameters
result – [out] The result.
schema – [in] the schema to be imported.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
bool ImportDataFromContent(std::string &result, const std::string &desc, const std::string &data, const std::string &delimiter, bool continue_on_error = false, int thread_nums = 8, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Import vertex or edge data from content string.
- Parameters
result – [out] The result.
desc – [in] data format description.
data – [in] the data to be imported.
delimiter – [in] data separator.
continue_on_error – [in] (Optional) whether to continue when importing data fails.
thread_nums – [in] (Optional) maximum number of threads.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
bool CallCypher(std::string &result, const std::string &cypher, const std::string &graph = "default", bool json_format = true, double timeout = 0)
Execute a cypher query.
- Parameters
result – [out] The result.
cypher – [in] inquire statement.
graph – [in] (Optional) the graph to query.
json_format – [in] (Optional) Returns the format, true is json,Otherwise, binary format.
timeout – [in] (Optional) Maximum execution time, overruns will be interrupted.
- Returns
True if it succeeds, false if it fails.
-
std::string GetUrl()
Get the url of single client.
- Returns
the url of single client.
-
void Logout()
Client log out.
Private Functions
-
LGraphResponse HandleRequest(LGraphRequest *req)
-
bool HandleCypherRequest(LGraphResponse *res, const std::string &query, const std::string &graph, bool json_format, double timeout)
-
std::string CypherResponseExtractor(const CypherResponse &cypher)
Private Members
-
std::string url
-
std::string user
-
std::string password
-
std::string token
-
int64_t server_version
-
std::shared_ptr<lgraph_rpc::m_channel> channel
-
std::shared_ptr<lgraph_rpc::m_controller> cntl
-
std::shared_ptr<lgraph_rpc::m_channel_options> options
-
fma_common::Logger &logger_
-
RpcSingleClient(const std::string &url, const std::string &user, const std::string &password)
-
explicit RpcClient(const std::string &url, const std::string &user, const std::string &password)
-
class RpcClient