crate.operator.cratedb module¶
- async crate.operator.cratedb.are_snapshots_in_progress(conn_factory, logger)¶
Check if there are any snapshots in progress by querying sys.jobs (or the configured table for testing purposes).
Since sys.jobs will also contain the current query (i.e. us selecting from sys.jobs) we also need to exclude our statement.
:param conn_factory the connection factory to connect to CrateDB :param logger the logger on which we’re logging :return A Tuple of the result (Bool) and the statement that is progress (if any).
- crate.operator.cratedb.connection_factory(host, password, username='system', **kwargs)¶
Create a connection factory to connect as user
system
tohost
.- Parameters
host (
str
) – The CrateDB cluster to connect to.password (
str
) – The password for thesystem
user.username (
str
) – An optional username to establish a connection. Defaults to"system"
.kwargs – Any additional arguments are passed as-is to
aiopg.connect()
.
- Returns
A partial function that, when called, will call
get_connection()
with the provided arguments and return its result.
- async crate.operator.cratedb.create_user(cursor, username, password)¶
Create user
username
and grant itALL PRIVILEGES
.
- async crate.operator.cratedb.get_cluster_admin_username(conn_factory, logger)¶
Returns the CrateDB admin username.
- async crate.operator.cratedb.get_cluster_settings(cursor)¶
Return information about the currently applied cluster settings from
sys.cluster.settings
.
- crate.operator.cratedb.get_connection(host, password, username='system', **kwargs)¶
Create a connection object to
host
as system user.- Parameters
host (
str
) – The CrateDB cluster to connect to.password (
str
) – The password for thesystem
user.username (
str
) – An optional username to establish a connection. Defaults to"system"
.kwargs – Any additional arguments are passed as-is to
aiopg.connect()
.
- Returns
An async context manager and coroutine wrapper around
aiopg.Connection
.
- async crate.operator.cratedb.get_healthiness(cursor)¶
Return the maximum severity of any table in the cluster from
sys.health
.
- async crate.operator.cratedb.get_number_of_nodes(cursor)¶
Return the number of nodes in the cluster from
sys.nodes
, which is the number of nodes that can see each other.
- async crate.operator.cratedb.is_cluster_healthy(conn_factory, expected_nodes, logger)¶
Check if a cluster is healthy.
The function checks for the cluster health using the sys.health table and the expected number of nodes in the cluster three times.
- Parameters
conn_factory – A callable that allows the operator to connect to the database. We regularly need to reconnect to ensure the connection wasn’t closed because it was opened to a CrateDB node that was shut down since the connection was opened.
expected_nodes (
int
) – The number of nodes that make up a healthy cluster.logger (
Logger
) –
- Return type
- async crate.operator.cratedb.reset_cluster_setting(conn_factory, logger, *, setting)¶
Reset the value of a cluster setting to its default value or to the value defined in the configuration file, if it was set on a node start-up.
- async crate.operator.cratedb.set_cluster_setting(conn_factory, logger, *, setting, value, mode='TRANSIENT')¶
Change a global cluster setting, see Cluster-wide settings, to a different value.
- Parameters
conn_factory – The connection factory to connect to CrateDB.
logger (
Logger
) – The logger on which we’re logging.setting (
str
) – The name of the setting that should be changed.mode (
str
) – The level of persistence. Settings that are set using the “TRANSIENT” mode will be discarded if the cluster is stopped or restarted. Using “PERSISTENT” mode will preserve the value of the setting if the cluster restarts, defaults to “TRANSIENT”.
- Return type
- async crate.operator.cratedb.update_user(cursor, username, password)¶
Update the users password.