Files
scylladb/dist/common/scripts/scylla_fstrim
Amos Kong e2eb754d03 use parse_scylla_dirs_with_default to get scylla directories
Use default data_file_directories/commitlog_directory if it's not assigned
in scylla.yaml

Signed-off-by: Amos Kong <amos@scylladb.com>
2019-11-28 15:48:14 +08:00

61 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2017 ScyllaDB
#
#
# This file is part of Scylla.
#
# Scylla is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Scylla is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scylla. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import yaml
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']))
# 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()