Skip to content

Conversation

@jhelbaum
Copy link
Contributor

@jhelbaum jhelbaum commented Jan 3, 2022

This is a followup to #9656 and implements the following step mentioned in that PR:

  • When possible, extract all the help and completion tips from COMMAND DOCS (Redis 7.0 and up)
  • If COMMAND DOCS fails, use the static help.h compiled into redis-cli.
  • Supplement additional command names from COMMAND (pre-Redis 7.0)

The last step is needed to add module command and other non-standard commands.

This PR does not change the interactive hinting mechanism, which still uses only the param strings to provide somewhat unreliable and inconsistent command hints (see #8084). That task is left for a future PR.

@oranagra
Copy link
Member

oranagra commented Jan 3, 2022

thanks for your PR.. started looking at it..
i now realize that deleting help.h would mean that new redis-cli will be unable to provide any hints when connected to old servers (in the past it just used to provide the wrong hings).
one alternative is to keep the old help.h just for use in old servers
but that would probably complicate the code, and also, i suppose it'll mean we'll have to keep the old help.h forever.
anyone has any other ideas before we embrace that "limitation"?

@jhelbaum
Copy link
Contributor Author

jhelbaum commented Jan 3, 2022

Right - that would mean keeping the existing help.h mechanism as a fallback for when COMMAND returns the old format. Basically, keep all the code this PR deletes, behind a conditional. We could keep it for a predefined transition period, until the old server version is no longer supported. But sure, it would complicate the code.

@oranagra
Copy link
Member

oranagra commented Jan 3, 2022

ok. i don't like it.. but just wanted to raise it.

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.

@jhelbaum i did a sloppy initial review (only looking at the diff, without being familiar of the code that uses it).
can't afford to spend much more time on that right now, so i figured raw feedback is better than nothing.

@guybe7
Copy link
Collaborator

guybe7 commented Jan 4, 2022

for the record, i guess it's not so bad if a new redis-cli doesn't show hints when running with an old redis server (I would imagine the more common case is an old redis-cli with an new redis-server)

@oranagra
Copy link
Member

oranagra commented Jan 4, 2022

i'm not sure that's right.. someone managing many redis servers, will maybe update his redis-cli but keep using it for both old and new servers.

@oranagra
Copy link
Member

@jhelbaum FYI, #10056 was merged.

@jhelbaum
Copy link
Contributor Author

Can redis-cli assume that COMMAND INFO and COMMAND DOCS return the commands in the same order? It would simplify the code.

@oranagra
Copy link
Member

currently that's the case, and i can't think of any reason why the implementation could be changed in a way that'll break that.
i.e. both commands recursively run on the same dict.
that said, it seems like an invalid assumption to make (each command has it's own documented semantics, but they have nothing to do with each other, formally)

@jhelbaum
Copy link
Contributor Author

COMMAND INFO is not necessary for this purpose. The code now only calls COMMAND DOCS, which has all the relevant information for the help strings.

@oranagra
Copy link
Member

@jhelbaum forgive me for the luck of focus. what's the status here?
ready for merge?

@jhelbaum
Copy link
Contributor Author

jhelbaum commented Jan 25, 2022 via email

@oranagra
Copy link
Member

I'll give it another review.. just wasn't sure there are still changes pending or it's ready from your side.
there are some tests in tests/integration/redis-cli.tcl but I i'm not sure if the infrastructure can serve for our purpose here.
and also, i suppose manual testing is enough for this feature, not sure we need regression tests.

@jhelbaum
Copy link
Contributor Author

Another thought: Presumably in a separate PR, would anyone object to breaking this up into multiple files? 8800 lines is a bit much much for one source file.

@oranagra
Copy link
Member

i agree. but i don't see a point in just breaking it up in a PR that does only that..
we should do some major revamp in it some day, maybe even split it into multiple tools, or multiple units bundled in one tool.
i don't have a concrete idea. just agree that what we currently have is a mess.

@jhelbaum
Copy link
Contributor Author

jhelbaum commented Feb 4, 2022

Okay, I've reinstated the static help.h file for use with pre-7.0 servers, along with the code that generates the help tables from it.

I still can't figure out why some of the tests are timing out. Any leads in investigating the problem would be appreciated.

Testing integration/redis-cli
[TIMEOUT]: clients state report follows.
sock55d1e5c59510 => (IN PROGRESS) Interactive CLI: INFO response should be printed raw

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.

just a quick skim though the recent changes.

@oranagra
Copy link
Member

oranagra commented Feb 4, 2022

I can't figure out why the test hangs on GH actions (it passes locally).
@yossigo maybe you can figure it out?

@jhelbaum
Copy link
Contributor Author

jhelbaum commented Feb 4, 2022

It's been broken since at least 896dad5

@oranagra
Copy link
Member

oranagra commented Feb 4, 2022

it was actually easy to reproduce locally if using the same make line as the one the CI uses.
the test hang because redis-cli crashed on SIGABRT because realloc was called with a bad address.

@oranagra
Copy link
Member

oranagra commented Feb 4, 2022

p.s. zrealloc uses realloc, but has this in smalloc.c:

#define realloc(ptr,size) je_realloc(ptr,size)

so when you call realloc from redis-cli.c, it uses libc allocator.
but if you debug this with make valgrind or any system that doesn't use jemalloc by default, then both use libc, which is why it didn't reproduce locally for you.

@jhelbaum
Copy link
Contributor Author

jhelbaum commented Feb 4, 2022 via email

@oranagra
Copy link
Member

oranagra commented Feb 5, 2022

Maybe we should automatically hide suggestions based on version?
I.e. Send HELLO or INFO at startup, and use the version to hide irrelevant suggestions?
or maybe we should remove commands and args that are newer than 6.2 from help.h when generating it?
The first option is nicer, but not sure how much effort we wanna invest in old version support (since in versions newer than 7, it'll happen automatically since we use command DOCS)

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.

for the record, some tests i did (with valgrind).

  • run it against latest server and against old server.
  • added to both servers some commands that don't exist in help.h, and verified they show in help and in completion hints.
  • run it with and without -3
  • verified the help @<cat> is working

the only problem i could spot (which may not be an issue), is that when using help.h (on old server) we show the since field, but when using COMMAND DOCS (new server) we don't.
it's logical since when we use COMMAND DOCS we show only the ones actually supported.
but since the users can't distinguish between these modes, i now think it'll be nicer to show it in both modes.

@oranagra oranagra merged commit 5b17909 into redis:unstable Feb 5, 2022
@jhelbaum jhelbaum deleted the cli-help-strings branch February 6, 2022 13:48
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Feb 7, 2022
Because SENTINEL DEBUG missing summary in its json file,
with the change in redis#10043, the following assertion will fail.
```
[redis]# src/redis-cli -p 26379
redis-cli: redis-cli.c:678: cliInitCommandHelpEntry: Assertion `reply->type == 1' failed.
```

This commit add the summary and complexity for SENTINEL DEBUG,
which introduced in redis#9291, and also improved the help message.
oranagra pushed a commit that referenced this pull request Feb 7, 2022
…ry (#10250)

Fix redis-cli with sentinel crash due to SENTINEL DEBUG missing summary

Because SENTINEL DEBUG missing summary in its json file,
with the change in #10043, the following assertion will fail.
```
[redis]# src/redis-cli -p 26379
redis-cli: redis-cli.c:678: cliInitCommandHelpEntry: Assertion `reply->type == 1' failed.
```

This commit add the summary and complexity for SENTINEL DEBUG,
which introduced in #9291, and also improved the help message.
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Feb 7, 2022
If summary or since is empty, we used to return NULL in
COMMAND DOCS. Currently all redis commands will have these
two fields.

But not for module command, summary and since are optional
for RM_SetCommandInfo. With the change in redis#10043, if a module
command doesn't have the summary or since, redis-cli will
crash (see redis#10250).

In this commit, COMMAND DOCS avoid adding summary or since
when they are missing.
oranagra pushed a commit that referenced this pull request Feb 7, 2022
If summary or since is empty, we used to return NULL in
COMMAND DOCS. Currently all redis commands will have these
two fields.

But not for module command, summary and since are optional
for RM_SetCommandInfo. With the change in #10043, if a module
command doesn't have the summary or since, redis-cli will
crash (see #10250).

In this commit, COMMAND DOCS avoid adding summary or since
when they are missing.
oranagra pushed a commit that referenced this pull request Mar 10, 2022
The following usage will output an empty newline:
```
> redis-cli help set
empty line
```

The reason is that in interactive mode, we have called
`cliInitHelp`, which initializes help.

When using `redis-cli help xxx` or `redis-cli help ? xxx`,
we can't match the command due to empty `helpEntries`,
so we output an empty newline.

In this commit, we will call `cliInitHelp` to init the help.
Note that in this case, we need to call `cliInitHelp` (COMMAND DOCS)
every time, which i think is acceptable.

So now the output will look like:
```
[redis]# src/redis-cli help get

  GET key
  summary: Get the value of a key
  since: 1.0.0
  group: string

[redis]#
```

Fixes #10378

This PR also fix a redis-cli crash when using `--ldb --eval`:
```
[root]# src/redis-cli --ldb --eval test.lua test 1
Lua debugging session started, please use:
quit    -- End the session.
restart -- Restart the script in debug mode again.
help    -- Show Lua script debugging commands.

* Stopped at 1, stop reason = step over
-> 1   local num = redis.call('GET', KEYS[1]);
redis-cli: redis-cli.c:718: cliCountCommands: Assertion
`commandTable->element[i]->type == 1' failed.
Aborted
```
Because in ldb mode, `COMMAND DOCS` or `COMMAND` will
return an array, only with one element, and the type
is `REDIS_REPLY_STATUS`, the result is `<error> Unknown
Redis Lua debugger command or wrong number of arguments`.

So if we are in the ldb mode, and init the Redis HELP, we
will get the wrong response and crash the redis-cli.
In ldb mode we don't initialize HELP, help is only initialized
after the lua debugging session ends.

It was broken in #10043
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants