Skip to content

fix(commands): correct write command flags for FUNCTION, MPUBLISH and NAMESPACE - #3835

Draft
leo7martins wants to merge 1 commit into
apache:unstablefrom
leo7martins:fix/3828-command-flags
Draft

leo7martins wants to merge 1 commit into
apache:unstablefrom
leo7martins:fix/3828-command-flags

Conversation

@leo7martins

Copy link
Copy Markdown

What was wrong

Issue #3828: commands that write to RocksDB (and/or replicate through the Propagate and PubSub column families) were declared without the write flag, so the flag metadata did not match the Redis command-flag specification and the write guards did not apply:

  • FUNCTION FLUSH deletes the Lua library key range from the Propagate column family and propagates to replicas, but GenerateFunctionFlags only set kCmdWrite for LOAD/DELETE, so FLUSH bypassed CLIENT PAUSE WRITE, slave-read-only and max-db-size.
  • MPUBLISH writes each message to the PubSub column family on the master to replicate it, exactly like PUBLISH, but it was missing from kWriteModeSpecialCmds, so CLIENT PAUSE WRITE did not defer it.
  • NAMESPACE ADD/SET/DEL rewrite the configuration file and, with repl-namespace-enabled, write the namespace metadata to the Propagate column family and replicate it, yet the command is registered read-only, so the mutating subcommands bypassed the write guards.

Fix

  • GenerateFunctionFlags now sets kCmdWrite for flush and kCmdReadOnly for the read-only list/listfunc/listlib subcommands, mirroring the existing SCRIPT flags and the Redis spec.
  • mpublish is added to kWriteModeSpecialCmds so it is treated consistently with PUBLISH under CLIENT PAUSE WRITE (both stay read-only-flagged so publishing remains available on read-only replicas).
  • GenerateNamespaceFlag sets kCmdWrite and clears kCmdReadOnly for add/set/del; get/current remain read-only, and the existing replica guard in CommandNamespace::Execute is unchanged.

Tests

New gocase test TestClientPauseWriteDefersWriteCommands (tests/gocase/unit/client/client_pause_write_test.go) asserts that CLIENT PAUSE WRITE defers FUNCTION FLUSH, MPUBLISH and NAMESPACE ADD/SET/DEL (their effects are not visible and subscribers receive nothing until CLIENT UNPAUSE), while the read-only FUNCTION LIST and NAMESPACE GET/CURRENT subcommands are still served immediately.

These tests were authored by an AI coding agent and were not executed locally (the development machine has no Go toolchain and no C++ toolchain/CMake to build the kvrocks binary the gocase harness requires); they are left to CI via ./x.py test go. The flag-generation logic was additionally validated by a table of 17 subcommand-to-flag checks.

Out of scope (possible follow-up flagged in the issue): auditing other commands with dynamic subcommands or repair writes (e.g. HLEN under field-expiration metadata).

Fixes #3828

This was written with help from an AI coding assistant.

… NAMESPACE

These commands write to RocksDB (and/or replicate through the Propagate
and PubSub column families) but were declared without the write flag, so
the flag metadata did not match the Redis command-flag specification and
the write guards did not apply to them:

- FUNCTION FLUSH deletes the lua library key range from the Propagate
  column family and propagates to replicas, but GenerateFunctionFlags
  only set kCmdWrite for the LOAD and DELETE subcommands, so FLUSH
  bypassed CLIENT PAUSE WRITE, slave-read-only and max-db-size. Set
  kCmdWrite for FLUSH, and also set kCmdReadOnly for the read-only
  LIST/LISTFUNC/LISTLIB subcommands, mirroring the SCRIPT flags.
- MPUBLISH writes each message to the PubSub column family on the
  master to replicate it, exactly like PUBLISH, but unlike PUBLISH it
  was not a member of kWriteModeSpecialCmds, so CLIENT PAUSE WRITE did
  not defer it. Treat it consistently with PUBLISH.
- NAMESPACE ADD/SET/DEL rewrite the configuration file and, when
  repl-namespace-enabled is on, write the namespace metadata to the
  Propagate column family and replicate it to replicas, yet the command
  is registered read-only. Set kCmdWrite and clear kCmdReadOnly for
  these mutating subcommands so the write guards apply, while GET and
  CURRENT remain read-only.

Add gocase regression coverage asserting that CLIENT PAUSE WRITE defers
FUNCTION FLUSH, MPUBLISH and NAMESPACE ADD/SET/DEL, while the read-only
FUNCTION LIST and NAMESPACE GET/CURRENT subcommands are still served.

Fixes apache#3828
@github-actions

Copy link
Copy Markdown

Hi @leo7martins,

Thank you for your pull request. Please review our Contributing Guide.

Please make sure you understand your changes and explain your reasoning in this pull request. Low-quality pull requests may be closed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commands marked read-only or missing kCmdWrite still write to RocksDB (FUNCTION FLUSH, MPUBLISH, NAMESPACE ADD/SET/DEL)

1 participant