Skip to content

Add check min-slave-* feature when evaluating Lua scripts and Functions#10160

Merged
oranagra merged 10 commits intoredis:unstablefrom
noradomi:scripting-min-slave-to-write-check
Feb 3, 2022
Merged

Add check min-slave-* feature when evaluating Lua scripts and Functions#10160
oranagra merged 10 commits intoredis:unstablefrom
noradomi:scripting-min-slave-to-write-check

Conversation

@noradomi
Copy link
Contributor

@noradomi noradomi commented Jan 21, 2022

What problem does this PR solve?

Reference this issue:: #9993
Currently, there is no check min-slave-* config when evaluating Lua script.

Before the fix:

127.0.0.1:7000> eval "return redis.call('set','P','value')" 0
OK

After the fix:

127.0.0.1:7000> eval "return redis.call('set','P','value')" 0
(error) ERR Error running script (call to d05e85801446f5c3b3262aa9928ebf556baf9d64): @user_script:1: @user_script: 1: -NOREPLICAS Not enough good replicas to write.

Check List

Tests

  • Tests added in integration-4.tcl.

Code changes

Add check enough good slaves for write command when evaluating scripts.
This check is made before the script is executed, if we have function flags, and per redis command if we don't.

To Do

  • in functions or eval with shebang, unless no-writes flags is set prevent the script from running in the first place

@anhldbk
Copy link

anhldbk commented Jan 24, 2022

@oranagra PTAL

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

The fix LGTM (@MeirShpilraien PTAL).

maybe there's a way to combine these tests with existing tests that check this mechanism?
i.e. there are already tests that set up this state, and check normal redis commands, so all we need is to add an additional check for a script.

@MeirShpilraien
Copy link

@oranagra change looks good but I wonder if maybe we should not even run the script in such case unless no-writes flags is set (then we need this fix only for Lua script that do not use the flags for backward compatibility). WDYT?

@anhldbk
Copy link

anhldbk commented Jan 25, 2022

@oranagra can this PR be merged into the latest 6.x branch?

@oranagra
Copy link
Member

@MeirShpilraien i agree, we should have both checks, one when we know the write flag in advance, and one when we don't.
in theory, the second check could be bad since it can break the atomicity of the script, but in fact the replicas state can't change during the execution of the script, so either it'l reject the very first write, or none.

@anhldbk @noradomi we're currently in the process of releasing 7.0 RC1 and are busy with other things (which is why i didn't review it for a while).
regarding 6.x, since 7.0 (unstable) has a lot of changes around this area, backporting a commit isn't trivial.
i suggest that after this one is merged, we'll make a separate PR against the 6.2 branch.

@noradomi
Copy link
Contributor Author

@oranagra maybe there's a way to combine these tests with existing tests that check this mechanism?

  • yeap, I refactored tests and combined these tests with existing tests for both normal commands and scripting.

@oranagra
Copy link
Member

@noradomi i added a TODO at the top, let me know if you're up to it, if not, we can open a separate issue.

@noradomi
Copy link
Contributor Author

@oranagra Sorry for the late reply, about the TODO, I haven't done it yet. So I think you can open another issue for it and I will try to contribute when I clearly understand the context about it. (ex: functions, no-scripts flag ?)

@anhldbk
Copy link

anhldbk commented Jan 28, 2022

@noradomi LGTM.

@anhldbk
Copy link

anhldbk commented Jan 29, 2022

@oranagra LGTY?

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

fix and tests LGTM.
as i noted (in the todo i added to the top), there's more to do in order to make this complete.
i'll look into it after 7.0 RC1 is released.

@oranagra
Copy link
Member

oranagra commented Feb 1, 2022

@MeirShpilraien please review my last commit.

anyone wanna make a PR for redis 6.2 branch?

@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Feb 1, 2022
Copy link

@MeirShpilraien MeirShpilraien left a comment

Choose a reason for hiding this comment

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

Looks good (small comment, not a blocker).

Co-authored-by: Meir Shpilraien (Spielrein) <[email protected]>
@oranagra oranagra changed the title Add check min-slave-* feature when evaluating Lua script Add check min-slave-* feature when evaluating Lua scripts and Functions Feb 3, 2022
@oranagra oranagra merged commit 53c43fc into redis:unstable Feb 3, 2022
@anhldbk
Copy link

anhldbk commented Feb 7, 2022

@noradomi pls make another PR for branch 6.2

@anhldbk
Copy link

anhldbk commented Feb 7, 2022

Thank you @oranagra @MeirShpilraien. You make my day.

@noradomi
Copy link
Contributor Author

noradomi commented Feb 7, 2022

@noradomi pls make another PR for branch 6.2

yes, I will. Thanks @oranagra @MeirShpilraien for your time.

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

Labels

release-notes indication that this issue needs to be mentioned in the release notes

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] Config min-slaves-to-write is not worked with Lua scripts

4 participants