lgraph_galaxy

namespace lgraph
namespace lgraph_api
class Galaxy
#include <lgraph_galaxy.h>

A galaxy is the storage engine for one TuGraph instance. It manages a set of User/Role/GraphDBs.

A galaxy can be opened in async mode, in which case ALL write transactions will be treated as async, whether they declare async or not. This can come in handy if we are performing a lot of writing, but can cause data loss for online processing.

Public Functions

explicit Galaxy(const std::string &dir, bool durable = false, bool create_if_not_exist = true)

Constructor.

抛出
  • DBNotExistError – Thrown if DB does not exist and create_if_not_exist is false.

  • IOError – Thrown if DB does not exist, but we failed to create the DB due to IO error.

  • InputError – Thrown if there are other input errors. e.g., dir is actually a plain file, or DB is corruptted.

参数
  • dir – The TuGraph dir.

  • durable – (Optional) True to open in durable mode. If set to false, ALL write transactions are async, whether they declare async or not.

  • create_if_not_exist – (Optional) If true, the TuGraph DB will be created if dir does not exist; otherwise, an exception is thrown.

Galaxy(const std::string &dir, const std::string &user, const std::string &password, bool durable, bool create_if_not_exist)

Constructor. Open the Galaxy and try to login with specified user and password.

抛出
  • DBNotExistError – Thrown if DB does not exist and create_if_not_exist is false.

  • IOError – Thrown if DB does not exist, but we failed to create the DB due to IO error.

  • InputError – Thrown if there are other input errors. e.g., dir is actually a plain file, or DB is corruptted.

  • UnauthorizedError – Thrown if user/password is not correct.

参数
  • dir – The dir.

  • user – The user.

  • password – The password.

  • durable – True to open the Galaxy in durable mode.

  • create_if_not_exist – True to create if DB does not exist.

Galaxy(Galaxy&&)
Galaxy &operator=(Galaxy&&)
~Galaxy()
void SetCurrentUser(const std::string &user, const std::string &password)

Validate and set current user

抛出
参数
  • user – The user.

  • password – The password.

void SetUser(const std::string &user)

Set current user

抛出
参数

user – The current user.

bool CreateGraph(const std::string &graph_name, const std::string &description = "", size_t max_size = (size_t)1 << 40)

Validate token and set current user

抛出
参数

graph_name – Name of the graph to create. description (Optional) Description of the graph. max_size (Optional) Maximum size of the graph.

返回

True if it succeeds, false if graph already exists.

bool DeleteGraph(const std::string &graph_name)

Delete a graph

抛出
参数

graph_name – Name of the graph.

返回

True if it succeeds, false if the graph does not exist.

bool ModGraph(const std::string &graph_name, bool mod_desc, const std::string &desc, bool mod_size, size_t new_max_size)

Modify graph info

抛出
参数
  • graph_name – Name of the graph.

  • mod_desc – True to modifier description.

  • desc – The new description.

  • mod_size – True to modifier size.

  • new_max_size – New maximum size.

返回

True if it succeeds, false if it fails.

std::map<std::string, std::pair<std::string, size_t>> ListGraphs() const

List graphs

抛出
返回

A dictionary of {graph_name: (description, max_size)}

bool CreateUser(const std::string &user, const std::string &password, const std::string &desc = "")

Creates a user

抛出
参数
  • user – The user.

  • password – The password.

  • desc – (Optional) The description.

返回

True if it succeeds, false if user already exists.

bool DeleteUser(const std::string &user)

Deletes the user.

抛出
参数

user – The user.

返回

True if it succeeds, false if user does not exist.

bool SetPassword(const std::string &user, const std::string &old_password, const std::string &new_password)

Set the password of the specified user.

抛出
  • InvalidGalaxyError – Thrown if current galaxy is invalid.

  • UnauthorizedError – Thrown if user does not have permission, or curr_user==user, but old_password is incorrect.

  • InputError – Thrown if new_password is illegal.

参数
  • user – The user to modify.

  • old_password – The old password, required if curr_user==user.

  • new_password – The new password.

返回

True if it succeeds, false if user does not exist.

bool SetUserDesc(const std::string &user, const std::string &desc)

Sets user description.

