Skip to content
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

Merged
merged 2 commits into from
Sep 29, 2023
Merged

Add getMultiWithErrors #17

merged 2 commits into from
Sep 29, 2023

Conversation

schleyfox
Copy link

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)


const usedServerKeys = Object.keys(serverKeytoLookupKeys);
const errors: GetMultiError<Keys>[] = [];
const results = await Promise.all(

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?

Copy link
Author

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

Copy link

@leon-root leon-root left a 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.

@schleyfox
Copy link
Author

@leon-root added tests and updated branch. Let me know if it looks good on your end.

@leon-root
Copy link

@leon-root added tests and updated branch. Let me know if it looks good on your end.

Tested on my side and works fine.
But I cannot simulate different Error cases.
I tested:

  • stop the container, got error: Error: connect ECONNREFUSED 127.0.0.1:11222
  • Add network delay of 1500ms, set command timeout to 1000ms. Working good.

@schleyfox schleyfox merged commit 7010678 into master Sep 29, 2023
1 check passed
@schleyfox schleyfox deleted the benjamin-getmultiwitherrors branch September 29, 2023 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants