Skip to content

Conversation

@CharlesChen888
Copy link
Contributor

@CharlesChen888 CharlesChen888 commented Nov 7, 2022

To resolve #11409

When no-touch mode is enabled, the client will not touch LRU/LFU of the keys it accesses, except when executing command TOUCH.
This allows inspecting or modifying the key-space without affecting their eviction.

Changes:

  • A command CLIENT NO-TOUCH ON|OFF to switch on and off this mode.
  • A client flag #define CLIENT_NOTOUCH (1ULL<<45), which can be shown with CLIENT INFO, by the letter "T" in the "flags" field.
  • Clear NO-TOUCH flag in clearClientConnectionState, which is used by RESET command and resetting temp clients used by modules.
  • Also clear NO-EVICT flag in clearClientConnectionState, this might have been an oversight, spotted by @madolson.
  • A test using DEBUG OBJECT command to verify that LRU stat is not touched when no-touch mode is on.

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.

Cool feature.

If found one more call to lookupKeyReadWithFlags without the NOTOUCH flag, in blocked.c, function handleClientsBlockedOnKeys:

            /* Serve clients blocked on the key. */
            robj *o = lookupKeyReadWithFlags(rl->db, rl->key, LOOKUP_NONOTIFY | LOOKUP_NOSTATS);

What do you think about this one? If the key just became ready, it must have just been written and therefore just touched, so touching it again doesn't hurt? But then we could as well add the NOTOUCH flag here...

Copy link
Contributor

@madolson madolson left a comment

Choose a reason for hiding this comment

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

Would you mind adding a simple test that it works? Probably in unit/introspection-2

@CharlesChen888
Copy link
Contributor Author

CharlesChen888 commented Nov 8, 2022

If found one more call to lookupKeyReadWithFlags without the NOTOUCH flag, in blocked.c, function handleClientsBlockedOnKeys:

            /* Serve clients blocked on the key. */
            robj *o = lookupKeyReadWithFlags(rl->db, rl->key, LOOKUP_NONOTIFY | LOOKUP_NOSTATS);

What do you think about this one? If the key just became ready, it must have just been written and therefore just touched, so touching it again doesn't hurt? But then we could as well add the NOTOUCH flag here...

This is where I got confused. The robj *o we get here seems not just for reading. For instance, when a client is blocked when executing BLPOP, a LPOP is going to be performed to the key which becomes ready.

@soloestoy
Copy link
Contributor

If found one more call to lookupKeyReadWithFlags without the NOTOUCH flag, in blocked.c, function handleClientsBlockedOnKeys:

            /* Serve clients blocked on the key. */
            robj *o = lookupKeyReadWithFlags(rl->db, rl->key, LOOKUP_NONOTIFY | LOOKUP_NOSTATS);

What do you think about this one? If the key just became ready, it must have just been written and therefore just touched, so touching it again doesn't hurt? But then we could as well add the NOTOUCH flag here...

This is where I got confused. The robj *o we get here seems not just for reading. For instance, when a client is blocked when executing BLPOP, a LPOP is going to be performed to the key which becomes ready.

this is introduce by #9572, do you remember why change it from lookup write to read @zuiderkwast ?

BTW, every time I see writable replica I still have to say I hate it, it messes things up.

@zuiderkwast
Copy link
Contributor

this is introduce by #9572, do you remember why change it from lookup write to read @zuiderkwast ?

@soloestoy (regarding the lookup in lookupKeyReadWithFlags) I don't remember why but I guess we changed it to preserve the old behaviour when we changed lookupKey. Anyway, this lookup is not a normal lookup since it's not for a specific client. Later, each key will be looked up again for a specific client and command. Let's just add NOTOUCH here (or change it so it doesn't use lookupKey at all).

Btw, I don't want to talk about writeable replicas. They're not fun. 😁

@soloestoy
Copy link
Contributor

soloestoy commented Nov 16, 2022

If the key just became ready, it must have just been written and therefore just touched, so touching it again doesn't hurt? But then we could as well add the NOTOUCH flag here...

but if it's lfu, we should touch the object to increase the frequency...

