OpenSIPS / opensips

OpenSIPS is a GPL implementation of a multi-functionality SIP Server that targets to deliver a high-level technical solution (performance, security and quality) to be used in professional SIP server platforms.
https://opensips.org
Other
1.25k stars 575 forks source link

[FEATURE] Support for a REDIS cluster #2811

Open Lt-Flash opened 2 years ago

Lt-Flash commented 2 years ago

Is your feature request related to a problem? Please describe. It's both a feature request and a problem we've experienced. We were using a single instance of REDIS server without any issues for a long time. Recently we have deployed a REDIS cluster consisting of three MASTER nodes and three SLAVE nodes and run into an issue. REDIS protocol shards data between nodes in a cluster so when you're connected to M1 node (for example) but KEY you're looking for is on another node REDIS will respond with (for example):

MOVED 16281 192.168.0.14:6379

And as per REDIS documentation (https://redis.io/docs/reference/cluster-spec/):

The error includes the hash slot of the key (3999) and the endpoint:port of the instance that can serve the query. The client needs to reissue the query to the specified node's endpoint address and port. The endpoint can be either an IP address, a hostname, or it can be empty (e.g. -MOVED 3999 :6380). An empty endpoint indicates that the server node has an an unknown endpoint, and the client should send the next request to the same endpoint as the current request but with the provided port.

Note that even if the client waits a long time before reissuing the query, and in the meantime the cluster configuration changed, the destination node will reply again with a MOVED error if the hash slot 3999 is now served by another node. The same happens if the contacted node had no updated information.

This behaviour disallows us to use REDIS cluster even with HAProxy or some other load balancer in front of it as the proxy can't analyze actual REDIS protocol and re-connect client to another REDIS node.

Describe the solution you'd like Update OpenSIPS REDIS cache module to support recent version of REDIS cluster.

Implementation

Describe alternatives you've considered The only alternative is to continue using a single REDIS instance with a probable VRRP backup and some synchronization between them.

Thank you!

Lt-Flash commented 2 years ago

Another idea - maybe it would be good to have all REDIS servers defined in a modparam or in DB so OpenSIPS could pre-open connections to all REDIS master/slave servers and as soon as it receives 'MOVED' response it can just use already open connection. If the server in 'MOVED' reply not listed then new connection needs to be open.

Lt-Flash commented 2 years ago

Just a reference to Kamalio's module, it seem to support 'MOVED' operations:

https://www.kamailio.org/docs/modules/devel/modules/ndb_redis.html

ishvaram commented 1 year ago

@Lt-Flash Is there an issue using Redis sentinel setup with Opensips (1 master - 2 slaves and based on the quorum value failover can happen and the master can be elected) MOVE command support is needed only when we go for Redis Cluster setup like multiple master-slave 1:1 master: slave cluster setup.

Lt-Flash commented 1 year ago

There is no issue using REDIS Sentinel, but the feature request is for REDIS Cluster. And REDIS Cluster is giving much more features than Sentinel which is just a failover solution.

ishvaram commented 1 year ago

@bogdan-iancu by when this cluster support will be available? any rough timeline?

bogdan-iancu commented 1 year ago

for the moment there is no plan for this feature