Skip to content

Commit e00e89b

Browse files
authored
[DPE-7549] Add compression and restore max-process (#1019)
* Add compression and restore max-process * Bump libs * Use available resources
1 parent 24d78b2 commit e00e89b

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
331331

332332
# Increment this PATCH version before using `charmcraft publish-lib` or reset
333333
# to 0 if you are raising the major API version
334-
LIBPATCH = 47
334+
LIBPATCH = 48
335335

336336
PYDEPS = ["ops>=2.0.0"]
337337

@@ -3760,6 +3760,10 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
37603760
event.relation, app=event.app, unit=event.unit
37613761
)
37623762

3763+
def _on_secret_changed_event(self, event: SecretChangedEvent) -> None:
3764+
"""Event emitted when the relation data has changed."""
3765+
pass
3766+
37633767

37643768
class OpenSearchProvides(OpenSearchProvidesData, OpenSearchProvidesEventHandlers):
37653769
"""Provider-side of the OpenSearch relation."""

src/backups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ def _render_pgbackrest_conf_file(self) -> bool:
11861186
# Open the template pgbackrest.conf file.
11871187
with open("templates/pgbackrest.conf.j2") as file:
11881188
template = Template(file.read())
1189+
cpu_count, _ = self.charm.get_available_resources()
11891190
# Render the template file with the correct values.
11901191
rendered = template.render(
11911192
enable_tls=self.charm.is_tls_enabled and len(self.charm.peer_members_endpoints) > 0,
@@ -1202,6 +1203,7 @@ def _render_pgbackrest_conf_file(self) -> bool:
12021203
storage_path=self.charm._storage_path,
12031204
user=BACKUP_USER,
12041205
retention_full=s3_parameters["delete-older-than-days"],
1206+
process_max=max(cpu_count - 2, 1),
12051207
)
12061208
# Delete the original file and render the one with the right info.
12071209
filename = "/etc/pgbackrest.conf"

templates/pgbackrest.conf.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[global]
22
backup-standby=y
3+
compress-type=zst
34
repo1-retention-full-type=time
45
repo1-retention-full={{ retention_full }}
56
repo1-retention-history=365
@@ -43,3 +44,6 @@ pg{{ ns.count }}-user={{ user }}
4344
{% set ns.count = ns.count + 1 %}
4445
{%- endfor %}
4546
{%- endif %}
47+
48+
[global:restore]
49+
process-max={{process_max}}

tests/unit/test_backups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,7 @@ def test_render_pgbackrest_conf_file(harness, tls_ca_chain_filename):
17611761
new_callable=PropertyMock(return_value=tls_ca_chain_filename),
17621762
) as _tls_ca_chain_filename,
17631763
patch("charm.PostgreSQLBackups._retrieve_s3_parameters") as _retrieve_s3_parameters,
1764+
patch("charm.PostgresqlOperatorCharm.get_available_resources", return_value=(4, 1024)),
17641765
):
17651766
# Set up a mock for the `open` method, set returned data to postgresql.conf template.
17661767
with open("templates/pgbackrest.conf.j2") as f:
@@ -1812,6 +1813,7 @@ def test_render_pgbackrest_conf_file(harness, tls_ca_chain_filename):
18121813
storage_path=harness.charm._storage_path,
18131814
user="backup",
18141815
retention_full=30,
1816+
process_max=2,
18151817
)
18161818

18171819
# Patch the `open` method with our mock.

0 commit comments

Comments
 (0)