-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Issue When sharding components (config-server + shards) are deployed and immediately related/integrated, the model hangs [see chat here](https://chat.charmhub.io/charmhub/pl/5baegxny5jro5md71gew8am5dy) ## Reason The model hangs because the relation hooks execute before both/either leader-elected + config changed, this results in `pass_hook_checks` not deferring the event, meaning that the event doesn't execute its necessary code and the model forever hangs waiting for an event to be re-emitted that will never be re-emitted ## Solution Update the order for checks in `pass_hook_checks` so that there is **always** a deferral if the database has not been initialised. ## Extra Update this scheme throughout the code base ## Tests An extra test suite was added for this case
- Loading branch information
1 parent
f92c12f
commit 678f839
Showing
6 changed files
with
175 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
tests/integration/sharding_tests/test_sharding_race_conds.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2023 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
import pytest | ||
from pytest_operator.plugin import OpsTest | ||
|
||
from .helpers import generate_mongodb_client, has_correct_shards | ||
|
||
SHARD_ONE_APP_NAME = "shard-one" | ||
SHARD_TWO_APP_NAME = "shard-two" | ||
SHARD_THREE_APP_NAME = "shard-three" | ||
SHARD_APPS = [SHARD_ONE_APP_NAME, SHARD_TWO_APP_NAME] | ||
CONFIG_SERVER_APP_NAME = "config-server-one" | ||
SHARD_REL_NAME = "sharding" | ||
CONFIG_SERVER_REL_NAME = "config-server" | ||
MONGODB_KEYFILE_PATH = "/var/snap/charmed-mongodb/current/etc/mongod/keyFile" | ||
|
||
TIMEOUT = 60 * 10 | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
async def test_build_and_deploy(ops_test: OpsTest) -> None: | ||
"""Build and deploy a sharded cluster.""" | ||
my_charm = await ops_test.build_charm(".") | ||
await ops_test.model.deploy( | ||
my_charm, | ||
num_units=2, | ||
config={"role": "config-server"}, | ||
application_name=CONFIG_SERVER_APP_NAME, | ||
) | ||
await ops_test.model.deploy( | ||
my_charm, num_units=2, config={"role": "shard"}, application_name=SHARD_ONE_APP_NAME | ||
) | ||
await ops_test.model.deploy( | ||
my_charm, num_units=2, config={"role": "shard"}, application_name=SHARD_TWO_APP_NAME | ||
) | ||
await ops_test.model.deploy( | ||
my_charm, num_units=2, config={"role": "shard"}, application_name=SHARD_THREE_APP_NAME | ||
) | ||
|
||
|
||
@pytest.mark.abort_on_fail | ||
async def test_immediate_relate(ops_test: OpsTest) -> None: | ||
"""Tests the immediate integration of cluster components works without error.""" | ||
await ops_test.model.integrate( | ||
f"{SHARD_ONE_APP_NAME}:{SHARD_REL_NAME}", | ||
f"{CONFIG_SERVER_APP_NAME}:{CONFIG_SERVER_REL_NAME}", | ||
) | ||
await ops_test.model.integrate( | ||
f"{SHARD_TWO_APP_NAME}:{SHARD_REL_NAME}", | ||
f"{CONFIG_SERVER_APP_NAME}:{CONFIG_SERVER_REL_NAME}", | ||
) | ||
await ops_test.model.integrate( | ||
f"{SHARD_THREE_APP_NAME}:{SHARD_REL_NAME}", | ||
f"{CONFIG_SERVER_APP_NAME}:{CONFIG_SERVER_REL_NAME}", | ||
) | ||
|
||
await ops_test.model.wait_for_idle( | ||
apps=[ | ||
CONFIG_SERVER_APP_NAME, | ||
SHARD_ONE_APP_NAME, | ||
SHARD_TWO_APP_NAME, | ||
SHARD_THREE_APP_NAME, | ||
], | ||
idle_period=20, | ||
status="active", | ||
timeout=TIMEOUT, | ||
raise_on_error=False, | ||
) | ||
|
||
mongos_client = await generate_mongodb_client( | ||
ops_test, app_name=CONFIG_SERVER_APP_NAME, mongos=True | ||
) | ||
|
||
# verify sharded cluster config | ||
assert has_correct_shards( | ||
mongos_client, | ||
expected_shards=[SHARD_ONE_APP_NAME, SHARD_TWO_APP_NAME, SHARD_THREE_APP_NAME], | ||
), "Config server did not process config properly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters