# Copyright (C) 2019-present MongoDB, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the Server Side Public License, version 1,
# as published by MongoDB, Inc.
#
# This program 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
# Server Side Public License for more details.
#
# You should have received a copy of the Server Side Public License
# along with this program. If not, see
# <http://www.mongodb.com/licensing/server-side-public-license>.
#
# As a special exception, the copyright holders give permission to link the
# code of portions of this program with the OpenSSL library under certain
# conditions as described in each individual source file and distribute
# linked combinations including the program with the OpenSSL library. You
# must comply with the Server Side Public License in all respects for
# all of the code used other than as permitted herein. If you modify file(s)
# with this exception, you may extend this exception to your version of the
# file(s), but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version. If you delete this
# exception statement from all source files in the program, then also delete
# it in the license file.
#
global:
    cpp_namespace: "mongo"

server_parameters:
    enableFlowControl:
        description: 'Enable flow control'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<bool>'
        cpp_varname: 'gFlowControlEnabled'
        default: true
        redact: false

    flowControlTargetLagSeconds:
        description: 'Target maximum majority committed lag with flow control enabled'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<std::int32_t>'
        cpp_varname: 'gFlowControlTargetLagSeconds'
        default: 10
        validator: { gt: 0 }
        redact: false

    flowControlThresholdLagPercentage:
        description: 'Threshold percentage of target lag where flow control will become engaged'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<double>'
        cpp_varname: 'gFlowControlThresholdLagPercentage'
        default: 0.5
        validator: { gte: 0.0, lte: 1.0 }
        redact: false

    flowControlMaxSamples:
        description: 'The maximum number of samples the flow control algorithm will hold onto.'
        set_at: [ startup ]
        cpp_vartype: 'int'
        cpp_varname: 'gFlowControlMaxSamples'
        default: 1000000
        validator: { gt: 0 }
        redact: false

    flowControlSamplePeriod:
        description: 'How often flow control samples optimes. Smaller periods have higher resolution, but will suffer degredation sooner in the event of commit point lag.'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<int>'
        cpp_varname: 'gFlowControlSamplePeriod'
        default: 1000
        validator: { gt: 0 }
        redact: false

    flowControlMinTicketsPerSecond:
        description: 'The minimum number of tickets flow control will hand out per second. A smaller value will have better resolution on batch-write workloads, but may unintentionally delay system operations.'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<int>'
        cpp_varname: 'gFlowControlMinTicketsPerSecond'
        default: 100
        validator: { gte: 0 }
        redact: false

    flowControlDecayConstant:
        description: 'The rate at which flow control will throttle based on how lagged the commit point is in time relative to the flow control threshold.'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<double>'
        cpp_varname: 'gFlowControlDecayConstant'
        default: 0.5
        validator: { gt: 0.0, lt: 1.0 }
        redact: false

    flowControlFudgeFactor:
        description: 'When commit point lag is close to the threshold lag, the primary should track the sustainer rate, with some small penalty. This value represents that penalty. A value of 1.0 represents no penalty, a value close to 0.0 represents a large penalty. Reducing oscillations should keep this value close to 1.0.'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<double>'
        cpp_varname: 'gFlowControlFudgeFactor'
        default: 0.95
        validator: { gt: 0.0, lte: 1.0 }
        redact: false

    flowControlTicketAdderConstant:
        description: 'When the commit point lag is small, flow control will add at least this many tickets per second. This provides meaningful ticket increase when immediately recovering from stalling events.'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<int>'
        cpp_varname: 'gFlowControlTicketAdderConstant'
        default: 1000
        validator: { gt: 0 }
        redact: false

    flowControlTicketMultiplierConstant:
        description: 'When the commit point lag is small, flow control will increase its ticket allocation by this factor. This provides meaningful ticket increase in more general recovery scenarios.'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<double>'
        cpp_varname: 'gFlowControlTicketMultiplierConstant'
        default: 1.05
        validator: { gt: 1.0 }
        redact: false

    flowControlWarnThresholdSeconds:
        description: 'If flow control detects the replica set is lagged and the sustainer point is not moving, it will eventually log a warning. This value controls how much time the flow control is in this state before it logs. A value of zero will disable the warnings.'
        set_at: [ startup, runtime ]
        cpp_vartype: 'AtomicWord<int>'
        cpp_varname: 'gFlowControlWarnThresholdSeconds'
        default: 10
        validator: { gte: 0 }
        redact: false
