Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Nov 30, 2023
1 parent 3f4b95f commit 794d9fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 3 additions & 4 deletions lib/charms/mongodb/v0/config_server_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
KEY_FILE = "keyFile"
HOSTS_KEY = "host"
CONFIG_SERVER_DB_KEY = "config-server-db"
MONGOS_SOCKET_URI_FMT = "%2Fvar%2Fsnap%2Fcharmed-mongodb%2Fcommon%2Fvar%2Fmongodb-27018.sock"

# The unique Charmhub library identifier, never change it
LIBID = "58ad1ccca4974932ba22b97781b9b2a0"
Expand Down Expand Up @@ -146,11 +147,10 @@ def _on_relation_changed(self, event) -> None:
)

# avoid restarting mongos when possible
if not updated_keyfile and not updated_config and self.charm.monogs_initialised:
if not updated_keyfile and not updated_config and self.is_mongos_running():
return

# mongos is not available until it is using new secrets
del self.charm.unit_peer_data["mongos_initialised"]
logger.info("Restarting mongos with new secrets")
self.charm.unit.status = MaintenanceStatus("starting mongos")
self.charm.restart_mongos_service()
Expand All @@ -163,12 +163,11 @@ def _on_relation_changed(self, event) -> None:
return

# TODO: Follow up PR. Add a user for mongos once it has been started
self.charm.unit_peer_data["mongos_initialised"] = json.dumps(True)
self.charm.unit.status = ActiveStatus()

def is_mongos_running(self) -> bool:
"""Returns true if mongos service is running."""
with MongosConnection(None, "mongodb://localhost:27018") as mongo:
with MongosConnection(None, f"mongodb://{MONGOS_SOCKET_URI_FMT}") as mongo:
return mongo.is_ready

def update_config_server_db(self, config_server_db) -> bool:
Expand Down
12 changes: 9 additions & 3 deletions lib/charms/mongodb/v1/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,21 @@ def get_mongos_args(
Returns:
A string representing the arguments to be passed to mongos.
"""
# suborinate charm which provides its own config_server_db, should only use unix domain socket
binding_ips = (
f"--bind_ip {MONGODB_COMMON_DIR}/var/mongodb-27018.sock"
if config_server_db
else "--bind_ip_all"
)

# mongos running on the config server communicates through localhost
# use constant for port
config_server_db = config_server_db or f"{config.replset}/localhost:27017"
config_server_db = config_server_db or f"{config.replset}/localhost:{Config.MONGODB_PORT}"

full_conf_dir = f"{MONGODB_SNAP_DATA_DIR}{CONF_DIR}" if snap_install else CONF_DIR
cmd = [
# mongos on config server side should run on 0.0.0.0 so it can be accessed by other units
# in the sharded cluster
"--bind_ip_all",
binding_ips,
f"--configdb {config_server_db}",
# config server is already using 27017
f"--port {Config.MONGOS_PORT}",
Expand Down

0 comments on commit 794d9fe

Please sign in to comment.