-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add getMultiWithErrors #17
Conversation
|
||
const usedServerKeys = Object.keys(serverKeytoLookupKeys); | ||
const errors: GetMultiError<Keys>[] = []; | ||
const results = await Promise.all( |
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.
in case of error, will results contains undefined for the keys or missing?
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.
results will be an array of partial results and undefineds, so if we had 3 keys foo, bar, and baz on different servers and the server for bar failed, we'd get:
[{foo: {value: "1", extras: "", cas: "token"}},
undefined,
{baz: {value: "2", extras: "", cas: "token"}]
This would be unpacked/coalesced by Object.assign({}, ...results)
to yield
{
foo: {value: "1", extras: "", cas: "token"},
baz: {value: "2", extras: "", cas: "token"}
}
from looking at the code/types, I think if bar were a cache miss instead of a failure we'd get
[{foo: {value: "1", extras: "", cas: "token"}},
{},
{baz: {value: "2", extras: "", cas: "token"}]
which would yield the same result
but I would need to verify and test
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.
Seems working, but need some testing. Change memjs is risky, we need lots of test code.
@leon-root added tests and updated branch. Let me know if it looks good on your end. |
Tested on my side and works fine.
|
if a single cache node involved in a
getMulti
call fails/times out, the whole batch errors out. The alternative is to treat the failure as a cache miss and return the partial result. We want information on the failures so that we can monitor, react, and/or circuit break on our end.This is untested. If we want to go in this direction, we can add tests and clean up (it's also possible to implement getMulti in terms of getMultiWithErrors to remove the code duplication)