Repository navigation
fix(cache): keep chords alive past result_expires - #10830
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10830 +/- ##
==========================================
+ Coverage 90.47% 90.49% +0.01%
==========================================
Files 153 153
Lines 21277 21294 +17
Branches 2590 2593 +3
==========================================
+ Hits 19251 19270 +19
+ Misses 1710 1709 -1
+ Partials 316 315 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
MehrazRumman
left a comment
There was a problem hiding this comment.
I checked this out and ran it against main. To test it end to end without memcached, I used a real in-process worker with the cache backend and a client that expires keys the way memcached does (TTL, 0 = never, touch, incr on a missing key returning None). The chord had three 1.5 s tasks and result_expires=1.
result_chord_expires |
main | this PR |
|---|---|---|
| not set | body never runs | body never runs (unchanged) |
60 |
body runs | |
0 |
body runs |
So the fix works, but only when the setting is set. Without it nothing changes, which is a reasonable default. The docs for chords and result_expires should point to the new setting, since that is where people hitting #4207 will look. The new cache unit tests fail on main and pass here, and the rest of test_cache.py / test_base.py passes.
1. With result_chord_expires=0, header results never expire
on_chord_part_return() refreshes each finished header result with 0 if not expires or not self.expires else max(...). With result_chord_expires=0 that is touch(key, 0), so in memcached every header result except the last one is kept forever, until it is evicted. After the chord above finished, two of the three header results had no expiry left.
With 60 the header results stay about 60 s after the chord finishes instead of result_expires (1 s here). That part is documented, but it is still longer than needed once the body has started.
The docs describe 0 as "the chord's bookkeeping never expires while the chord is open", which does not cover this. Giving the header results their normal lifetime back when the chord completes fixes both cases:
finally:
deps.delete()
self.delete(key)
if self._chord_expires is not None:
# The chord is done: give the header results back their
# normal lifetime instead of the chord's.
for dep in deps.results:
self.expire(self.get_key_for_task(dep.id), self.expires)With this, the body still runs for both 60 and 0, all header results end up with result_expires (1 s) after the chord finishes, and the same unit tests pass.
2. Redis: _set_chord_key() skips RedisBackend.set()
The complex-header group record used to go through header_result.save(), so through RedisBackend.set(). Now it calls client.set() directly. That drops the _MAX_STR_VALUE_SIZE check: a header too large for Redis used to raise BackendStoreError('value too large for Redis backend') and now goes straight to Redis. It also drops the publish(), which is harmless because nothing subscribes to group keys. Keeping the size check in _set_chord_key() would keep the old error.
3. Order with #10827
This branch carries the Redis commit from #10827 (2a218d9, "fix(redis): add result_chord_expires for chord keys"). If both stay open, it would help to merge #10827 first and rebase this on top, so the cache part can be reviewed on its own.
Minor
- The integration tests check what you intend, but they only run in the
cacheandredistox environments. It would be worth confirming in CI thattest_chord_expiresactually runs rather than skips. - The memcached 30-day note is important. Maybe also log a warning in the cache backend when
result_chord_expiresis over 30 days, since memcached then treats it as an absolute timestamp and the keys expire immediately.
|
@MehrazRumman thanks for the initial review, may be it would be better if you could review this first #10827 as this pr is the base. although some review comments are valid for this first pr already. |
|
I've merged the #10827 changes into this branch and fixed the header results. When a chord finishes, every header result gets The cache backend also logs a warning at startup when About CI: the integration workflow skips the new memcached test, because it has no memcached service. The smoke suite does run memcached, so I added a test there with a chord whose tasks outlive |
auvipy
left a comment
There was a problem hiding this comment.
please fix the merge conflicts
auvipy
left a comment
There was a problem hiding this comment.
please fix the merge conflicts again
|
Merged |
Description
Follow-up to #10827 that fixes #4207 for the memcached backend. This builds on #10827
On the cache backend, a chord's group record and its header results only live for
result_expires. If the chord runs longer than that, the body never runs. With 5.7.0b1, a chord of three 3-second tasks andresult_expires=1fails every time.This makes the cache backend use
result_chord_expirestoo:result_expires.Redis avoids the problem by copying the results into one key. I didn't do that here, because memcached caps an item at 1 MB by default and large chords that work today would break.
If the setting isn't set, the only change is a few extra
touchcalls. DynamoDB and GCS share this code but don't implementexpire, so they aren't affected.