Files
scylladb/dist/common/scripts/scylla_fstrim
Yaniv Michael Kaul af8eaa9ea5 scripts: fixes flagged by CodeQL/PyLens
Unused imports, unused variables and such.
Initially, there were no functional changes, just to get rid of some standard CodeQL warnings.

I've then broken the CI, as apparently there's a install time(!?) Python script creation for the sole purpose of product
naming. I changed it - we have it in etcdir, as SCYLLA-PRODUCT-FILE.
So added (copied from a different script) a get_product() helper function in scylla_util.py and used it instead.

While at it, also fixed the too broad import from scylla_util, which 'forced' me to also fix other specific imports (such as shutil).

Improvement - no need to backport.
Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>

Closes scylladb/scylladb#27883
2026-01-09 15:13:12 +02:00

47 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2017-present ScyllaDB
#
#
# SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
import os
import argparse
import subprocess
from scylla_util import parse_scylla_dirs_with_default
def find_mount_point(path):
path = os.path.abspath(path)
while not os.path.ismount(path):
path = os.path.dirname(path)
return path
def main():
parser = argparse.ArgumentParser(description='Run fstrim on Scylla data partitions.')
parser.add_argument('-c', '--config', dest='config', action='store',
default='/etc/scylla/scylla.yaml',
help='path to scylla.yaml')
args = parser.parse_args()
cfg = parse_scylla_dirs_with_default(conf=args.config)
mountpoints = set()
for d in cfg['data_file_directories']:
mountpoints.add(find_mount_point(d))
mountpoints.add(find_mount_point(cfg['commitlog_directory']))
mountpoints.add(find_mount_point(cfg['schema_commitlog_directory']))
# workaround of #2649
subprocess.call(["/opt/scylladb/scripts/scylla-blocktune", "--set-nomerges", "1"])
for d in mountpoints:
print("Running fstrim on {} ...".format(d))
res = subprocess.call(["fstrim", d])
if res != 0:
print("{} doesn't support TRIM.".format(d))
subprocess.call(["/opt/scylladb/scripts/scylla-blocktune", "--set-nomerges", "2"])
if __name__ == "__main__":
main()