Skip to content

Commit

Permalink
Refine debug logging
Browse files Browse the repository at this point in the history
We used to rely on cached_xlog_location and replaced_xlog_location when showing a debug message about pod update prevention, but that produced false positives, i.e.
```
2024-06-06 11:34:36,308 DEBUG: prevented pod update, keeping cached xlog value for up to -1 seconds
```

Make sure we only show this message when we actually used cached xlog, no updates happen, but they should have happened,
since cached value and received member value do not match.
  • Loading branch information
alexeyklyukin committed Jun 6, 2024
1 parent a926734 commit 1851cfc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions patroni/dcs/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,21 +1344,22 @@ def touch_member(self, data: Dict[str, Any]) -> bool:
replaced_xlog_location: Optional[str] = data.get('xlog_location', None)
cached_xlog_location, last_updated = self._get_cached_xlog_location()
now = time.time()
use_cached_xlog = False
if last_updated is not None and last_updated + self._xlog_cache_ttl > now:
if cached_xlog_location is not None and replaced_xlog_location is not None:
data['xlog_location'] = cached_xlog_location
use_cached_xlog = True
elif replaced_xlog_location is not None:
# location cache expired
self._set_cached_xlog_location(replaced_xlog_location)
replaced_xlog_location = None
ret = member and pod_labels is not None\
and all(pod_labels.get(k) == v for k, v in role_labels.items())\
and deep_compare(data, member.data)

if not ret:
# if we move forward with an update anyway, make sure to write the actual
# value for the xlog, and not the stale cached value.
if replaced_xlog_location is not None:
if use_cached_xlog:
self._set_cached_xlog_location(replaced_xlog_location)

Check failure on line 1363 in patroni/dcs/kubernetes.py

View workflow job for this annotation

GitHub Actions / pyright

Argument of type "str | None" cannot be assigned to parameter "location" of type "str" in function "_set_cached_xlog_location"   Type "str | None" cannot be assigned to type "str"     "None" is incompatible with "str" (reportArgumentType)
data['xlog_location'] = replaced_xlog_location
metadata = {'namespace': self._namespace, 'name': self._name, 'labels': role_labels,
Expand All @@ -1367,7 +1368,7 @@ def touch_member(self, data: Dict[str, Any]) -> bool:
ret = self._api.patch_namespaced_pod(self._name, self._namespace, body)
if ret:
self._pods.set(self._name, ret)
elif cached_xlog_location != replaced_xlog_location and last_updated is not None:
elif use_cached_xlog and cached_xlog_location != replaced_xlog_location:
logger.debug("prevented pod update, keeping cached xlog value for up to %d seconds",
(last_updated + self._xlog_cache_ttl - now))

Check failure on line 1373 in patroni/dcs/kubernetes.py

View workflow job for this annotation

GitHub Actions / pyright

Argument type is unknown   Argument corresponds to parameter "args" in function "debug" (reportUnknownArgumentType)

Check failure on line 1373 in patroni/dcs/kubernetes.py

View workflow job for this annotation

GitHub Actions / pyright

Operator "+" not supported for "None" (reportOptionalOperand)

Expand Down

0 comments on commit 1851cfc

Please sign in to comment.