Repository navigation
Conversation
Hello delthas,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
... and 5 files with indirect coverage changes
@@ Coverage Diff @@
## development/9.6 #2939 +/- ##
================================================
Coverage 81.76% 81.76%
================================================
Files 217 217
Lines 46363 46400 +37
================================================
+ Hits 37907 37940 +33
- Misses 8456 8460 +4
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Request integration branchesWaiting for integration branch creation to be requested by the user. To request integration branches, please comment on this pull request with the following command: Alternatively, the |
dc70f4c to
5970a46
Compare
9436bd2 to
1110f61
Compare
DarkIsDude
left a comment
There was a problem hiding this comment.
We are missing a use case I guess ? With secondary (that we can have in an Artesca config?).
Still broken (lagging secondary)
- Bucket b changes from A to B on the primary.
- The change stream handler gets the event, sees b isn't cached, and does nothing. No lookup is pending, so there's nothing to flag.
- getConfig(b) misses the cache and adds L1 to pending[b].
- findOne(b) goes to a secondary that hasn't replicated the change yet and returns A.
- L1.changed is false, so getConfig(b) caches A. ✗
Now I have a weird feeling with this PR. IMO we have a more deeper problem of responsability and we are trying to put a patch when we should think bigger ?
The change stream handler only refreshes cached buckets. When a bucket's configuration changed while its lookup was in flight, the handler skipped it, and the lookup then cached what it read before the change: a stale configuration, or since BB-908 a stale absence of one, kept until the bucket changes again or is evicted. Track the lookups in flight per bucket, have the handler flag those of the bucket that changed, and return their result without caching it, so that the next entry reads it again. Also read the configuration from the primary, whatever the configured read preference: the change stream reports majority-committed changes, so a lookup started after a change was handled could otherwise still read the previous configuration from a lagging secondary, and cache it. Issue: BB-939
1110f61 to
516acfc
Compare
We technically can have a read preference for secondary set up in Zenko but ARTESCA never sets any. Still, this can indeed cause the issue you listed, so I'm adding an explicit "primary" read preference to the |
I see what you mean with 1 job filling the cache and 1 job emptying it. But we can't just have the changestream populate the cache, since we're trying to keep it LRU (least recently used, others are dropped) with a cap. The easy and "clean" solution would be to create a whole cache of all the configurations of all the buckets but this wouldn't work for a large XDM type install. So I'd say take the fix and no bigger change for now. |
|
Also adding @francoisferrand for an additional eye on this |
Hand written, please read 🙂
The bucket notification handler receives a stream of events and sends notifications according to what the bucket notification configuration says.
So when it receives an event, it must lookup the bucket notification configuration. We have added (and recently improved) a cache for the configurations.
But there is a subtle race when the two happen at once:
When we're unlucky, we cache miss, fetch, during the fetch the value changes from A to B, but we store A in the cache and never update it again. The code that's supposed to delete the cached value when we receive B does it before we store A. Race lost.
This fixes it by having a map of pending configuration lookups by bucket. When a bucket changes while lookups are ongoing, we tell the lookups not to store the value they fetched, because it is stale. It can then be re-fetched later. Race avoided.
Before:
sequenceDiagram participant G as getConfig(b) participant M as metastore participant H as change stream handler participant C as cache G->>C: get(b): miss G->>M: findOne(b), reads config A H->>C: b changed to B: b not cached, skipped M-->>G: config A G->>C: add(b, A), stale until b changes againAfter:
sequenceDiagram participant G as getConfig(b) participant M as metastore participant H as change stream handler participant P as pendingLookups participant C as cache G->>C: get(b): miss G->>P: add lookup of b, changed: false G->>M: findOne(b), reads config A H->>P: b changed to B: flag lookup, changed: true M-->>G: config A G->>P: remove lookup of b Note over G,C: changed: return A, not cached, the next lookup reads BIssue: BB-939