Skip to content

Commit

Permalink
Merge pull request #900 from globocom/feat/redis62
Browse files Browse the repository at this point in the history
Redis 6.2.7. Added redis configuration and some changes for Redis Sentinel
  • Loading branch information
Erkmann committed May 31, 2023
2 parents 06c8fbe + 1815fe1 commit c01c66d
Show file tree
Hide file tree
Showing 5 changed files with 1,374 additions and 86 deletions.
68 changes: 40 additions & 28 deletions dbaas/drivers/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,13 @@ def get_metric_collector_user(self, username):
def get_metric_collector_password(self, password):
return self.databaseinfra.password


class RedisSentinel(Redis):

@property
def engine(self):
return self.databaseinfra.engine

@property
def ports(self):
return (6379, 26379)
Expand Down Expand Up @@ -490,18 +495,15 @@ def check_instance_is_master(self, instance, default_timeout=False):
for sentinel in sentinels:
client = self.get_sentinel_instance_client(sentinel)
try:
master = client.sentinel_get_master_addr_by_name(
self.databaseinfra.name)
master = client.sentinel_get_master_addr_by_name(self.databaseinfra.name)
masters_for_sentinel.append(master)
except Exception as e:
error = 'Connection error to {}. Error: {}'.format(
sentinel, e)
error = 'Connection error to {}. Error: {}'.format(sentinel, e)
LOG.info(error)

sentinels_believe_is_master = 0
for master_host, master_port in masters_for_sentinel:
if (instance.address == master_host and
instance.port == master_port):
if instance.address == master_host and instance.port == master_port:
sentinels_believe_is_master += 1

if sentinels_believe_is_master > 1:
Expand All @@ -526,16 +528,22 @@ def switch_master(self, instance=None, preferred_slave_instance=None):
fi
}"""

script += """
/usr/local/redis/src/redis-cli -h {} -p {} <<EOF_DBAAS
SENTINEL failover {}
exit
\nEOF_DBAAS
die_if_error "Error reseting sentinel"
""".format(
sentinel_instance.address, sentinel_instance.port,
self.databaseinfra.name
)
if self.engine.major_version == 6:
script += """
/usr/bin/redis-cli -h {} -p {} <<EOF_DBAAS
SENTINEL failover {}
exit
\nEOF_DBAAS
die_if_error "Error reseting sentinel"
""".format(sentinel_instance.address, sentinel_instance.port, self.databaseinfra.name)
else:
script += """
/usr/local/redis/src/redis-cli -h {} -p {} <<EOF_DBAAS
SENTINEL failover {}
exit
\nEOF_DBAAS
die_if_error "Error reseting sentinel"
""".format(sentinel_instance.address, sentinel_instance.port, self.databaseinfra.name)

script = build_context_script({}, script)
host.ssh.run_script(script)
Expand Down Expand Up @@ -739,19 +747,23 @@ def switch_master(self, instance=None, preferred_slave_instance=None):
fi
}"""

script += """
/usr/local/redis/src/redis-cli -h {} -p {} -a {} -c<<EOF_DBAAS
CLUSTER FAILOVER
exit
\nEOF_DBAAS
die_if_error "Error executing cluster failover"
""".format(
slave_instance.address, slave_instance.port,
self.databaseinfra.password
)

if self.engine.major_version == 6:
script += """
/usr/bin/redis-cli -h {} -p {} -a {} -c<<EOF_DBAAS
CLUSTER FAILOVER
exit
\nEOF_DBAAS
die_if_error "Error executing cluster failover"
""".format(slave_instance.address, slave_instance.port, self.databaseinfra.password)
else:
script += """
/usr/local/redis/src/redis-cli -h {} -p {} -a {} -c<<EOF_DBAAS
CLUSTER FAILOVER
exit
\nEOF_DBAAS
die_if_error "Error executing cluster failover"
""".format(slave_instance.address, slave_instance.port, self.databaseinfra.password)
script = build_context_script({}, script)

host.ssh.run_script(script)

def get_master_instance(self):
Expand Down
8 changes: 1 addition & 7 deletions dbaas/drivers/replication_topologies/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,7 @@ def get_deploy_steps(self):
)}, {
'Check ACL': (
'workflow.steps.util.acl.BindNewInstance',
)},
# {
# 'Creating monitoring and alarms': (
# 'workflow.steps.util.zabbix.CreateAlarms',
# 'workflow.steps.util.db_monitor.CreateInfraMonitoring',
# )},
{
)}, {
'Creating monitoring and alarms': (
'workflow.steps.util.zabbix.CreateAlarms',
'workflow.steps.util.db_monitor.CreateInfraMonitoring',
Expand Down

0 comments on commit c01c66d

Please sign in to comment.