Skip to content

Commit

Permalink
Updated roles: init_dbserver, and setup_pgd. All tasks related to: PG…
Browse files Browse the repository at this point in the history
…D, PGD CAMO, and PGD GROUP COMMIT SCOPES
  • Loading branch information
dougortiz committed Aug 24, 2023
1 parent 158ba9d commit 370290a
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 361 deletions.
14 changes: 0 additions & 14 deletions roles/init_dbserver/tasks/init_dbserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@
- hostvars[inventory_hostname].pgd.use_physical_backup is defined
- hostvars[inventory_hostname].pgd.use_physical_backup|bool

- name: Import PGD verify tasks
ansible.builtin.import_tasks: verify_pgd_settings.yml
when:
- validate_only|bool or use_validation|bool
- not remove_only|bool
- install_pgd
- pgd_commit_scopes | length > 0

- name: Force cleanup based on force_initdb
ansible.builtin.include_tasks: rm_initdb.yml
when: >
Expand Down Expand Up @@ -112,9 +104,3 @@
- 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
2 changes: 1 addition & 1 deletion roles/init_dbserver/tasks/setup_tde.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
become: true
when:
- edb_master_key|length > 0
- pg_data not in edb_master_key_location
- edb_master_key_location not in pg_data

- name: Store edb_master_key in a secure location
ansible.builtin.copy:
Expand Down
2 changes: 1 addition & 1 deletion roles/init_dbserver/tasks/validate_init_dbserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
ansible.builtin.wait_for:
port: "{{ pg_port }}"
state: started
msg: "Port {{ pg_port }} is listening."
msg: "Port {{ pg_port }} is not listening."
become: true

- name: Check pg_unix_socket_directories socket
Expand Down
4 changes: 2 additions & 2 deletions roles/init_dbserver/tasks/verify_tde_vars.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Verify edb_key_wrap_cmd and edb_key_unwrap_cmd
- name: Verify edb_key_wrap_cmd is defined or not
ansible.builtin.fail:
msg: "edb_key_wrap_cmd and edb_key_unwrap_cmd are must for initializing a cluster with TDE"
msg: "edb_key_wrap_cmd and edb_key_unwrap_cmd are must for initializing a cluster"
when: edb_key_wrap_cmd|length < 1 or edb_key_unwrap_cmd|length < 1

- name: Verify edb_master_key and edb_secure_master_key
Expand Down
2 changes: 0 additions & 2 deletions roles/setup_pgd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ 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.
=======




Expand Down
100 changes: 23 additions & 77 deletions roles/setup_pgd/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pass_dir: "~/.edb"
pg_local_wal_archive_dir: ""
edb_audit_directory: ""


# unix socket domain directories
pg_unix_socket_directories:
- "/var/run/postgresql"
Expand Down Expand Up @@ -92,24 +91,8 @@ pgd_cluster_nodes: []
local_node_dsn: ""
lead_primary_dsn: ""

etc_hosts_lists: []

supported_os:
- CentOS7
- CentOS8
- RedHat7
- RedHat8
- Rocky8
- AlmaLinux8
- OracleLinux7

supported_pg_type:
- EPAS
- PG

supported_pg_version:
- 14
- 15
# For CAMO Commit Scopes
max_prepared_transactions: 100

# The following parameters must be configured in the 'pgd_commit_scopes' list
# the values below are examples and should be adjusted to your requirements
Expand All @@ -129,63 +112,26 @@ supported_pg_version:
# - member_nodes: ['edb-primary3']
# - default_group_cs: true
# - cs_rule: "ALL ( pgd_remaining_nodes ) GROUP COMMIT"
supported_pgd_version:
- 5
pgd_commit_scopes: ""

