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

valkey-cli: re-select previously selected database after reconnect #1694

Merged
merged 2 commits into from
Feb 10, 2025

Conversation

xbasel
Copy link
Member

@xbasel xbasel commented Feb 9, 2025

DB0 is selecetd after reconnection regardless of the previously selected database. The prompt show the previously selected databse while working with DB0, which is misleading.
The code has been chanegd to reselect the requested database.

Fixes #1693

@xbasel
Copy link
Member Author

xbasel commented Feb 9, 2025

Fixes issue #1693

@xbasel xbasel marked this pull request as draft February 9, 2025 21:08
Copy link

codecov bot commented Feb 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.94%. Comparing base (de3672a) to head (d7b1cbc).
Report is 13 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1694      +/-   ##
============================================
- Coverage     71.04%   70.94%   -0.11%     
============================================
  Files           121      123       +2     
  Lines         65311    65535     +224     
============================================
+ Hits          46399    46492      +93     
- Misses        18912    19043     +131     
Files with missing lines Coverage Δ
src/valkey-cli.c 54.38% <100.00%> (-1.51%) ⬇️

... and 27 files with indirect coverage changes

Copy link
Member

@enjoy-binbin enjoy-binbin left a comment

Choose a reason for hiding this comment

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

i think we can do a re-select in here? after the reconnect

static int issueCommandRepeat(int argc, char **argv, long repeat) {
    /* In Lua debugging mode, we want to pass the "help" to the server to get
     * it's own HELP message, rather than handle it by the CLI, see ldbRepl.
     *
     * For the normal server HELP, we can process it without a connection. */
    if (!config.eval_ldb && (!strcasecmp(argv[0], "help") || !strcasecmp(argv[0], "?"))) {
        cliOutputHelp(--argc, ++argv);
        return REDIS_OK;
    }

    while (1) {
        if (config.cluster_reissue_command || context == NULL || context->err == REDIS_ERR_IO ||
            context->err == REDIS_ERR_EOF) {
            if (cliConnect(CC_FORCE) != REDIS_OK) {
                cliPrintContextError();
                config.cluster_reissue_command = 0;
                return REDIS_ERR;
            }
+           reset config
+           cliSelect();
        }

@xbasel
Copy link
Member Author

xbasel commented Feb 10, 2025

i think we can do a re-select in here? after the reconnect

static int issueCommandRepeat(int argc, char **argv, long repeat) {
    /* In Lua debugging mode, we want to pass the "help" to the server to get
     * it's own HELP message, rather than handle it by the CLI, see ldbRepl.
     *
     * For the normal server HELP, we can process it without a connection. */
    if (!config.eval_ldb && (!strcasecmp(argv[0], "help") || !strcasecmp(argv[0], "?"))) {
        cliOutputHelp(--argc, ++argv);
        return REDIS_OK;
    }

    while (1) {
        if (config.cluster_reissue_command || context == NULL || context->err == REDIS_ERR_IO ||
            context->err == REDIS_ERR_EOF) {
            if (cliConnect(CC_FORCE) != REDIS_OK) {
                cliPrintContextError();
                config.cluster_reissue_command = 0;
                return REDIS_ERR;
            }
+           reset config
+           cliSelect();
        }

cliSelect() is already invoked in cliConnect():
https://github.com/valkey-io/valkey/blob/unstable/src/valkey-cli.c#L1670

@xbasel xbasel force-pushed the persistSelectDb branch 3 times, most recently from 07c5cb0 to 1e1a1cb Compare February 10, 2025 12:31
DB0 is selecetd after reconnection regardless of the previously selected
database. The prompt show the previously selected databse while working
with DB0, which is misleading.
The code has been chanegd to reselect the requested database.

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
@xbasel xbasel marked this pull request as ready for review February 10, 2025 13:43
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.

Looks good in general.

If you write Fixes #xxxx or Closes #xxxx in the PR top comment, it links the PR to the issue closes the issue when merging. It's useful.

This PR obsoletes #1382. I prefer this new PR because it includes a test case.

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
@zuiderkwast zuiderkwast added bug Something isn't working release-notes This issue should get a line item in the release notes labels Feb 10, 2025
@zuiderkwast zuiderkwast merged commit b8c471e into valkey-io:unstable Feb 10, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working release-notes This issue should get a line item in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Valkey-cli Incorrect database selection after connection drop
3 participants