Skip to content

Fix zuiFind crash / RM_ScanKey hang on SET object listpack encoding#11581

Merged
oranagra merged 12 commits intoredis:unstablefrom
enjoy-binbin:zuiFind_support_set_listpack
Dec 9, 2022
Merged

Fix zuiFind crash / RM_ScanKey hang on SET object listpack encoding#11581
oranagra merged 12 commits intoredis:unstablefrom
enjoy-binbin:zuiFind_support_set_listpack

Conversation

@enjoy-binbin
Copy link
Contributor

@enjoy-binbin enjoy-binbin commented Dec 5, 2022

In #11290, we added listpack encoding for SET object.
But forgot to support it in zuiFind, causes ZINTER, ZINTERSTORE,
ZINTERCARD, ZIDFF, ZDIFFSTORE to crash.
And forgot to support it in RM_ScanKey, causes it hang.

This PR add support SET listpack in zuiFind, and in RM_ScanKey.
And add tests for related commands to cover this case.

Other changes:

  • There is no reason for zuiFind to go into the internals of the SET.
    It can simply use setTypeIsMember and don't care about encoding.
  • Remove the #include "intset.h" from server.h reduce the chance of
    accidental intset API use.
  • Move setTypeAddAux, setTypeRemoveAux and setTypeIsMemberAux
    interfaces to the header.
  • In scanGenericCommand, use setTypeInitIterator and setTypeNext
    to handle OBJ_SET scan.
  • In RM_ScanKey, improve hash scan mode, use lpGetValue like zset,
    they can share code and better performance.

The zuiFind part fixes #11578

In redis#11290, we added listpack encoding for SET object,
but forgot to support it in zuiFind. Causing for example
ZDIFF command to act on the SET object, it will crash.

This PR add support SET listpack in zuiFind, and add tests
for related commands to cover this case.

Fixes redis#11578
@enjoy-binbin enjoy-binbin changed the title Fix zuiFind crash on SET object listpack encoding Fix ZDIFF / ZDIFFSTORE crash on zuiFind when SET object listpack encoding Dec 5, 2022
@enjoy-binbin enjoy-binbin changed the title Fix ZDIFF / ZDIFFSTORE crash on zuiFind when SET object listpack encoding Fix zuiFind crash on SET object listpack encoding Dec 5, 2022
Copy link
Contributor

@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.

Thanks @enjoy-binbin for fixing this and thanks @hbina for reporting this issue so it can be fixed before Redis 7.2 is released!

It's embarrassing that I missed this function when I implemented listpack encoding for sets.

enjoy-binbin and others added 4 commits December 5, 2022 18:47
zuiderkwast suggest:
there is no reason for zuiFind to go into the internals of the set. It
can simply use setTypeIsMember and don't care about encoding.

Co-authored-by: Viktor Söderqvist <[email protected]>
Co-authored-by: Viktor Söderqvist <[email protected]>
Copy link
Contributor

@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.

LGTM

@enjoy-binbin enjoy-binbin changed the title Fix zuiFind crash on SET object listpack encoding Fix zuiFind crash / RM_ScanKey hang on SET object listpack encoding Dec 7, 2022
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.

LGTM. any other comments?

Copy link
Contributor

@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.

LGTM

Thanks for doing the extra (slightly unrelated) refactoring! I wouldn't have required it but it's an improvement definitely.

@oranagra
Copy link
Member

oranagra commented Dec 8, 2022

do we wanna take this opportunity and improve the hash scan code to use lpGetValue instead of lpGet?
i don't mind doing it in another PR, but i wanna hammer it now before we forget and move on..

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.

great.
can you please update the top comment to mention the additional changes and their implications (performance)

@oranagra oranagra merged commit 20854cb into redis:unstable Dec 9, 2022
@enjoy-binbin enjoy-binbin deleted the zuiFind_support_set_listpack branch December 9, 2022 23:01
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
…edis#11581)

In redis#11290, we added listpack encoding for SET object.
But forgot to support it in zuiFind, causes ZINTER, ZINTERSTORE,
ZINTERCARD, ZIDFF, ZDIFFSTORE to crash.
And forgot to support it in RM_ScanKey, causes it hang.

This PR add support SET listpack in zuiFind, and in RM_ScanKey.
And add tests for related commands to cover this case.

Other changes:
- There is no reason for zuiFind to go into the internals of the SET.
  It can simply use setTypeIsMember and don't care about encoding.
- Remove the `#include "intset.h"` from server.h reduce the chance of
  accidental intset API use.
- Move setTypeAddAux, setTypeRemoveAux and setTypeIsMemberAux
  interfaces to the header.
- In scanGenericCommand, use setTypeInitIterator and setTypeNext
  to handle OBJ_SET scan.
- In RM_ScanKey, improve hash scan mode, use lpGetValue like zset,
  they can share code and better performance.

The zuiFind part fixes redis#11578

Co-authored-by: Oran Agra <[email protected]>
Co-authored-by: Viktor Söderqvist <[email protected]>
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
…edis#11581)

In redis#11290, we added listpack encoding for SET object.
But forgot to support it in zuiFind, causes ZINTER, ZINTERSTORE,
ZINTERCARD, ZIDFF, ZDIFFSTORE to crash.
And forgot to support it in RM_ScanKey, causes it hang.

This PR add support SET listpack in zuiFind, and in RM_ScanKey.
And add tests for related commands to cover this case.

Other changes:
- There is no reason for zuiFind to go into the internals of the SET.
  It can simply use setTypeIsMember and don't care about encoding.
- Remove the `#include "intset.h"` from server.h reduce the chance of
  accidental intset API use.
- Move setTypeAddAux, setTypeRemoveAux and setTypeIsMemberAux
  interfaces to the header.
- In scanGenericCommand, use setTypeInitIterator and setTypeNext
  to handle OBJ_SET scan.
- In RM_ScanKey, improve hash scan mode, use lpGetValue like zset,
  they can share code and better performance.

The zuiFind part fixes redis#11578

Co-authored-by: Oran Agra <[email protected]>
Co-authored-by: Viktor Söderqvist <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[CRASH] ZINTER betwen SET and ZSET crashes

4 participants