抛出
参数
  • user – The user.

  • desc – The new description.

返回

True if it succeeds, false if user does not exist.

bool SetUserRoles(const std::string &user, const std::vector<std::string> &roles)

Set the roles of the specified user. If you need to add or delete a role, you will need to use GetUserInfo to get the roles first.

抛出
参数
  • user – The user.

  • roles – A list of roles.

返回

True if it succeeds, false if user does not exist.

bool SetUserGraphAccess(const std::string &user, const std::string &graph, const AccessLevel &access)

Sets user access rights on a graph.

抛出
参数
  • user – The user.

  • graph – The graph.

  • access – The access level.

返回

True if it succeeds, false if it user does not exist.

bool DisableUser(const std::string &user)

Disable a user. A disabled user is not able to login or perform any operation. A user cannot disable itself.

抛出
参数

user – The user to disable.

返回

True if it succeeds, false if user does not exist.

bool EnableUser(const std::string &user)

Enables the user.

抛出
参数

user – The user.

返回

True if it succeeds, false if user does not exist.

std::map<std::string, UserInfo> ListUsers() const

List all users

抛出
返回

A dictionary of {user_name:user_info}

UserInfo GetUserInfo(const std::string &user) const

Gets user information

抛出
参数

user – The user.

返回

The user information.

bool CreateRole(const std::string &role, const std::string &desc)

Create a role. A role has different access levels to different graphs. Every user must be assigned some role to get access to graphs.

抛出
参数
  • role – The role.

  • desc – The description.

返回

True if it succeeds, false if role already exists.

bool DeleteRole(const std::string &role)

Deletes the role described by role

抛出
参数

role – The role.

返回

True if it succeeds, false if role does not exist.

bool DisableRole(const std::string &role)

Disable a role. A disabled role still has the data, but is not effective. i.e., users will not have access rights to graphs that are obtained by having this role.

抛出
参数

role – The role.

返回

True if it succeeds, false if the role does not exist.

bool EnableRole(const std::string &role)

Enables the role.

抛出
参数

role – The role.

返回

True if it succeeds, false if role does not exist.

bool SetRoleDesc(const std::string &role, const std::string &desc)

Set the description of the specified role

抛出
参数
  • role – The role.

  • desc – The description.

返回

True if it succeeds, false if role does not exist.

bool SetRoleAccessRights(const std::string &role, const std::map<std::string, AccessLevel> &graph_access)

Set access of the role to graphs. If you need to add or remove access to part of the graphs, you need to get full graph_access map by using GetRoleInfo first.

抛出
参数
  • role – The role.

  • graph_access – The graph access.

返回

True if it succeeds, false if role does not exist.

bool SetRoleAccessRightsIncremental(const std::string &role, const std::map<std::string, AccessLevel> &graph_access)

Incrementally modify the access right of the specified role. For example, for a role that has access right {graph1:READ, graph2:WRITE}, calling this function with graph_access={graph2:READ, graph3:FULL} will set the access right of this role to {graph1:READ, graph2:READ, graph3:FULL}

抛出
参数
  • role – The role.

  • graph_access – The graph access.

返回

True if it succeeds, false if role does not exist.

RoleInfo GetRoleInfo(const std::string &role) const

Gets role information

抛出
参数

role – The role.

返回

The role information.

std::map<std::string, RoleInfo> ListRoles() const

List all the roles

抛出
返回

A dictionary of {role_name:RoleInfo}

AccessLevel GetAccessLevel(const std::string &user, const std::string &graph) const

Get the access level that the specified user have to the graph

抛出
参数
  • user – The user.

  • graph – The graph.

返回

The access level.

GraphDB OpenGraph(const std::string &graph, bool read_only = false) const

Opens a graph.

抛出
参数
  • graph – The graph.

  • read_only – (Optional) True to open in read-only mode. A read-only GraphDB cannot be written to.

返回

A GraphDB.

void Close()

Closes this Galaxy, turning it into an invalid state.

Private Functions

explicit Galaxy(lgraph::Galaxy *db)
inline Galaxy(const Galaxy&)
inline Galaxy &operator=(const Galaxy&)

Private Members

std::string user_
lgraph::Galaxy *db_