Skip to content

Commit

Permalink
Handle not empty error in zk delete
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailBurdukov committed Feb 14, 2024
1 parent 74d66f8 commit b958127
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ch_tools/chadmin/internal/zookeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from math import sqrt

from kazoo.client import KazooClient
from kazoo.exceptions import NoNodeError
from kazoo.exceptions import NoNodeError, NotEmptyError

from ch_tools.chadmin.cli import get_clickhouse_config, get_macros
from ch_tools.chadmin.internal.utils import chunked
Expand Down Expand Up @@ -162,11 +162,18 @@ def _delete_nodes_transaction(zk, to_delete_in_trasaction):
to_delete_in_trasaction,
)
for node in to_delete_in_trasaction:
try:
zk.delete(node, recursive=True)
except NoNodeError:
# Someone deleted node before us. Do nothing.
print("Node {node} is already absent, skipped".format(node=node))
successful_delete = False
while not successful_delete:
try:
zk.delete(node, recursive=True)
successful_delete = True
except NoNodeError:
# Someone deleted node before us. Do nothing.
print("Node {node} is already absent, skipped".format(node=node))
successful_delete = True
except NotEmptyError:
# Someone created a node while we deleting. Restart the operation.
pass


def _remove_subpaths(paths):
Expand Down Expand Up @@ -294,7 +301,6 @@ def _set_replicas_is_lost(zk, table_paths, nodes):
Set flag <path>/replicas/<replica_name>/is_lost to 1
"""
for path in table_paths:

replica_path = os.path.join(path, "replicas")
if not zk.exists(replica_path):
continue
Expand Down

0 comments on commit b958127

Please sign in to comment.