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

Initial support of transactions #5

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Initial support of transactions #5

wants to merge 1 commit into from

Conversation

bjosv
Copy link
Collaborator

@bjosv bjosv commented Nov 16, 2020

Handles MULTI, EXEC and DISCARD messages in the pipeline API
using redisClusterAppendCommand()

What the implementation does is that when a MULTI command is received it is not sent directly.
Instead its saved in a queue as normally done as well, but now also keeping its command string that will be sent later.
When the next command is received its slot is extracted, and used for the saved MULTI command as well.
The MULTI command is now sent to the correct node before the first command in the transaction.
When EXEC is sent this finishes the transaction state, and will receive the array of all responses.

Only supports transactions to a single slot
Only supports the pipeline API currently
Support for async and single sync api to be added

Copy link
Collaborator

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

Beautiful! Very nice and simple API.

} else {
__redisClusterSetError(
cc, REDIS_ERR_OTHER,
"No keys in command(must have keys for redis cluster mode)");
Copy link
Collaborator

Choose a reason for hiding this comment

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

These messages are not beautiful, but legacy... Maybe some other time, we can reformulate them.

hircluster.c Outdated
Comment on lines 3268 to 3269
__redisClusterSetError(cc, REDIS_ERR_OTHER,
"only supports same slot transactions");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Who only supports? Better use passive, e.g. "Only same slot transactions supported".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

hircluster.c Outdated
Comment on lines 3273 to 3286
if (cc->transaction_slot == TRANSACTION_STARTED) {
// Previous command was MULTI, use current slot as transaction slot
listNode *prev_command = listLast(cc->requests);
if (prev_command == NULL) {
__redisClusterSetError(cc, REDIS_ERR_OTHER, "transaction failure");
goto error;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can prev_command ever be NULL if we are in TRANSACTION_STARTED? (Maybe after reconnect?)

If it can't happen, maybe this should be an ASSERT instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should not be possible unless there is some fishyness. There are a lot of checks throughout the codebase and many where asserts could be more fitting, like if the clustercontext is null..which is everywhere.
I was thinking that when there are more tests to lean on we could make the internals more strict and assert where applicable

hircluster.c Outdated
// Send MULTI command to correct slot first
if (__redisClusterAppendCommand(cc, multi_command) != REDIS_OK) {
__redisClusterSetError(cc, REDIS_ERR_OTHER,
"transaction fail while sending MULTI");
Copy link
Collaborator

Choose a reason for hiding this comment

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

fail -> failure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

Comment on lines 23 to 29
status = redisClusterAppendCommand(
cc, "SET foo five"); // Not ok due to other slot
assert(status != REDIS_OK);
status = redisClusterAppendCommand(cc, "GET bar");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it aligns better with the rest of the code like this:

    status = redisClusterAppendCommand(cc, "SET foo five");
    assert(status != REDIS_OK); // Not ok due to other slot

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

Handles MULTI, EXEC and DISCARD messages in the pipeline API
using `redisClusterAppendCommand()`

Only supports transactions to a single slot
@metal3-io-bot
Copy link
Member

@bjosv: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants