Skip to content

Commit

Permalink
Added support for camo and group commit scopes. Updated 'README.md' f…
Browse files Browse the repository at this point in the history
…or 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.
  • Loading branch information
dougortiz committed Aug 23, 2023
1 parent a626621 commit b6d0b9c
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 0 deletions.
6 changes: 6 additions & 0 deletions roles/init_dbserver/tasks/init_dbserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@
- validate_only|bool or use_validation|bool
- not remove_only|bool
- run_initdb

- name: Import PGD validate tasks
ansible.builtin.import_tasks: validate_pgd_settings.yml
when:
- validate_only|bool or use_validation|bool
- not remove_only|bool
59 changes: 59 additions & 0 deletions roles/init_dbserver/tasks/validate_pgd_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
- name: Check that PGD CAMO commit scope is configured properly
ansible.builtin.assert:
that:
- pgd_commit_scopes[0].cs_name is defined and pgd_commit_scopes[0].cs_name|string != ''
- pgd_commit_scopes[0].cs_type is defined and pgd_commit_scopes[0].cs_type|string != ''
- pgd_commit_scopes[0].cs_origin_node_group is defined and pgd_commit_scopes[0].cs_origin_node_group|string != ''
- pgd_commit_scopes[0].cs_rule is defined and pgd_commit_scopes[0].cs_rule|string != ''
fail_msg: "The PGD CAMO commit scope cannot contain empty values."
success_msg: "The PGD CAMO commit scope does contain defined and non-empty configuration values."

- name: Check that PGD Group commit scope is configured properly
ansible.builtin.assert:
that:
- pgd_commit_scopes[1].cs_name is defined and pgd_commit_scopes[1].cs_name|string != ''
- pgd_commit_scopes[1].cs_type is defined and pgd_commit_scopes[1].cs_type|string != ''
- pgd_commit_scopes[1].cs_origin_node_group is defined and pgd_commit_scopes[1].cs_origin_node_group|string != ''
- pgd_commit_scopes[1].cs_rule is defined and pgd_commit_scopes[1].cs_rule|string != ''
fail_msg: "The PGD Group commit scope cannot contain empty values."
success_msg: "The PGD Group commit scope does contain defined and non-empty configuration values."

- name: Check that PGD CAMO commit scope is configured properly
ansible.builtin.assert:
that:
- pgd_commit_scopes[0].cs_type|string == 'CAMO'
- pgd_commit_scopes[0].member_nodes is defined
- pgd_commit_scopes[0].member_nodes|length == 2
fail_msg: "The PGD commit scope {{ pgd_commit_scopes[0].cs_name }} is not configured correctly."
success_msg: "The PGD CAMO commit scope: {{ pgd_commit_scopes[0].cs_name }} is not configured correctly."

- name: Check that PGD Group commit scope is configured properly
ansible.builtin.assert:
that:
- pgd_commit_scopes[1].cs_type|string == 'GROUP_COMMIT'
- pgd_commit_scopes[1].member_nodes is defined
- pgd_commit_scopes[1].member_nodes|length > 0
fail_msg: "The PGD Group commit scope {{ pgd_commit_scopes[1].cs_name }} is not configured correctly."
success_msg: "The PGD commit scope: {{ pgd_commit_scopes[1].cs_name }} is not configured correctly."

- name: Checks that only PGD CAMO commit scopes default_group_cs is set to true
ansible.builtin.assert:
that:
- (pgd_commit_scopes[0].default_group_cs|bool == true or pgd_commit_scopes[1].default_group_cs|bool == false) or (pgd_commit_scopes[0].default_group_cs|bool == false or pgd_commit_scopes[1].default_group_cs|bool == true)
fail_msg: "Only one PGD commit scope can have 'default_group_cs' set to true."
success_msg: "The PGD CAMO and Group commit scope 'default_group_cs' values are configured correctly."

- name: Initialize CAMO and Group commit scopes member_nodes array
set_fact:
result_dict: {}

- name: Check if a member_node exists in both PGD commit scope member_nodes array
set_fact:
result_dict: "{{ result_dict | combine({item: item in pgd_commit_scopes[1].member_nodes}) }}"
loop: "{{ pgd_commit_scopes[0].member_nodes }}"

- name: Assert member nodes for each commit scope exist within each other
fail:
msg: "A member_node cannot belong to a PGD CAMO nor Group commit scope."
when: true in result_dict.values()
31 changes: 31 additions & 0 deletions roles/setup_pgd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,37 @@ Dependencies
This role does not have any dependencies, but package repositories should have been
configured beforehand with the `setup_repo` role. At least one lead primary must exist
and a database cluster must be initialized on that node.
=======

### `PGD Commit Scopes Configuration`

The code below is part of the [roles/setup_pgd/defaults/main.yml](./defaults/main.yml), and
example for configuring two PGD commit scopes is listed below.

The configuration requirements for PGD through the configuration setting variables are:
1. Only one scope can be configured as default at a time. The variable to configure is: `default_group_cs`
2. The length of the `member_nodes` for a `camo` commit scope is exactly `two`
3. No node in `member_nodes` for either commit scope can belong to the other commit scope
4. All nodes in `member_nodes` must belong to a `parent_group`
5. The `cs_rule` parameter must be: valid, correctly formatted, and adhere to the correct syntax

```yaml
pgd_commit_scopes:
- cs_name: 'camo_scope_1'
cs_type: 'CAMO' # either camo or group_commit
parent_group: 'pgd_cluster' # this group is present in cluster
cs_origin_node_group: 'pgd_two_nodes' # this group may or may not be present
member_nodes: ['edb-primary1', 'edb-primary2']
default_group_cs: true # don't make mandatory, default('false') if not present in array
cs_rule: "ALL ( pgd_two_nodes ) ON visible CAMO DEGRADE ON (timeout=500s) TO ASYNC"
- cs_name: 'groupcommit_scope_1'
cs_type: 'GROUP_COMMIT'
parent_group: 'pgd_cluster'
cs_origin_node_group: 'pgd_remaining_nodes'
member_nodes: ['edb-primary3']
default_group_cs: false
cs_rule: "ALL ( pgd_remaining_nodes ) GROUP COMMIT"
```


Example Playbook
Expand Down
18 changes: 18 additions & 0 deletions roles/setup_pgd/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,25 @@ supported_pg_version:
supported_pgd_version:
- 5

<<<<<<< HEAD
# For CAMO Commit Scopes
max_prepared_transactions: 100

pgd_commit_scopes: ""
=======
pgd_commit_scopes:
- cs_name: 'camo_scope_1'
cs_type: 'CAMO' # either camo or group_commit
parent_group: 'pgd_cluster' # this group is present in cluster
cs_origin_node_group: 'pgd_two_nodes' # this group may or may not be present
member_nodes: ['edb-primary1', 'edb-primary2']
default_group_cs: true # don't make mandatory, default('false') if not present in array
cs_rule: "ALL ( pgd_two_nodes ) ON visible CAMO DEGRADE ON (timeout=500s) TO ASYNC"
- cs_name: 'groupcommit_scope_1'
cs_type: 'GROUP_COMMIT'
parent_group: 'pgd_cluster'
cs_origin_node_group: 'pgd_remaining_nodes'
member_nodes: ['edb-primary3']
default_group_cs: false
cs_rule: "ALL ( pgd_remaining_nodes ) GROUP COMMIT"
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
63 changes: 63 additions & 0 deletions roles/setup_pgd/tasks/pgd_camo_commitscope_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
tasks_from: execute_sql_scripts
vars:
pg_query:
<<<<<<< HEAD
- query: "SELECT COUNT(1) FROM bdr.node_group WHERE node_group_name = '{{ item.parent_group }}'"
=======
- query: "SELECT COUNT(1) FROM bdr.node_group WHERE node_group_name = '{{ pgd_commit_scopes[0].parent_group }}'"
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
db: "{{ pgd_cluster_database }}"

- name: Store status of existence of PGD parent group
Expand All @@ -19,7 +23,11 @@
tasks_from: execute_sql_scripts
vars:
pg_query:
<<<<<<< HEAD
- query: "SELECT COUNT(1) FROM bdr.node_group WHERE node_group_name = '{{ item.cs_origin_node_group }}'"
=======
- query: "SELECT COUNT(1) FROM bdr.node_group WHERE node_group_name = '{{ pgd_commit_scopes[0].cs_origin_node_group }}'"
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
db: "{{ pgd_cluster_database }}"

- name: Store status of existence of PGD commit scope origin node group
Expand All @@ -32,47 +40,74 @@
tasks_from: execute_sql_scripts
vars:
pg_query:
<<<<<<< HEAD
- query: "SELECT bdr.create_node_group(node_group_name := '{{ item.cs_origin_node_group }}',
parent_group_name := '{{ item.parent_group }}',
=======
- query: "SELECT bdr.create_node_group(node_group_name := '{{ pgd_commit_scopes[0].cs_origin_node_group }}',
parent_group_name := '{{ pgd_commit_scopes[0].parent_group }}',
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
join_node_group := false
)"
db: "{{ pgd_cluster_database }}"
ignore_query_execution_error: false
when:
<<<<<<< HEAD
- inventory_hostname == item.member_nodes[0]
- _pgd_camo_originnodegroup_exists|int == 0 and _pgd_camo_parentgroup_exists|int == 1
- item.cs_type == 'CAMO'
=======
- inventory_hostname == pgd_commit_scopes[0].member_nodes[0]
- _pgd_camo_originnodegroup_exists|int == 0 and _pgd_camo_parentgroup_exists|int == 1
- pgd_commit_scopes[0].cs_type == 'CAMO'
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)

