architecture/design/auto_flags.md
AutoFlags are gFlags with two hard-coded values: Initial and Target (instead of the regular gFlag Default). AutoFlags have two states: promoted and not-promoted. An AutoFlag is set to its Initial value in the not-promoted state and to its Target value in the promoted state.
auto_flags.json file is created in the bin directory. This file has the list of all AutoFlags in the yb-master and yb-tserver processes.A Workflow is the series of activities that are necessary to complete a task (ex: user issuing a DML, tablet split, load balancing). They can be simple and confined to a function block or involve coordination between multiple universes. Workflows that add or modify the format of data that is sent over the wire to another process or is persisted on disk require special care. The consumer of the data and its persistence determines when the new workflow can be safely enabled after an upgrade, and whether it is safe to perform rollbacks or downgrades after they are enabled. AutoFlags are required to safely and automatically enable such workflows.
For example, yb_enable_expression_pushdown requires all yb-tservers to run a version which can understand and respond to the new request type. So, it can only be enabled after all yb-tservers in the universe have upgraded to a supported code version. Using a regular gFlag, we have to set the default value to false so that we don't start using it during an upgrade. After the upgrade, customer will have to manually set it to true. An AutoFlag will have initial value false and target value true and will not require customers to manually set it.
New AutoFlags are defined using the following syntax in the primary cpp file where their value is used.
DEFINE_RUNTIME_AUTO_<value_type>(<flag_name>, <flag_class>, <initial_value> , <target_value>, "<usage>");
bool, int32, int64, uint64, double, string]kLocalVolatile, kLocalPersisted, kExternal]<value_type>.<value_type>.Ex:
DEFINE_RUNTIME_AUTO_bool(fun_with_flags, kLocalPersisted, /* initial_value */ false, /* target_value */ true, "Vexillology is the study of flags.");
If you need to use the AutoFlag in additional files then you can declare them using the following syntax.
DECLARE_<value_type>(<flag_name>);
bool, int32, int64, uint64, double, string] Must match the one used to define the AutoFlag.Ex:
DECLARE_bool(fun_with_flags);
Postgres AutoFlags require an AutoFlag and a GUC variable with the same name, value and description. These AutoFlags use a slightly different macro.
DEFINE_RUNTIME_AUTO_PG_FLAG(<value_type>, <flag_name>, <flag_class>, <initial_value> , <target_value>, "<usage>");
Ex:
DEFINE_RUNTIME_AUTO_PG_FLAG(bool, yb_enable_expression_pushdown, kLocalVolatile, false, true, "Push supported expressions from ysql down to DocDB for evaluation.");
AutoFlag class is picked based on the persistence property of the data, and which processes use it.
| AutoFlag class | When to Promote | Safe to demote | Examples |
|---|---|---|---|
| LocalVolatile | After all the processes in our universe have been upgraded to the new code version. | Yes | yb_enable_expression_pushdown |
| LocalPersisted | After all the processes in our universe have been upgraded to the new code version. | No | enable_flush_retryable_requests |
| External | After all the processes in our universe and other dependent universes and processes have been upgraded to the new code version. | No | regular_tablets_data_block_key_value_encoding, enable_stream_compression |
Note:
String flags are not Runtime safe. Avoid these until #16593 is fixed.