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.
- Throws
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.
- Parameters
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.
- Throws
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.
- Parameters
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()
-
void SetCurrentUser(const std::string &user, const std::string &password)
Validate and set current user.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user/password is incorrect.
- Parameters
user – The user.
password – The password.
-
void SetUser(const std::string &user)
Set current user.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if token is incorrect.
- Parameters
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission to create graph.
InputError – Other input errors such as invalid graph name, size, etc.
- Parameters
graph_name – Name of the graph to create. description (Optional) Description of the graph. max_size (Optional) Maximum size of the graph.
- Returns
True if it succeeds, false if graph already exists.
-
bool DeleteGraph(const std::string &graph_name)
Delete a graph.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission to delete graph.
- Parameters
graph_name – Name of the graph.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission to modify graph.
- Parameters
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.
- Returns
True if it succeeds, false if it fails.
-
std::map<std::string, std::pair<std::string, size_t>> ListGraphs() const
List graphs.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission to list graphs.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if other input errors, such as illegal user name, password, etc.
- Parameters
user – The user.
password – The password.
desc – (Optional) The description.
- Returns
True if it succeeds, false if user already exists.
-
bool DeleteUser(const std::string &user)
Deletes the user.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
- Parameters
user – The user.
- Returns
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.
- Throws
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.
- Parameters
user – The user to modify.
old_password – The old password, required if curr_user==user.
new_password – The new password.
- Returns
True if it succeeds, false if user does not exist.
-
bool SetUserDesc(const std::string &user, const std::string &desc)
Sets user description.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if desc is illegal.
- Parameters
user – The user.
desc – The new description.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if any role does not exist.
- Parameters
user – The user.
roles – A list of roles.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if graph does not exist.
- Parameters
user – The user.
graph – The graph.
access – The access level.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if user name is illegal.
- Parameters
user – The user to disable.
- Returns
True if it succeeds, false if user does not exist.
-
bool EnableUser(const std::string &user)
Enables the user.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if user name is illegal.
- Parameters
user – The user.
- Returns
True if it succeeds, false if user does not exist.
-
std::map<std::string, UserInfo> ListUsers() const
List all users.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
- Returns
A dictionary of {user_name:user_info}
-
UserInfo GetUserInfo(const std::string &user) const
Gets user information.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
- Parameters
user – The user.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if role name or desc is illegal.
- Parameters
role – The role.
desc – The description.
- Returns
True if it succeeds, false if role already exists.
-
bool DeleteRole(const std::string &role)
Deletes the role described by role.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if role name is illegal.
- Parameters
role – The role.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if role name is illegal.
- Parameters
role – The role.
- Returns
True if it succeeds, false if the role does not exist.
-
bool EnableRole(const std::string &role)
Enables the role.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if role name is illegal.
- Parameters
role – The role.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if role name or desc is illegal.
- Parameters
role – The role.
desc – The description.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if role name or any of the graph name is illegal.
- Parameters
role – The role.
graph_access – The graph access.
- Returns
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}.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if role name or any of the graph name is illegal.
- Parameters
role – The role.
graph_access – The graph access.
- Returns
True if it succeeds, false if role does not exist.
-
RoleInfo GetRoleInfo(const std::string &role) const
Gets role information.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if role name is illegal.
- Parameters
role – The role.
- Returns
The role information.
-
std::map<std::string, RoleInfo> ListRoles() const
List all the roles.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
- Returns
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.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if user name or graph name is illegal.
- Parameters
user – The user.
graph – The graph.
- Returns
The access level.
-
GraphDB OpenGraph(const std::string &graph, bool read_only = false) const
Opens a graph.
- Throws
InvalidGalaxyError – Thrown if current galaxy is invalid.
UnauthorizedError – Thrown if user does not have permission.
InputError – Thrown if graph name is illegal.
- Parameters
graph – The graph.
read_only – (Optional) True to open in read-only mode. A read-only GraphDB cannot be written to.
- Returns
A GraphDB.
Private Functions
-
explicit Galaxy(const std::string &dir, bool durable = false, bool create_if_not_exist = true)
-
class Galaxy