diff --git a/lib/charms/opensearch/v0/opensearch_base_charm.py b/lib/charms/opensearch/v0/opensearch_base_charm.py index b07a17094..28e3b219f 100644 --- a/lib/charms/opensearch/v0/opensearch_base_charm.py +++ b/lib/charms/opensearch/v0/opensearch_base_charm.py @@ -1042,10 +1042,18 @@ def _stop_opensearch(self, *, restart=False) -> None: self.status.set(WaitingStatus(ServiceIsStopping)) if self.opensearch.is_node_up(): - # TODO: we should probably NOT have any exclusion on restart - # https://chat.canonical.com/canonical/pl/bgndmrfxr7fbpgmwpdk3hin93c - # 1. Add current node to the voting + alloc exclusions - self.opensearch_exclusions.add_current() + try: + nodes = self._get_nodes(True) + # do not add exclusions if it's the last unit to stop + # otherwise cluster manager election will be blocked when starting up again + # and re-using storage + if len(nodes) > 1: + # TODO: we should probably NOT have any exclusion on restart + # https://chat.canonical.com/canonical/pl/bgndmrfxr7fbpgmwpdk3hin93c + # 1. Add current node to the voting + alloc exclusions + self.opensearch_exclusions.add_current() + except OpenSearchHttpError: + logger.debug("Failed to get online nodes, voting and alloc exclusions not added") # TODO: should block until all shards move addressed in PR DPE-2234