Anyway, this lookup is not a normal lookup since it's not for a specific client. Later, each key will be looked up again for a specific client and command. Let's just add NOTOUCH here (or change it so it doesn't use lookupKey at all).

I don't get your point about "each key will be looked up again for a specific client and command", for example BLPOP will use the object directly without look up it again.

@zuiderkwast
Copy link
Contributor

I don't get your point about "each key will be looked up again for a specific client and command", for example BLPOP will use the object directly without look up it again.

@soloestoy You're right... but blockingPopGenericCommand calls lookupKeyWrite before blocking the client.

BLPOP only blocks if the key doesn't exist though. If the key is created by another client using LPUSH, there is no LRU/LFU stored when our client is unblocked. I guess we do want to increment LRU/LFU for BLPOP when popping...

@CharlesChen888
Copy link
Contributor Author

CharlesChen888 commented Nov 16, 2022

So regarding the lookupKeyReadWithFlags in handleClientsBlockedOnKeys, I guess we can leave it unchanged here. If we do need to pass a NOTOUCH flag in it, we can discuss it in #11012, as it is refactoring blocking framework.

@CharlesChen888
Copy link
Contributor Author

CharlesChen888 commented Nov 16, 2022

Just had another thought: in the orginal issue #11409, we only need a stealth/no-touch mode for read operations, but should we limit it in read operations? Or is it ok to perform write operations without touching LRU/LFU stats?

If stealth/no-touch mode can also apply to write operations, it is easier to implement.

@madolson WDYT?

@zuiderkwast
Copy link
Contributor

should we limit it in read operations? Or is it ok to perform write operations without touching LRU/LFU stats?

Is it useful or confusing?

If stealth mode is a kind of super-readonly mode that shouldn't do any changes to keys, then we should probably return an error for write commands. If it is a useful hack for administrators, then we can allow no-touch for write operations too...

@CharlesChen888 CharlesChen888 changed the title Add client stealth mode for not changing LRU/LFU stats when performing read operations. Add client no-touch mode for not changing LRU/LFU stats when looking up keys. Nov 17, 2022
@CharlesChen888 CharlesChen888 requested review from madolson and oranagra and removed request for madolson and oranagra November 18, 2022 08:15
@madolson
Copy link
Contributor

madolson commented Dec 7, 2022

Discussed in the core meeting. Discussion was to decouple the stealth mode conversation, and proceed with this PR as is. Folks should take a look shortly.

@madolson
Copy link
Contributor

madolson commented Jan 5, 2023

@soloestoy Do you still plan on following up on this? I can help close on this if you are busy.

@soloestoy
Copy link
Contributor

soloestoy commented Jan 5, 2023

@madolson @oranagra seems this PR is finished? as the top comment said.

@soloestoy
Copy link
Contributor

@madolson @oranagra please approve, I think it's ready to be merged.

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.

sorry for the long delay. forgot about it....
mostly LGTM, here are some minor comments.

Copy link
Contributor

@madolson madolson left a comment

Choose a reason for hiding this comment

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

Minor comments as well, looks OK to me.

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

@CharlesChen888 can you please make a redis-doc PR as well?

@CharlesChen888
Copy link
Contributor Author

@oranagra of course, I'm already writing it.

@oranagra oranagra added the state:needs-doc-pr requires a PR to redis-doc repository label Feb 20, 2023
@oranagra
Copy link
Member

i wonder if we should mention the change about NO-EVICT in the docs somewhere?
i.e. it should be mentioned as a behavior change in the release notes, and it doesn't belong in the command's history section (not an interface change).
it means that 7.0 and 7.2 will behave differently in that regard, but we don't usually document bug fixes in the docs..

Co-authored-by: sundb <sundbcn@gmail.com>
@CharlesChen888
Copy link
Contributor Author

i wonder if we should mention the change about NO-EVICT in the docs somewhere? i.e. it should be mentioned as a behavior change in the release notes, and it doesn't belong in the command's history section (not an interface change). it means that 7.0 and 7.2 will behave differently in that regard, but we don't usually document bug fixes in the docs..

@oranagra I think we need to doc the change of RESET command anyway (for clearing no-touch flag), so just mention it alongside of no-touch?

@oranagra
Copy link
Member

@CharlesChen888 my question was about documenting the history. i.e. mention that in redis 7.0 we didn't reset the no-evict and in 7.2 we do..
i guess we shouldn't do that, and we will certainly mention the change in the release notes.

@oranagra oranagra changed the title Add client no-touch mode for not changing LRU/LFU stats when looking up keys. Add CLIENT NO-TOUCH to allow clients to inspect or modify keys without affecting LRU/LFU Feb 23, 2023
@oranagra oranagra changed the title Add CLIENT NO-TOUCH to allow clients to inspect or modify keys without affecting LRU/LFU Add CLIENT NO-TOUCH for clients to run commands without affecting LRU/LFU of keys Feb 23, 2023
@oranagra oranagra merged commit 897c3d5 into redis:unstable Feb 23, 2023
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Feb 23, 2023
CLIENT NO-TOUCH added in redis#11483, but forgot to add the since
field in the JSON file. This PR adds the since field to it
with a value of 7.2.0
oranagra pushed a commit that referenced this pull request Feb 23, 2023
CLIENT NO-TOUCH added in #11483, but forgot to add the since
field in the JSON file. This PR adds the since field to it
with a value of 7.2.0
enjoy-binbin pushed a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
…/LFU of keys (redis#11483)

When no-touch mode is enabled, the client will not touch LRU/LFU of the
keys it accesses, except when executing command `TOUCH`.
This allows inspecting or modifying the key-space without affecting their eviction.

Changes:
- A command `CLIENT NO-TOUCH ON|OFF` to switch on and off this mode.
- A client flag `#define CLIENT_NOTOUCH (1ULL<<45)`, which can be shown
  with `CLIENT INFO`, by the letter "T" in the "flags" field.
- Clear `NO-TOUCH` flag in `clearClientConnectionState`, which is used by `RESET`
  command and resetting temp clients used by modules.
- Also clear `NO-EVICT` flag in `clearClientConnectionState`, this might have been an
  oversight, spotted by @madolson.
- A test using `DEBUG OBJECT` command to verify that LRU stat is not touched when
  no-touch mode is on.
 

Co-authored-by: chentianjie <chentianjie@alibaba-inc.com>
Co-authored-by: Madelyn Olson <34459052+madolson@users.noreply.github.com>
Co-authored-by: sundb <sundbcn@gmail.com>
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
CLIENT NO-TOUCH added in redis#11483, but forgot to add the since
field in the JSON file. This PR adds the since field to it
with a value of 7.2.0
oranagra pushed a commit to redis/redis-doc that referenced this pull request Oct 24, 2023
no-evict added in redis/redis#8687
no-touch added in redis/redis#11483

Co-authored-by: Binbin <binloveplau1314@qq.com>
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 state:needs-doc-pr requires a PR to redis-doc repository

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[NEW] Perform a GET without changing the idletime

7 participants