Skip to content

Commit

Permalink
Increase swappiness max and fix cast (#434)
Browse files Browse the repository at this point in the history
## Issue
This PR increases the max allowed for swappiness and fixes an erroneous
string to string comparison


Manually tested on: AWS EC2
  • Loading branch information
Mehdi-Bendriss authored Sep 10, 2024
1 parent 96b3cc9 commit f8b701f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/charms/opensearch/v0/opensearch_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,26 +455,26 @@ def normalize_allocation_exclusions(exclusions: Union[List[str], Set[str], str])
def missing_sys_requirements(self) -> List[str]:
"""Checks the system requirements."""

def apply(prop: str, value: str) -> bool:
def apply(prop: str, value: int) -> bool:
"""Apply a sysctl value and check if it was set."""
try:
self._run_cmd(f"sysctl -w {prop}={value}")
return self._run_cmd(f"sysctl -n {prop}") == value
return int(self._run_cmd(f"sysctl -n {prop}")) == value
except OpenSearchCmdError:
return False

missing_requirements = []

prop, val = "vm.max_map_count", "262144"
if self._run_cmd(f"sysctl -n {prop}") < val and not apply(prop, val):
prop, val = "vm.max_map_count", 262144
if int(self._run_cmd(f"sysctl -n {prop}")) < val and not apply(prop, val):
missing_requirements.append(f"{prop} should be at least {val}")

prop, val = "vm.swappiness", "0"
if self._run_cmd(f"sysctl -n {prop}") > val and not apply(prop, val):
missing_requirements.append(f"{prop} should be {val}")
prop, val = "vm.swappiness", 1
if int(self._run_cmd(f"sysctl -n {prop}")) > val and not apply(prop, 0):
missing_requirements.append(f"{prop} should be at most 1")

prop, val = "net.ipv4.tcp_retries2", "5"
if self._run_cmd(f"sysctl -n {prop}") > val and not apply(prop, val):
prop, val = "net.ipv4.tcp_retries2", 5
if int(self._run_cmd(f"sysctl -n {prop}")) > val and not apply(prop, val):
missing_requirements.append(f"{prop} should be at most {val}")

return missing_requirements
Expand Down

0 comments on commit f8b701f

Please sign in to comment.