question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

readonly mode not execute command on slave node

See original GitHub issue

I set readonly_mode=True to test the readonly mode. And print the node which realy execute command. But whether readonly_mode is True or False the node server_type is all master.

from rediscluster import RedisCluster


def main():
    startup_nodes = [{"host": "", "port": ""}]
    rc = RedisCluster(startup_nodes=startup_nodes, decode_responses=True, readonly_mode=True)
    print(rc.set('foo', 'bar'))
    print(rc.get('foo'))

if __name__ == "__main__":
    main()

I print the node in client.py to get node info.

 @clusterdown_wrapper
    def execute_command(self, *args, **kwargs):
        """
        Send a command to a node in the cluster
        """
        ....
            else:
                if self.refresh_table_asap:
                    # MOVED
                    node = self.connection_pool.get_master_node_by_slot(slot)
                else:
                    node = self.connection_pool.get_node_by_slot(slot, self.read_from_replicas and (command in self.READ_COMMANDS))
                    is_read_replica = node['server_type'] == 'slave'
                print(node)
                r = self.connection_pool.get_connection_by_node(node)

        ....

The print is :

{'host': '', 'port': , 'name': '', 'server_type': 'master'}
True
{'host': '', 'port': , 'name': '', 'server_type': 'master'}
bar

I consider is because of the partial get node.

                if self.refresh_table_asap:
                    # MOVED
                    node = self.connection_pool.get_master_node_by_slot(slot)
                else:
                    node = self.connection_pool.get_node_by_slot(slot, self.read_from_replicas and (command in self.READ_COMMANDS))
                    is_read_replica = node['server_type'] == 'slave'
                r = self.connection_pool.get_connection_by_node(node)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Grokzencommented, Sep 17, 2020

The two different connection pools will get a makeover in 3.0.0

1reaction
Grokzencommented, May 6, 2020

@ididid8 I did some digging into this issue, what i figured out is that there is two different connectionpools implemented that is controlled and activated by two different flags. What it seems like is that the flag you are using right now readonly_mode=True is using a broken implementation of READONLY mode. What is working tho is the following code snippet where i modified your example

from rediscluster import RedisCluster

startup_nodes = [{"host": "127.0.0.1", "port": "7000"}]
rc = RedisCluster(
    startup_nodes=startup_nodes,
    decode_responses=True,
    read_from_replicas=True,
)
print(rc.set('foo', 'bar'))

for i in range(0, 10):
    print(rc.get('foo'))

read_from_replicas=True activates a working connectionpool that will utilize READONLY correctly. When i ran the script above it loadbalanced the GET commands about equally between the master and the slave nodes to which the slot belonged to. No it do not send all read commands to the slaves, but it loadbalances them equally across all nodes at least. Both of these connection pools needs to be merged into a single solution, but right now they will remain as is until i can sort that out and i reccommend that you use read_from_replicas=True to fullfill your need.

Read more comments on GitHub >

github_iconTop Results From Across the Web

(lettuce) READONLY You can't write against a read only slave
Whenever the service is deployed, several docker nodes will appear ERROR: READONLY You can't write against a read only slave. lettuce ...
Read more >
Readonly mode — redis-py-cluster 2.1.3 documentation
By default, Redis Cluster always returns MOVE redirection response on accessing slave node. You can overcome this limitation [for scaling read with READONLY...
Read more >
READONLY - Redis
READONLY tells a Redis Cluster replica node that the client is willing to read possibly stale data and is not interested in running...
Read more >
Configure repository - Alfresco Docs
To set Alfresco to read-only mode, use one of the following methods: Using the alfresco-global.properties file; Using a JMX client such as JConsole....
Read more >
Readwritesplit - MariaDB Knowledge Base
The readwritesplit router is designed to increase the read-only processing capability of a cluster while maintaining consistency.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found