You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#86
## Context
These are the situations the charm should handle without raising an
uncaught exception:
- `mysqlrouter --bootstrap` fails because server does not have quorum
- `mysqlrouter --bootstrap` fails because server is unreachable (error
code
[2003](https://dev.mysql.com/doc/mysql-errors/8.0/en/client-error-reference.html#error_cr_conn_host_error))
- mysqlsh `shell.connect()` fails because server is unreachable (error
code
[2003](https://dev.mysql.com/doc/mysql-errors/8.0/en/client-error-reference.html#error_cr_conn_host_error))
(mysqlsh commands seem to not fail even if server does not have quorum)
## Solution
Catch exceptions in the aforementioned situations & set waiting status.
Retry connections on the next Juju event
## Alternatives considered
We decided not to retry within the Juju event so that
- (primary reason) the user is not blocked from removing the unit(s)
- if the endpoint from mysql server changes, we need to get a new event
to get the updated endpoint
A retry within the Juju event with a short timeout was considered.
However, during initial deployment ~15 events are currently fired (so a
1 min timeout could block the charm for 15 minutes). It would be
possible to mitigate that by storing information about the last
retry—but the complexity was not worth it.
Discussion about Juju limitation that we may not get another event until
update status:
https://matrix.to/#/!xdClnUGkurzjxqiQcN:ubuntu.com/$_SXnGJWUQCeFGu9vpBxD5GJ5hgMMAHchOmWBPiqjDFY?via=ubuntu.com&via=matrix.org&via=cutefunny.art
## Implementation/refactoring
- Catch mysql shell `DBError` exceptions, serialize them to JSON, and
raise corresponding exception in charm code. This was done to move
complexity (i.e. exception handling) from mysqlsh python code to charm
code
- Move mysqlsh python code from strings to Jinja templates (for better
syntax highlighting/analysis & code review/diffs)
- Use JSON files to transfer data from mysqlsh python code to charm code
instead of printing & parsing stdout
logger.debug(f"Getting MySQL Router user for {unit_name=}")
138
-
rows=json.loads(
139
-
self._run_commands(
140
-
[
141
-
f"result = session.run_sql(\"SELECT USER, ATTRIBUTE->>'$.router_id' FROM INFORMATION_SCHEMA.USER_ATTRIBUTES WHERE ATTRIBUTE->'$.created_by_user'='{self.username}' AND ATTRIBUTE->'$.created_by_juju_unit'='{unit_name}'\")",
"SELECT USER, ATTRIBUTE->>'$.router_id' FROM INFORMATION_SCHEMA.USER_ATTRIBUTES WHERE ATTRIBUTE->'$.created_by_user'='{{ username }}' AND ATTRIBUTE->'$.created_by_juju_unit'='{{ unit_name }}'"
5
+
)
6
+
rows = result.fetch_all()
7
+
# mysqlsh objects are weird—they quack (i.e. duck typing) like standard Python objects (e.g. list,
8
+
# dict), but do not serialize to JSON correctly.
9
+
# Cast to str & load from JSON str before serializing
0 commit comments