<<<<<<< HEAD
<<<<<<< HEAD
# For CAMO Commit Scopes
max_prepared_transactions: 100
etc_hosts_lists: []

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.)
=======
# The following parameters must be configured in the 'pgd_commit_scopes' list
# the values below are examples and should be adjusted to your requirements
# for CAMO
# - cs_type: 'CAMO'
# for GROUP_COMMIT
# - cs_type: 'GROUP_COMMIT'
# for CAMO
# - cs_name: 'camo_scope_1'
# for GROUP_COMMIT
# - cs_name: 'group_commit_scope_1'
# - parent_group: 'pgd_cluster'
# for CAMO
# - cs_origin_node_group: 'pgd_two_nodes'
# for GROUP_COMMIT
# - cs_origin_node_group: 'pgd_gc_nodes'
# for CAMO
# - member_nodes: ['edb-primary1', 'edb-primary2']
# for GROUP_COMMIT
# - member_nodes: ['edb-primary3']
# - default_group_cs: true
# for CAMO
# - cs_rule: "ALL ( pgd_two_nodes ) ON visible CAMO DEGRADE ON (timeout=500s) TO ASYNC"
# for GROUP_COMMIT
# - cs_rule: "ALL ( pgd_remaining_nodes ) GROUP COMMIT"
pgd_commit_scopes:
- cs_name: ''
cs_type: ''
parent_group: ''
cs_origin_node_group: ''
member_nodes: ['']
default_group_cs: true
cs_rule: ""
>>>>>>> abab58a (Added checks for 'pgd_commit_scopes' list. Removed 'streaming' and 'max_prepared' for GROUP COMMIT SCOPE.)
supported_os:
- CentOS7
- CentOS8
- RedHat7
- RedHat8
- Rocky8
- AlmaLinux8
- OracleLinux7

supported_pg_type:
- EPAS
- PG

supported_pg_version:
- 14
- 15

supported_pgd_version:
- 5
96 changes: 13 additions & 83 deletions roles/setup_pgd/tasks/pgd_camo_commitscope_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
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 @@ -23,11 +19,7 @@
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 @@ -40,74 +32,45 @@
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 @@ -119,28 +82,16 @@
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 @@ -150,11 +101,7 @@
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 @@ -169,25 +116,13 @@
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
<<<<<<< HEAD
=======
>>>>>>> abab58a (Added checks for 'pgd_commit_scopes' list. Removed 'streaming' and 'max_prepared' for GROUP COMMIT SCOPE.)
- item.default_group_cs|bool
- item.cs_type|string == 'CAMO'
- _pgd_camoscope_exists|int == 1 and _pgd_camo_originnodegroup_exists|int == 1

- name: Configure BDR 'default_streaming_mode' to off
Expand All @@ -205,30 +140,25 @@
db: "{{ pgd_cluster_database }}"
ignore_query_execution_error: false
when:
- item.default_group_cs|bool
- item.cs_type|string == 'CAMO'
- _pgd_camoscope_exists|int == 1 and _pgd_camo_originnodegroup_exists|int == 1

- name: ALTER max_prepared_transactions
community.postgresql.postgresql_query:
query: >-
ALTER SYSTEM SET max_prepared_transactions = '{{ max_prepared_transactions }}'
port: "{{ pg_port }}"
db: "{{ pg_database }}"
login_user: "{{ pg_owner }}"
login_unix_socket: "{{ pg_unix_socket_directories[0] }}"
autocommit: true
no_log: "{{ disable_logging }}"
become: true
become_user: "{{ pg_owner }}"
ansible.builtin.include_role:
name: manage_dbserver
tasks_from: execute_sql_scripts
apply:
throttle: 1
vars:
pg_query:
- query: "ALTER SYSTEM SET max_prepared_transactions = '{{ max_prepared_transactions }}'"
db: "{{ pg_database }}"
autocommit: true
ignore_query_execution_error: false
when:
- _pgd_camoscope_exists|int == 1 and _pgd_camo_originnodegroup_exists|int == 1

- name: Restart the pg service
ansible.builtin.systemd:
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 370290a

Please sign in to comment.