# Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
#  This source code is licensed under both the GPLv2 (found in the
#  COPYING file in the root directory) and Apache 2.0 License
#  (found in the LICENSE.Apache file in the root directory).
#
# This ini file is very similar to the Rocksdb ini file in terms of syntax.
# (refer rocksdb/examples/rocksdb_option_file_example.ini)
# It is made up of multiple sections and each section is made up of multiple
# key-value pairs. Each section must have a name. The recognized sections are
# Rule, Suggestion, Condition followed by their name in "" that acts as an
# identifier. There should be at least one Rule section in the file.
#
# Each rule must be associated with at least one condition and one suggestion.
# If a Rule is associated with multiple Conditions, then all the conditions
# must be triggered in order for the Rule to be triggered.
# The suggestions don't have any ordering amongst them as of now.
#
# A Condition must be associated to a data source specified by the parameter
# 'source' and this must be the first parameter specified for the Condition.
#
# A suggestion is an advised change to a database or column_family option to
# improve the performance of the database in some way. Every suggestion is
# is associated with one or more Rules.

[Rule "stall-too-many-memtables"]
suggestions=inc-bg-flush:inc-write-buffer
conditions=stall-too-many-memtables

[Condition "stall-too-many-memtables"]
source=LOG
regex=Stopping writes because we have \d+ immutable memtables \(waiting for flush\), max_write_buffer_number is set to \d+
scope=column_family

[Rule "stall-too-many-L0"]
suggestions=inc-max-subcompactions:inc-max-bg-compactions:inc-write-buffer-size:dec-max-bytes-for-level-base:inc-l0-slowdown-writes-trigger
conditions=stall-too-many-L0

[Condition "stall-too-many-L0"]
source=LOG
regex=Stalling writes because we have \d+ level-0 files
scope=column_family

[Rule "stop-too-many-L0"]
suggestions=inc-max-bg-compactions:inc-write-buffer-size:inc-l0-stop-writes-trigger
conditions=stop-too-many-L0

[Condition "stop-too-many-L0"]
source=LOG
regex=Stopping writes because we have \d+ level-0 files
scope=column_family

[Rule "stall-too-many-compaction-bytes"]
suggestions=inc-max-bg-compactions:inc-write-buffer-size:inc-hard-pending-compaction-bytes-limit:inc-soft-pending-compaction-bytes-limit
conditions=stall-too-many-compaction-bytes

[Condition "stall-too-many-compaction-bytes"]
source=LOG
regex=Stalling writes because of estimated pending compaction bytes \d+
scope=column_family

[Suggestion "inc-bg-flush"]
option=DBOptions.max_background_flushes
action=increase

[Suggestion "inc-write-buffer"]
option=CFOptions.max_write_buffer_number
action=increase

[Suggestion "inc-max-subcompactions"]
option=DBOptions.max_subcompactions
action=increase

[Suggestion "inc-max-bg-compactions"]
option=DBOptions.max_background_compactions
action=increase

[Suggestion "inc-write-buffer-size"]
option=CFOptions.write_buffer_size
action=increase

[Suggestion "dec-max-bytes-for-level-base"]
option=CFOptions.max_bytes_for_level_base
action=decrease

[Suggestion "inc-l0-slowdown-writes-trigger"]
option=CFOptions.level0_slowdown_writes_trigger
action=increase

[Suggestion "inc-l0-stop-writes-trigger"]
option=CFOptions.level0_stop_writes_trigger
action=increase

[Suggestion "inc-hard-pending-compaction-bytes-limit"]
option=CFOptions.hard_pending_compaction_bytes_limit
action=increase

[Suggestion "inc-soft-pending-compaction-bytes-limit"]
option=CFOptions.soft_pending_compaction_bytes_limit
action=increase

[Rule "level0-level1-ratio"]
conditions=level0-level1-ratio
suggestions=l0-l1-ratio-health-check

[Condition "level0-level1-ratio"]
source=OPTIONS
options=CFOptions.level0_file_num_compaction_trigger:CFOptions.write_buffer_size:CFOptions.max_bytes_for_level_base
evaluate=int(options[0])*int(options[1])-int(options[2])<(-251659456)  # should evaluate to a boolean

[Suggestion "l0-l1-ratio-health-check"]
description='modify options such that (level0_file_num_compaction_trigger * write_buffer_size - max_bytes_for_level_base < 5) is satisfied'
