Repository navigation
fix(commands): correct write command flags for FUNCTION, MPUBLISH and NAMESPACE - #3835
Draft
leo7martins wants to merge 1 commit into
Draft
leo7martins wants to merge 1 commit into
leo7martins wants to merge 1 commit into
Conversation
… 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
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Issue #3828: commands that write to RocksDB (and/or replicate through the Propagate and PubSub column families) were declared without the
writeflag, so the flag metadata did not match the Redis command-flag specification and the write guards did not apply:FUNCTION FLUSHdeletes the Lua library key range from the Propagate column family and propagates to replicas, butGenerateFunctionFlagsonly setkCmdWriteforLOAD/DELETE, soFLUSHbypassedCLIENT PAUSE WRITE,slave-read-onlyandmax-db-size.MPUBLISHwrites each message to the PubSub column family on the master to replicate it, exactly likePUBLISH, but it was missing fromkWriteModeSpecialCmds, soCLIENT PAUSE WRITEdid not defer it.NAMESPACE ADD/SET/DELrewrite the configuration file and, withrepl-namespace-enabled, write the namespace metadata to the Propagate column family and replicate it, yet the command is registeredread-only, so the mutating subcommands bypassed the write guards.Fix
GenerateFunctionFlagsnow setskCmdWriteforflushandkCmdReadOnlyfor the read-onlylist/listfunc/listlibsubcommands, mirroring the existingSCRIPTflags and the Redis spec.mpublishis added tokWriteModeSpecialCmdsso it is treated consistently withPUBLISHunderCLIENT PAUSE WRITE(both stayread-only-flagged so publishing remains available on read-only replicas).GenerateNamespaceFlagsetskCmdWriteand clearskCmdReadOnlyforadd/set/del;get/currentremain read-only, and the existing replica guard inCommandNamespace::Executeis unchanged.Tests
New gocase test
TestClientPauseWriteDefersWriteCommands(tests/gocase/unit/client/client_pause_write_test.go) asserts thatCLIENT PAUSE WRITEdefersFUNCTION FLUSH,MPUBLISHandNAMESPACE ADD/SET/DEL(their effects are not visible and subscribers receive nothing untilCLIENT UNPAUSE), while the read-onlyFUNCTION LISTandNAMESPACE GET/CURRENTsubcommands 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
kvrocksbinary 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.
HLENunder field-expiration metadata).Fixes #3828
This was written with help from an AI coding assistant.