Skip to content

Commit

Permalink
[DPE-4757] - Update shared library code, so that mongos waits for upg…
Browse files Browse the repository at this point in the history
…rade (#430)

## Context - What is this file?
This library code is used between `mongos`-charm and `mongodb`-charm
(when Charmed MongoDB is running as a config-server), to manage
connections between routers and config-servers. In this lib:
- Charmed mongos requests the user and shares its user with its
associated client application
- Charmed mongos manages its connection with the associated
config-server
- Charmed mongos starts its `mongos` service (as it is required to have
a config-server before starting)

This file is "owned" by Charmed MongoDB - so any direct changes to the
file **must** be made in this repo, before copying them over to Charmed
Mongos

## Issue
`mongos` does not wait for upgrades to finish before processing
integrations to the `config-server`. To prevent any broken states, we
should finish an upgrade before integrating to the config-server.

## Solution
Check if an upgrade is on-going. If it is prevent the relevant hook from
executing.

## What is next
Update the `mongos` charm to have the newest version of this lib to
ensure that `mongos` waits for upgrades to finish before
  • Loading branch information
MiaAltieri authored Aug 4, 2024
1 parent d3fcf8a commit 88482ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charm_internal_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9
10
18 changes: 17 additions & 1 deletion lib/charms/mongodb/v0/config_server_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 6

LIBPATCH = 7


class ClusterProvider(Object):
Expand Down Expand Up @@ -240,6 +241,13 @@ def __init__(
)

def _on_database_created(self, event) -> None:
if self.charm.upgrade_in_progress:
logger.warning(
"Processing client applications is not supported during an upgrade. The charm may be in a broken, unrecoverable state."
)
event.defer()
return

if not self.charm.unit.is_leader():
return

Expand Down Expand Up @@ -286,6 +294,7 @@ def _on_relation_changed(self, event) -> None:
return

self.charm.status.set_and_share_status(ActiveStatus())
self.charm.mongos_intialised = True

def _on_relation_broken(self, event: RelationBrokenEvent) -> None:
# Only relation_deparated events can check if scaling down
Expand Down Expand Up @@ -339,6 +348,13 @@ def pass_hook_checks(self, event):
event.defer()
return False

if self.charm.upgrade_in_progress:
logger.warning(
"Processing client applications is not supported during an upgrade. The charm may be in a broken, unrecoverable state."
)
event.defer()
return False

return True

def is_mongos_running(self) -> bool:
Expand Down

0 comments on commit 88482ca

Please sign in to comment.