parent
073c96a3fd
commit
daf13107a0
@ -0,0 +1,48 @@
|
|||||||
|
- debug:
|
||||||
|
msg: "Compressing room `{{ room_details.room_id }}` having {{ room_details.count }} state group rows"
|
||||||
|
|
||||||
|
- name: Generate rust-synapse-compress-state room compression command
|
||||||
|
set_fact:
|
||||||
|
matrix_synapse_rust_synapse_compress_state_compress_room_command: >-
|
||||||
|
{{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-compress-room
|
||||||
|
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
||||||
|
--cap-drop=ALL
|
||||||
|
--network={{ matrix_docker_network }}
|
||||||
|
-v {{ matrix_synapse_rust_synapse_compress_state_base_path }}:/work
|
||||||
|
{{ matrix_synapse_rust_synapse_compress_state_docker_image }}
|
||||||
|
/synapse-compress-state -t -o /work/state-compressor.sql
|
||||||
|
-p "host={{ matrix_synapse_database_host }} user={{ matrix_synapse_database_user }} password={{ matrix_synapse_database_password }} dbname={{ matrix_synapse_database_database }}"
|
||||||
|
-r '{{ room_details.room_id }}'
|
||||||
|
|
||||||
|
- name: Run rust-synapse-compress-state room compression command (SQL generation)
|
||||||
|
command: "{{ matrix_synapse_rust_synapse_compress_state_compress_room_command }}"
|
||||||
|
async: "{{ matrix_synapse_rust_synapse_compress_state_compress_room_time }}"
|
||||||
|
poll: 10
|
||||||
|
register: matrix_synapse_rust_synapse_compress_state_compress_room_command_result
|
||||||
|
|
||||||
|
- debug: var="matrix_synapse_rust_synapse_compress_state_compress_room_command_result"
|
||||||
|
|
||||||
|
- name: Generate Postgres compression SQL import command
|
||||||
|
set_fact:
|
||||||
|
matrix_synapse_rust_synapse_compress_state_psql_import_command: >-
|
||||||
|
{{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-psql-import
|
||||||
|
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
||||||
|
--cap-drop=ALL
|
||||||
|
--network={{ matrix_docker_network }}
|
||||||
|
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql
|
||||||
|
-v {{ matrix_synapse_rust_synapse_compress_state_base_path }}:/work:ro
|
||||||
|
--entrypoint=/bin/sh
|
||||||
|
{{ matrix_postgres_docker_image_latest }}
|
||||||
|
-c "cat /work/state-compressor.sql |
|
||||||
|
psql -v ON_ERROR_STOP=1 -h matrix-postgres"
|
||||||
|
|
||||||
|
- name: Import compression SQL into Postgres
|
||||||
|
command: "{{ matrix_synapse_rust_synapse_compress_state_psql_import_command }}"
|
||||||
|
async: "{{ matrix_synapse_rust_synapse_compress_state_psql_import_time }}"
|
||||||
|
poll: 10
|
||||||
|
register: matrix_synapse_rust_synapse_compress_state_psql_import_command_result
|
||||||
|
|
||||||
|
- name: Clean up
|
||||||
|
file:
|
||||||
|
path: "{{ matrix_synapse_rust_synapse_compress_state_base_path }}/state-compressor.sql"
|
||||||
|
state: absent
|
@ -0,0 +1,118 @@
|
|||||||
|
# Pre-checks
|
||||||
|
|
||||||
|
- name: Fail if Postgres not enabled
|
||||||
|
fail:
|
||||||
|
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot use rust-synapse-compress-state."
|
||||||
|
when: "not matrix_postgres_enabled|bool"
|
||||||
|
|
||||||
|
|
||||||
|
# Defaults
|
||||||
|
|
||||||
|
- name: Set matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time, if not provided
|
||||||
|
set_fact:
|
||||||
|
matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time: 15
|
||||||
|
when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time|default('') == ''"
|
||||||
|
|
||||||
|
- name: Set matrix_synapse_rust_synapse_compress_state_compress_room_time, if not provided
|
||||||
|
set_fact:
|
||||||
|
matrix_synapse_rust_synapse_compress_state_compress_room_time: 1800
|
||||||
|
when: "matrix_synapse_rust_synapse_compress_state_compress_room_time|default('') == ''"
|
||||||
|
|
||||||
|
- name: Set matrix_synapse_rust_synapse_compress_state_psql_import_time, if not provided
|
||||||
|
set_fact:
|
||||||
|
matrix_synapse_rust_synapse_compress_state_psql_import_time: 1800
|
||||||
|
when: "matrix_synapse_rust_synapse_compress_state_psql_import_time|default('') == ''"
|
||||||
|
|
||||||
|
- name: Set matrix_synapse_rust_synapse_compress_state_min_state_groups_required, if not provided
|
||||||
|
set_fact:
|
||||||
|
# The minimum number of state groups we're looking for before we consider a room eligible for compression.
|
||||||
|
# Rooms with a smaller state groups count will not be compressed.
|
||||||
|
matrix_synapse_rust_synapse_compress_state_min_state_groups_required: 100000
|
||||||
|
when: "matrix_synapse_rust_synapse_compress_state_min_state_groups_required|default('') == ''"
|
||||||
|
|
||||||
|
|
||||||
|
# Actual compression work
|
||||||
|
|
||||||
|
- name: Ensure rust-synapse-compress-state paths exist
|
||||||
|
file:
|
||||||
|
path: "{{ matrix_synapse_rust_synapse_compress_state_base_path }}"
|
||||||
|
state: directory
|
||||||
|
mode: 0750
|
||||||
|
owner: "{{ matrix_user_username }}"
|
||||||
|
group: "{{ matrix_user_groupname }}"
|
||||||
|
|
||||||
|
- name: Ensure rust-synapse-compress-state image is pulled
|
||||||
|
docker_image:
|
||||||
|
name: "{{ matrix_synapse_rust_synapse_compress_state_docker_image }}"
|
||||||
|
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||||||
|
force_source: "{{ matrix_synapse_rust_synapse_compress_state_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
|
||||||
|
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_synapse_rust_synapse_compress_state_docker_image_force_pull }}"
|
||||||
|
|
||||||
|
- name: Generate rust-synapse-compress-state room find command
|
||||||
|
set_fact:
|
||||||
|
matrix_synapse_rust_synapse_compress_state_find_rooms_command: >-
|
||||||
|
{{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-find-rooms
|
||||||
|
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
||||||
|
--cap-drop=ALL
|
||||||
|
--network={{ matrix_docker_network }}
|
||||||
|
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql
|
||||||
|
{{ matrix_postgres_docker_image_latest }}
|
||||||
|
psql -v ON_ERROR_STOP=1 -h matrix-postgres {{ matrix_synapse_database_database }} -c
|
||||||
|
'SELECT array_to_json(array_agg(row_to_json (r))) FROM (SELECT room_id, count(*) AS count FROM state_groups_state GROUP BY room_id HAVING count(*) > {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} ORDER BY count DESC) r;'
|
||||||
|
|
||||||
|
- name: Find rooms eligible for compression with rust-synapse-compress-state
|
||||||
|
command: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command }}"
|
||||||
|
async: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time }}"
|
||||||
|
poll: 10
|
||||||
|
register: matrix_synapse_rust_synapse_compress_state_find_rooms_command_result
|
||||||
|
|
||||||
|
# We expect the output to be like this:
|
||||||
|
#
|
||||||
|
# "stdout_lines": [
|
||||||
|
# " array_to_json ",
|
||||||
|
# "----------------------------------------------------------------------------------------------------------------------------",
|
||||||
|
# " [{\"room_id\":\"!some-id\",\"count\":2461329},{\"room_id\":\"!another-id\",\"count\":512017}]",
|
||||||
|
# "(1 row)"
|
||||||
|
# ]
|
||||||
|
#
|
||||||
|
# Row 3 (out of 4) contains the actual result.
|
||||||
|
#
|
||||||
|
# Row 3 contains a space when there's no result.
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- debug: var="matrix_synapse_rust_synapse_compress_state_find_rooms_command_result"
|
||||||
|
|
||||||
|
- name: Fail if room find result is not what we expect
|
||||||
|
fail:
|
||||||
|
msg: >-
|
||||||
|
Expecting 4 lines in the "find rooms" result.
|
||||||
|
when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.failed or matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines|length != 4"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
# matrix_synapse_rust_synapse_compress_state_eligible_rooms is a list
|
||||||
|
# of dictionaries like this: {'room_id': '!some-id', 'count': 2461329}
|
||||||
|
- set_fact:
|
||||||
|
matrix_synapse_rust_synapse_compress_state_eligible_rooms: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines[2] | from_json }}"
|
||||||
|
|
||||||
|
- name: Display rooms that will be compressed
|
||||||
|
debug:
|
||||||
|
msg: >-
|
||||||
|
The following rooms contain more than {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} state group rows
|
||||||
|
(configurable via `matrix_synapse_rust_synapse_compress_state_min_state_groups_required`)
|
||||||
|
and will be compressed:
|
||||||
|
{{ matrix_synapse_rust_synapse_compress_state_eligible_rooms }}
|
||||||
|
|
||||||
|
- name: Compress room state
|
||||||
|
include_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/compress_room.yml"
|
||||||
|
with_items: "{{ matrix_synapse_rust_synapse_compress_state_eligible_rooms }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: room_details
|
||||||
|
when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines[2] != ' '"
|
||||||
|
|
||||||
|
- name: Show notice about lack of rooms to compress
|
||||||
|
debug:
|
||||||
|
msg: >-
|
||||||
|
No rooms were found to contain more than {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} state group rows
|
||||||
|
(configurable via `matrix_synapse_rust_synapse_compress_state_min_state_groups_required`),
|
||||||
|
so there's nothing to compress.
|
||||||
|
when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines[2] == ' '"
|
Loading…
Reference in new issue