- name: Run query to re-check if PGD CAMO commit scope origin node group
ansible.builtin.include_role:
name: manage_dbserver
tasks_from: execute_sql_scripts
vars:
pg_query:
<<<<<<< HEAD
- query: "SELECT COUNT(1) FROM bdr.node_group WHERE node_group_name = '{{ item.cs_origin_node_group }}'"
=======
- query: "SELECT COUNT(1) FROM bdr.node_group WHERE node_group_name = '{{ pgd_commit_scopes[0].cs_origin_node_group }}'"
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
db: "{{ pgd_cluster_database }}"

- name: Store status of existence of PGD commit scope origin node group
ansible.builtin.set_fact:
_pgd_camo_originnodegroup_exists: "{{ sql_query_output.results[0].query_result[0].count | int }}"

<<<<<<< HEAD
# FIX ME: Get 'join' to work
=======
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
- name: Switch primary node towards PGD node sub group with two nodes when CAMO
ansible.builtin.include_role:
name: manage_dbserver
tasks_from: execute_sql_scripts
vars:
pg_query:
<<<<<<< HEAD
- query: "SELECT bdr.switch_node_group(node_group_name := '{{ item.cs_origin_node_group }}',
=======
- query: "SELECT bdr.switch_node_group(node_group_name := '{{ pgd_commit_scopes[0].cs_origin_node_group }}',
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
wait_for_completion := true
)"
db: "{{ pgd_cluster_database }}"
ignore_query_execution_error: false
when:
- inventory_hostname == node
- _pgd_camo_originnodegroup_exists|int == 1 and _pgd_camo_parentgroup_exists|int == 1
<<<<<<< HEAD
- item.cs_type == 'CAMO'
loop: "{{ item.member_nodes }}"
=======
- pgd_commit_scopes[0].cs_type == 'CAMO'
loop: "{{ pgd_commit_scopes[0].member_nodes }}"
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
loop_control:
loop_var: node

Expand All @@ -84,16 +119,28 @@
throttle: 1
vars:
pg_query:
<<<<<<< HEAD
- query: "SELECT bdr.add_commit_scope(commit_scope_name := '{{ item.cs_name }}',
origin_node_group := '{{ item.cs_origin_node_group }}',
rule := '{{ item.cs_rule }}'
=======
- query: "SELECT bdr.add_commit_scope(commit_scope_name := '{{ pgd_commit_scopes[0].cs_name }}',
origin_node_group := '{{ pgd_commit_scopes[0].cs_origin_node_group }}',
rule := '{{ pgd_commit_scopes[0].cs_rule }}'
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
)"
db: "{{ pgd_cluster_database }}"
ignore_query_execution_error: false
when:
<<<<<<< HEAD
- inventory_hostname == node
- _pgd_camo_originnodegroup_exists|int == 1 and _pgd_camo_parentgroup_exists|int == 1
loop: "{{ item.member_nodes }}"
=======
- inventory_hostname == node
- _pgd_camo_originnodegroup_exists|int == 1 and _pgd_camo_parentgroup_exists|int == 1
loop: "{{ pgd_commit_scopes[0].member_nodes }}"
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
loop_control:
loop_var: node

Expand All @@ -103,7 +150,11 @@
tasks_from: execute_sql_scripts
vars:
pg_query:
<<<<<<< HEAD
- query: "SELECT COUNT(1) FROM bdr.commit_scopes WHERE commit_scope_name = '{{ item.cs_name }}'"
=======
- query: "SELECT COUNT(1) FROM bdr.commit_scopes WHERE commit_scope_name = '{{ pgd_commit_scopes[0].cs_name }}'"
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
db: "{{ pgd_cluster_database }}"

- name: Store status of existence of PGD CAMO commit scope
Expand All @@ -118,13 +169,20 @@
throttle: 1
vars:
pg_query:
<<<<<<< HEAD
- query: "SELECT bdr.alter_node_group_option(node_group_name := '{{ item.cs_origin_node_group }}',
config_key := 'default_commit_scope',
config_value := '{{ item.cs_name }}'
=======
- query: "SELECT bdr.alter_node_group_option(node_group_name := '{{ pgd_commit_scopes[0].cs_origin_node_group }}',
config_key := 'default_commit_scope',
config_value := '{{ pgd_commit_scopes[0].cs_name }}'
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
)"
db: "{{ pgd_cluster_database }}"
ignore_query_execution_error: false
when:
<<<<<<< HEAD
- item.default_group_cs|bool
- item.cs_type|string == 'CAMO'
- _pgd_camoscope_exists|int == 1 and _pgd_camo_originnodegroup_exists|int == 1
Expand Down Expand Up @@ -166,3 +224,8 @@
name: "{{ pg_service }}"
state: restarted
become: true
=======
- pgd_commit_scopes[0].default_group_cs|bool == true
- pgd_commit_scopes[0].cs_type|string == 'CAMO'
- _pgd_camoscope_exists|int == 1 and _pgd_camo_originnodegroup_exists|int == 1
>>>>>>> c5b23aa (Added support for camo and group commit scopes. Updated 'README.md' for 'setup_pgd' role. Added tests for pgd configuration settings in 'main.yml' in 'init_dbserver' role.)
Loading

0 comments on commit b6d0b9c

Please sign in to comment.