ScyllaDB 配置命令参考:scylla.yaml 参数如何映射为命令行选项
ScyllaDB 配置命令参考scylla.yaml 参数如何映射为命令行选项【免费下载链接】scylladbNoSQL data store using the Seastar framework, compatible with Apache Cassandra and Amazon DynamoDB项目地址: https://gitcode.com/GitHub_Trending/sc/scylladb本篇基于官方文档 docs/getting-started/config-commands.rst讲解 ScyllaDB 的配置命令体系如何用scylla --help查看全部可配置项以及scylla.yaml中的 YAML 参数如cluster_name如何按固定规则转换为等价的命令行参数如scylla --cluster-name Test Cluster。读完本文你将掌握YAML 参数 → 命令行选项的映射规则、命令输出的各个组成部分以及从 db/config.hh、utils/config_file.hh 源码层面理解这套机制的底层原理。一、查看 ScyllaDB 全部配置命令在终端执行以下命令即可列出 ScyllaDB 支持的全部配置命令scylla --help该命令无需 sudo 或 root 权限只要你有权限在当前目录执行即可。输出内容包含两部分ScyllaDB 自身的选项scylla optionsSeastar 框架的选项——在输出中列为Core Options。因为 ScyllaDB 构建在 Seastar 之上反应堆reactor、内存、I/O 等底层行为都由 Seastar 控制这些参数同样可以从命令行传入。文档中给出的一个不完整的输出示例如下scylla version 4.2.3-0.20210104.24346215c2 with build-id 0c8faf8bb8a3a0eda9337aad98ed3a6d814a4fa9 starting ... command used: scylla --help parsed command line options: [help] scylla options: -h [ --help ] show help message --version print version number and exit --options-file arg configuration file (i.e. SCYLLA_HOME/conf/scylla.yaml) --memtable-flush-static-shares arg If set to higher than 0, ignore the controllers output and set the memtable shares statically. Do not set this unless you know what you are doing and suspect a problem in the controller. This option will be retired when the controller reaches more maturity --compaction-static-shares arg If set to higher than 0, ignore the controllers output and set the compaction shares statically. Do not set this unless you know what you are doing and suspect a problem in the controller. This option will be retired when the controller reaches more maturity完整列表需要在终端中实际运行该命令查看。这段输出的来源可以从源码确认main.cc 中的print_starting_message()负责打印Scylla version {} with build-id {} starting ...、command used: ...和parsed command line options: [...]三行诊断信息——它与示例输出逐行对应。而--options-file的注册见 main.ccinit(options-file, bpo::valuesstring(), configuration file (i.e. SCYLLA_HOME/conf/scylla.yaml));二、核心规则scylla.yaml 参数 → 命令行参数这是本文档最重要的实操结论ScyllaDB 的大量命令行命令是从scylla.yaml的配置参数派生出来的。以仓库自带的配置文件 conf/scylla.yaml 为例其中包含如下参数cluster_name: Test Cluster要在命令行发送同一个配置执行scylla --cluster-name Test Cluster通用转换规则四步法从scylla.yaml文件中取一个配置参数在其前面加上scylla --前缀把参数名中的每一个下划线_替换为连字符-在终端中运行该命令。更多示例均以 conf/scylla.yaml 中实际出现的参数为参照scylla.yaml 参数等价的命令行形式cluster_name: Test Clusterscylla --cluster-name Test Clusternum_tokens: 256scylla --num-tokens 256commitlog_sync: periodicscylla --commitlog-sync periodiccommitlog_segment_size_in_mb: 32scylla --commitlog-segment-size-in-mb 32concurrent_reads: 32scylla --concurrent-reads 32注意官方文档明确提醒——只应使用官方支持的配置项。scylla.yaml分为受支持的参数与不受支持的参数保留或为向后兼容而留两段Scylla 只读取使用第一段。三、源码剖析参数如何变成命令行选项文档中的映射规则在源码中由一条清晰的调用链实现理解它能帮助你在排查配置问题时快速定位。3.1 每个 YAML 参数都是一个named_valueTdb/config.hh 中定义了db::config类继承自utils::config_file每个可配置项都声明为一个类型化的named_valuenamed_valuesstring cluster_name; named_valuesstring listen_address; named_valueuint32_t memtable_total_space_in_mb; named_valuesstring commitlog_sync; named_valueuint32_t commitlog_segment_size_in_mb; named_valueuint32_t concurrent_reads; // ... 数百个配置项这正是YAML 参数与命令行选项一一对应的根源同一个named_value既对应scylla.yaml里的一个键也对应一个命令行长选项键名按下划线转连字符的规则生成命令行名。3.2 选项注册append_all与add_options在 main.cc 的scylla_main()中所有配置项被批量注册到命令行解析器boost::program_optionsauto cfg make_lw_shareddb::config(ext); auto init app.get_options_description().add_options(); init(version, bpo::bool_switch(), print version number and exit); ... init(options-file, bpo::valuesstring(), configuration file (i.e. SCYLLA_HOME/conf/scylla.yaml)); configurable::append_all(*cfg, init); // 注册所有 Seastar 侧可配置项 cfg-add_options(init); // 注册 scylla.yaml 派生的所有选项这就是scylla --help能列出全部scylla --xxx选项的直接原因。3.3 选项的生命周期状态只有 Used 才能上命令行utils/config_file.hh 中每个配置项带有一个value_status状态枚举它解释了为什么有些 YAML 参数在--help中看不到Used有效且会改变 Scylla 行为的选项。只有 Used 选项会被加入命令行选项即可以出现在scylla --xxx形式中Unused继承自 Cassandra 或尚未实现的选项。配置文件里仍可接受但不再作为命令行选项暴露以降低噪音Invalid继承但不打算实现的选项启动时看到会打印告警保留只是为了平滑迁移Deprecated已弃用的选项。在配置文件或命令行中指定时会被解析并打印弃用告警。在 main.cc 中可以看到弃用选项被单独放进 Deprecated options - ignored 分组启动时若发现使用会打印xxx option ignored (deprecated)告警。此外每个配置项还有liveness可更新性属性LiveUpdate值变化时可热更新配合 SIGHUP 重新加载MustRestart修改后必须重启节点。以及config_source来源追踪可区分值来自SettingsFilescylla.yaml、CommandLine命令行、CQL、Internal还是API——这在排查到底是哪里设置了这个值时非常有用。3.4 配置文件读取与优先级启动时 main.cc 的read_config()决定读取哪个 YAML 文件if (opts.contains(options-file)) { file opts[options-file].assstring(); } else { file db::config::get_conf_sub(scylla.yaml).string(); }即若指定了--options-file则读取指定文件否则按 db/config.hh 中get_conf_dir()的规则依次取$SCYLLA_CONF、$SCYLLA_HOME/conf或当前目录下的conf。读取过程中对每个选项的解析结果会通过回调按value_status打印 warn/error 日志无效或弃用项会给出提示。命令行与配置文件的取值关系从源码结构看两者写入的是同一批named_value命令行值在选项解析阶段写入、YAML 值在read_config阶段写入实际优先级以当前版本代码路径为准建议修改后通过scylla --version启动日志或system_config虚拟表核对生效值。3.5 SIGHUP 热重载修改 YAML 后无需改命令行main.cc 中的sighup_handler处理SIGHUP信号收到信号后在 shard 0 上加锁lock_for_config_update()重新执行read_config()再broadcast_to_all_shards()将新值广播到所有 shard。这意味着命令行参数只在进程启动时解析一次而scylla.yaml中的 LiveUpdate 类参数可以在运行中通过kill -HUP pid触发重新加载。因此YAML 参数 → 命令行参数的等价映射主要用于启动时配置例如用 systemd/容器方式拉起节点、不想改磁盘上 YAML 时临时覆盖参数长期运行态的调优更常通过修改 YAML SIGHUP 完成前提是该项支持 LiveUpdate。3.6 启动时的配置校验命令行与 YAML 传入的值最终会被统一校验典型检查包括见 main.cc--developer-mode对应 YAMLdeveloper_mode未开启时NOFILE rlimit 低于 10000 会拒绝启动推荐 200000每 shard 内存低于 1 GiB 会报错提示调整--memory或--smp这两者正是 Seastar Core Options 一族的选项印证了第一部分Seastar 命令的说法未配置--io-properties/--io-properties-file时提示 I/O 调度器未正确配置并建议运行scylla_io_setup。四、实操要点小结查全量参数scylla --help注意区分 ScyllaDB 选项与 Seastar Core OptionsYAML 转命令行scylla.yaml键名 → 加scylla --前缀 → 下划线换成连字符如cluster_name→scylla --cluster-name Test Cluster指定配置文件位置scylla --options-file SCYLLA_HOME/conf/scylla.yaml缺省按$SCYLLA_CONF/$SCYLLA_HOME/conf/conf顺序查找只使用官方支持参数scylla.yaml后半段的不支持参数仅为兼容保留不应依赖看到 Deprecated 告警应尽快从配置中移除启动后核对启动日志会打印command used与parsed command line options可用于确认参数是否按预期传入。适用前提本文所有行为描述以当前仓库源码main.cc、db/config.hh、utils/config_file.hh、conf/scylla.yaml为准不同 ScyllaDB 版本间部分选项的增删例如--memtable-flush-static-shares、--compaction-static-shares这类待退役选项可能不同请以对应版本的scylla --help实际输出为准。【免费下载链接】scylladbNoSQL data store using the Seastar framework, compatible with Apache Cassandra and Amazon DynamoDB项目地址: https://gitcode.com/GitHub_Trending/sc/scylladb创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考