Skip to content

Commit

Permalink
Exclude opensearch lock index from restore (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical authored Apr 17, 2024
1 parent 75db1e9 commit 0f10e56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/charms/opensearch/v0/opensearch_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(...):
OpenSearchHttpError,
OpenSearchNotFullyReadyError,
)
from charms.opensearch.v0.opensearch_locking import OpenSearchNodeLock
from charms.opensearch.v0.opensearch_plugins import OpenSearchBackupPlugin, PluginState
from ops.charm import ActionEvent
from ops.framework import EventBase, Object
Expand All @@ -92,7 +93,11 @@ def __init__(...):

S3_REPO_BASE_PATH = "/"

INDICES_TO_EXCLUDE_AT_RESTORE = {".opendistro_security", ".opensearch-observability"}
INDICES_TO_EXCLUDE_AT_RESTORE = {
".opendistro_security",
".opensearch-observability",
OpenSearchNodeLock.OPENSEARCH_INDEX,
}

REPO_NOT_CREATED_ERR = "repository type [s3] does not exist"
REPO_NOT_ACCESS_ERR = f"[{S3_REPOSITORY}] path [{S3_REPO_BASE_PATH}] is not accessible"
Expand Down
10 changes: 5 additions & 5 deletions lib/charms/opensearch/v0/opensearch_locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class OpenSearchNodeLock(ops.Object):
Uses OpenSearch document for lock. Falls back to peer databag if no units online
"""

_OPENSEARCH_INDEX = ".charm_node_lock"
OPENSEARCH_INDEX = ".charm_node_lock"

def __init__(self, charm: "opensearch_base_charm.OpenSearchBaseCharm"):
super().__init__(charm, "opensearch-node-lock")
Expand All @@ -198,7 +198,7 @@ def _unit_with_lock(self, host) -> str | None:
try:
document_data = self._opensearch.request(
"GET",
endpoint=f"/{self._OPENSEARCH_INDEX}/_source/0",
endpoint=f"/{self.OPENSEARCH_INDEX}/_source/0",
host=host,
alt_hosts=self._charm.alt_hosts,
retries=3,
Expand Down Expand Up @@ -242,7 +242,7 @@ def acquired(self) -> bool: # noqa: C901
try:
self._opensearch.request(
"PUT",
endpoint=f"/{self._OPENSEARCH_INDEX}",
endpoint=f"/{self.OPENSEARCH_INDEX}",
host=host,
alt_hosts=alt_hosts,
retries=3,
Expand All @@ -263,7 +263,7 @@ def acquired(self) -> bool: # noqa: C901
try:
self._opensearch.request(
"PUT",
endpoint=f"/{self._OPENSEARCH_INDEX}/_create/0?refresh=true",
endpoint=f"/{self.OPENSEARCH_INDEX}/_create/0?refresh=true",
host=host,
alt_hosts=alt_hosts,
retries=3,
Expand Down Expand Up @@ -330,7 +330,7 @@ def release(self):
try:
self._opensearch.request(
"DELETE",
endpoint=f"/{self._OPENSEARCH_INDEX}/_doc/0?refresh=true",
endpoint=f"/{self.OPENSEARCH_INDEX}/_doc/0?refresh=true",
host=host,
alt_hosts=alt_hosts,
retries=3,
Expand Down

0 comments on commit 0f10e56

Please sign in to comment.