Skip to content

cluster: Create a readonly command lookup table - #3019

Open
michael-grunder wants to merge 1 commit into
developfrom
fix/readonly-lut
Open

michael-grunder wants to merge 1 commit into
developfrom
fix/readonly-lut

Conversation

@michael-grunder

Copy link
Copy Markdown
Member
  • Add attributes to redis_cluster.stub.php to denote readonly commands
  • Create a helper to generate the lookup table with gperf
  • Check if commands are read-only in rawCommand invocation.
  • Fix four more locations where we were allowing c->readonly to be inherited

Fixes: #3017

See: #3018

Comment thread redis_readonly_commands.h Resolved
@michael-grunder

Copy link
Copy Markdown
Member Author

@tillkruss This should solve the issue while still allowing readonly commands to distribute even via rawCommand

@tillkruss

Copy link
Copy Markdown
Member

One follow-up: could we keep replica routing for key-based rawCommand() reads, but pin commands to the specified node when the caller passes [host, port]?

The new test expects rawCommand($master, 'GET', $key) to hit a replica under FAILOVER_DISTRIBUTE_SLAVES. The repro in #3017 was a write, but I’d expect an explicit address to select that node for reads too, especially when checking what a specific primary returns.

@michael-grunder

Copy link
Copy Markdown
Member Author

One follow-up: could we keep replica routing for key-based rawCommand() reads, but pin commands to the specified node when the caller passes [host, port]?

Right now [host, port] and key just run through a common helper that maps it to a slot. Then we try to deliver to that slot depending on the failover/distribute settings.

We can't really pin the commands to an exact instance for [host, port] because that would change behavior, but we probably can introduce a new form maybe a third argument?

// means send to localhost:7000 or any replicas depending on OPT_FAILOVER/OPT_DISTRIBUTE
$rc->rawCommand(['localhost', 7000], 'config', 'set', 'slave-serve-stale-data', 'yes');

// Means send exactly to localhost:7000
$rc->rawCommand(['localhost', 7000, true], 'config', 'set', 'slave-serve-stale-data', 'yes');

* Add `@redis-readonly` PHPDoc tags to denote read-only commands.
* Create a  helper to generate the lookup table of read-only commands with `gperf`
* Check if  commands are read-only in `rawCommand` invocation.
* Fix four more locations where we were allowing `c->readonly` to be
  inherited

Fixes: #3017

See: #3018
@tillkruss

Copy link
Copy Markdown
Member

@michael-grunder That could work 👍

This branch has not been deployed

No deployments
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.

RedisCluster: directed rawCommand() may be routed to a replica under FAILOVER_DISTRIBUTE

3 participants