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

Multi get and consistend hashing #1

Merged
merged 16 commits into from
Mar 26, 2021
Merged

Conversation

blackmad
Copy link

@blackmad blackmad commented Mar 24, 2021

Implement multi/pipelined get in memjs in what I think is the least intrusive way possible, using almost all of their existing abstractions. Didn't want to do a big TS rewrite, or es6 upgrade, etc etc. If we keep doing surgery on this library I think we try to get this merged as in, and then separately try to bring the project up to vanilla es6, and then maybe typescript.

Based on: https://github.com/couchbase/memcached/blob/master/docs/BinaryProtocol.md#0x0d-getkq-get-with-key-quietly
Clients should implement multi-get (still important for reducing network roundtrips!) as n pipelined requests, the first n-1 being getq/getkq, the last being a regular get/getk. That way you're guaranteed to get a response, and you know when the server's done. You can also do the naive thing and send n pipelined get/getks, but then you could potentially get back a lot of "NOT_FOUND" error code packets. Alternatively, you can send 'n' getq/getkqs, followed by a 'noop' command.

This takes the last option because I thought it was the clearest. Uses the same hashing library (hashring) as the official client.

Minor things to note

  • 24 is a magic number everywhere, it's the size of the memcache request header (and the smallest op as well - no-op)
  • memcache is not the same as redis
  • the bufferify() helper checks if something is already a buffer and doesn't re-encode if it is (some new code in utils.js takes advantage of this)

@justjake
Copy link

as the official client

Source? What is this referencing?

@blackmad
Copy link
Author

blackmad commented Mar 24, 2021 via email

Copy link

@justjake justjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks really, really good. Your buffer handling changes took a bit to sink in but make things more understandable overall. The getMulti internals look good too. What do you think about the tradeoff of using the same seq number for each key, VS using a different seq number for each pipelined request, and doing all the merging and result accumulation in latchCallback?

lib/memjs/memjs.js Outdated Show resolved Hide resolved
lib/memjs/memjs.js Outdated Show resolved Hide resolved
lib/memjs/memjs.js Outdated Show resolved Hide resolved
lib/memjs/memjs.js Outdated Show resolved Hide resolved
lib/memjs/memjs.js Outdated Show resolved Hide resolved
lib/memjs/memjs.js Outdated Show resolved Hide resolved
lib/memjs/utils.js Outdated Show resolved Hide resolved
lib/memjs/utils.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved

if (err) {
hadError = true;
callback(err, null, null);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what cases does err cover? Is it connection errors, parsing errors, or does it include the server replying "hey we don't have this key"?
a) comment here might be good about this
b) could we ever want to return a partially filled recordMap?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add comment

err is just thrown errors - missing key is not an error (also, we are using "getkq - get key quiet" which doesn't even reply on missing key)

re: returning a partially filled recordMap - thought about this one some and ... I think no? it seems really unpredictable if you're calling five memcache backends and one goes bad, maybe the bad one replies first and this is empty, or the bad one replies last and it's mostly full, would the client really want to deal with that ... hmmm ... I mean, there's no harm in passing the recordMap back here and the client can choose if they want to use it? okay fine, yes

Copy link

@justjake justjake Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I think you’re right that it’s weird to return inconsistently complete stuff.

@blackmad
Copy link
Author

re: "What do you think about the tradeoff of using the same seq number for each key, VS using a different seq number for each pipelined request, and doing all the merging and result accumulation in latchCallback?" - thought about this last night and it seems harder in that case to clear the handlers after the case if there's an error in the middle? would require a bunch more accounting and I think it would make server <-> client a leakier abstraction

@blackmad blackmad requested a review from justjake March 25, 2021 16:30
Copy link

@justjake justjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!!!

lib/memjs/constants.js Outdated Show resolved Hide resolved
lib/memjs/memjs.js Show resolved Hide resolved
}
break;
case 1:
if (callback) { callback(null, null, null); }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this get called only once for the NO_OP, or can it get called multiple times for getkq responses after the server gets the no-op?

lib/memjs/memjs.js Outdated Show resolved Hide resolved
lib/memjs/memjs.js Outdated Show resolved Hide resolved
@blackmad blackmad force-pushed the multiGetAndConsistendHashing branch from ec12da0 to 68c504a Compare March 26, 2021 12:53
@blackmad blackmad merged commit 8b67064 into master Mar 26, 2021
@blackmad blackmad deleted the multiGetAndConsistendHashing branch March 26, 2021 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants