Module cartridge.twophase

Clusterwide configuration propagation two-phase algorithm.

(Added in v1.2.0-19)

Functions

patch_clusterwide (patch) Edit the clusterwide configuration.
get_schema () Get clusterwide DDL schema.
set_schema (schema) Apply clusterwide DDL schema.
on_patch (trigger_new, trigger_old) Set up trigger for for patch_clusterwide.

Local Functions

prepare_2pc (data) Two-phase commit - preparation stage.
commit_2pc () Two-phase commit - commit stage.
abort_2pc () Two-phase commit - abort stage.


Functions

patch_clusterwide (patch)
Edit the clusterwide configuration. Top-level keys are merged with the current configuration. To remove a top-level section, use patch_clusterwide{key = box.NULL}.

The function uses a two-phase commit algorithm with the following steps:

I. Patches the current configuration.

II. Validates topology on the current server.

III. Executes the preparation phase (prepare_2pc) on every server excluding expelled and disabled servers.

IV. If any server reports an error, executes the abort phase (abort_2pc). All servers prepared so far are rolled back and unlocked.

V. Performs the commit phase (commit_2pc). In case the phase fails, an automatic rollback is impossible, the cluster should be repaired manually.

Parameters:

Returns:

    boolean true

Or

  1. nil
  2. table Error description
get_schema ()
Get clusterwide DDL schema.

(Added in v1.2.0-28)

Returns:

    string Schema in YAML format

Or

  1. nil
  2. table Error description
set_schema (schema)
Apply clusterwide DDL schema.

(Added in v1.2.0-28)

Parameters:

  • schema string in YAML format

Returns:

    string The same new schema

Or

  1. nil
  2. table Error description
on_patch (trigger_new, trigger_old)
Set up trigger for for patch_clusterwide.

It will be executed before new new config applied.

If the parameters are (nil, old_trigger), then the old trigger is deleted.

The trigger function is called with two argument: - conf_new (ClusterwideConfig) - conf_old (ClusterWideConfig)

It is allowed to modify conf_new, but not conf_old. Return values are ignored. If calling a trigger raises an error, patch_clusterwide returns it as nil, err.

(Added in v2.1.0-4)

Parameters:

  • trigger_new function
  • trigger_old function

Usage:

    local function inject_data(conf_new, _)
        local data_yml = yaml.encode({foo = 'bar'})
        conf_new:set_plaintext('data.yml', data_yml)
    end)
    
    twophase.on_patch(inject_data) -- set custom patch modifier trigger
    twophase.on_patch(nil, inject_data) -- drop trigger

Local Functions

prepare_2pc (data)
Two-phase commit - preparation stage.

Validate the configuration and acquire a lock setting local variable and writing "config.prepare.yml" file. If the validation fails, the lock isn't acquired and doesn't have to be aborted.

Parameters:

  • data table clusterwide config content

Returns:

    boolean true

Or

  1. nil
  2. table Error description
commit_2pc ()
Two-phase commit - commit stage.

Back up the active configuration, commit changes to filesystem by renaming prepared file, release the lock, and configure roles. If any errors occur, configuration is not rolled back automatically. Any problem encountered during this call has to be solved manually.

Returns:

    boolean true

Or

  1. nil
  2. table Error description
abort_2pc ()
Two-phase commit - abort stage.

Release the lock for further commit attempts.

Returns:

    boolean true
generated by LDoc 1.4.6 Last updated 2020-04-24 16:23:15