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).

Parameters

logger (Logger) –

Return type

Tuple[bool, Optional[str]]

crate.operator.cratedb.connection_factory(host, password, username='system', **kwargs)

Create a connection factory to connect as user system to host.

Parameters
  • host (str) – The CrateDB cluster to connect to.

  • password (str) – The password for the system 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 it ALL PRIVILEGES.

Parameters
  • cursor (Cursor) – A database cursor object to the CrateDB cluster where the user should be added.

  • username (str) – The username for the new user.

  • password (str) – The password for the new user.

Return type

None

async crate.operator.cratedb.get_cluster_admin_username(conn_factory, logger)

Returns the CrateDB admin username.

Parameters

cursor – A database cursor to a current and open database connection.

Return type

Optional[str]

Returns

Either a string that represents the CrateDB admin username or None

async crate.operator.cratedb.get_cluster_settings(cursor)

Return information about the currently applied cluster settings from sys.cluster.settings.

Parameters

cursor (Cursor) – A database cursor to a current and open database connection.

Return type

Dict

Returns

A Dict with all currently applied 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 the system 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.

Parameters

cursor (Cursor) – A database cursor to a current and open database connection.

Return type

int

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.

Parameters

cursor (Cursor) – A database cursor to a current and open database connection.

Return type

int

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

bool

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.

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 reset.

Return type

None

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.

  • value (Union[str, int]) – The new value of the setting.

  • 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

None

async crate.operator.cratedb.update_user(cursor, username, password)

Update the users password.

Parameters
  • cursor (Cursor) – A database cursor object to the CrateDB cluster where the user should be updated.

  • username (str) – The username of the user that should be updated.

  • password (str) – The new password.

Return type

None