Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailBurdukov committed Apr 10, 2024
1 parent 6502fea commit 1f5a282
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
30 changes: 11 additions & 19 deletions ch_tools/chadmin/cli/data_store_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ch_tools.common.cli.formatting import print_response

CLICKHOUSE_PATH = "/var/lib/clickhouse"
CLICKHOUSE_STORE_PATH = CLICKHOUSE_PATH + "/store"


@group("data-store")
Expand Down Expand Up @@ -37,14 +38,7 @@ def data_store_group():
"--store-path",
"store_path",
default=CLICKHOUSE_PATH + "/store",
help="Set the store subdirectory path, `/var/lib/clickhouse/store` by default.",
)
@option(
"--show-directory-size",
"show_directory_size",
is_flag=True,
default=False,
help="Flag to show metadata size.",
help="Set the store subdirectory path.",
)
@option(
"--show-all-metadata",
Expand All @@ -54,23 +48,24 @@ def data_store_group():
help="Flag to only orphaned metadata.",
)
def clean_orphaned_tables_command(
ctx, column, remove, store_path, show_directory_size, show_only_orphaned_metadata
ctx, column, remove, store_path, show_only_orphaned_metadata
):
results = []
for prefix in os.listdir(store_path):
path = store_path + "/" + prefix
path_result = process_path(path, prefix, column, remove, show_directory_size)
path_result = process_path(path, prefix, column, remove)
if show_only_orphaned_metadata and path_result["status"] != "not_used":
continue
if not show_directory_size:
del path_result["size"]
results.append(path_result)

print_response(ctx, results, default_format="table")


def process_path(
path: str, prefix: str, column: str, remove: bool, count_directory_size: bool
path: str,
prefix: str,
column: str,
remove: bool,
) -> dict:
logging.info("Processing path %s with prefix %s:", path, prefix)

Expand All @@ -81,12 +76,9 @@ def process_path(
"removed": False,
}

if count_directory_size:
size = du(path)
logging.info("Size of path %s: %s", path, size)
result["size"] = size
else:
result["size"] = 0
size = du(path)
logging.info("Size of path %s: %s", path, size)
result["size"] = size

file = prefix_exists_in_metadata(prefix)

Expand Down
2 changes: 2 additions & 0 deletions tests/features/data_storage_group.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Feature: chadmin data-store commands
"""
- path: /var/lib/clickhouse/disks/object_storage/store/123
status: not_used
size: 8.0K
removed: false
"""
When we execute command on clickhouse01
Expand All @@ -30,5 +31,6 @@ Feature: chadmin data-store commands
"""
- path: /var/lib/clickhouse/disks/object_storage/store/123
status: not_used
size: 8.0K
removed: true
"""

0 comments on commit 1f5a282

Please sign in to comment.