New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure cache gets properly updated with concurrent access for action with attachments #4183
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in principle, left two nits.
@@ -198,23 +198,40 @@ trait DocumentFactory[W <: DocumentRevisionProvider] extends MultipleReadersSing | |||
doc: DocId, | |||
rev: DocRevision = DocRevision.empty, | |||
fromCache: Boolean = cacheEnabled)(implicit transid: TransactionId, mw: Manifest[W]): Future[W] = { | |||
getWithAttachment(db, doc, rev, fromCache, None) | |||
Try { | |||
require(db != null, "db undefined") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should get rid of all of these. Do we ever use null
anywhere?
Try { | ||
require(db != null, "db undefined") | ||
} map { | ||
implicit val logger = db.logging | ||
implicit val ec = db.executionContext | ||
val key = doc.asDocInfo(rev) | ||
_ => | ||
cacheLookup(CacheKey(key), db.get[W](key, attachmentHandler), fromCache) | ||
cacheLookup(CacheKey(key), db.get[W](key, Some(attachmentHandler)) flatMap { postProcess }, fromCache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I find the combinators a bit hard to read
db.get[W](key, Some(attachmentHandler)).flatMap(postProcess)
Is imo a bit clearer.
Codecov Report
@@ Coverage Diff @@
## master #4183 +/- ##
==========================================
- Coverage 86.03% 81.19% -4.85%
==========================================
Files 152 152
Lines 7292 7275 -17
Branches 472 477 +5
==========================================
- Hits 6274 5907 -367
- Misses 1018 1368 +350
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
…with attachments (apache#4183)
@tysonnorris notices with concurrent action invocation scenario that same attachment is being fetched multiple times in case of cache miss.
Description
If multiple request try to load an action with attachment which is not present in cache then currently it leads to multiple request to load the same attachment from backing store. This PR adds a new test which demonstrate this behavior. This test would try to concurrently read action (5 threads). Without fix you would see logs like below which show that attachment is being read multiple times
As a fix now the cache update operation also includes the inline logic. So a cache update would be considered complete only when the action code is also inlined. This ensures even with concurrent reader threads only one thread performs the db access and others make use of the cache
Related issue and scope
My changes affect the following components
Types of changes
Checklist: