SlideShare a Scribd company logo
Redis Sentinel
charsyam@naver.com
Redis.io
Redis/Twemproxy
Contributor
카카오 홈 개발자
Redis Monitoring?
Redis sentinelinternals deview
Redis sentinelinternals deview
Redis sentinelinternals deview
Checking Liveness
Checking Liveness
servers = [ ('localhost', 6379),
('localhost', 6380),
('localhost', 6381) ]
conns = []
def check():
for conn in conns:
print conn.ping()
Checking it works
Checking it works
def check():
for conn in conns:
i = conn.info()
print i['run_id'],
i['used_memory_human'],
i['total_commands_processed']
Is it Reliable?
Is Server really
Failed?
Split Network.
Server is busy.
Monitoring is not
the one we really
want.
HA

High Availity
What do you do?
When your servers failed
1. Recognize Redis is down.
2. choose new master
candidate
3. Promote slave to Master.
4. make client connect to
new master
What
Redis Sentinel
do?
1. Check Redis Liveness
1. Check Redis Liveness
-Subjective Down
-Objective Down
2. Choose good slave.
Good Slave
NOT SDOWN, ODOWN, DISCONNECTED

NOT DEMOTE
Ping reply > info_validity_time
Slave_priority != 0
Info reply > info_validity_time
Choose new master

Sort

Slave Priority
Runid
3. Promote it
Promoting
Send Slaveof no one to new master

Send Slaveof [new master ip] [addr] to
Other redis
Notify new master to clietns
+switch-master

Set DEMOTE mark to old-Master
Failover Scenario
Sentinel
Master
Slave
Slave

Pub/Sub

Client
Client
Sentinel
Master
Slave A
Slave B

Pub/Sub

Client
Client
Choose Slave A
as New Master

Master
Slave A
Slave B

Sentinel
Pub/Sub

Client
Client
Send to Slave B
Slaveof Slave A

Master
Slave A
Slave B

Sentinel
Pub/Sub

Client
Client
Send “Slaveof no
one” to Slave A

Master
Slave A
Slave B

Sentinel
Pub/Sub

Client
Client
Send “Slaveof Slave
A” to Slave B

Master
Master
Slave B

Sentinel
Pub/Sub

Client
Client
Sentinel
Master
Master
Slave B

Pub/Sub: +switch-master

Client
Client
Sentinel Internal
Sentinel Failover State Machine
State
내용
NONE
WAIT_START
SELECT_SLAVE
SEND_SLAVEOF
WAIT_PROMOTION
RECONF_SLAVES
DETECT_END

Next State
SELECT_SLAVE
SEND_SLAVEOF
WAIT_PROMOTION
Starting Point Of Sentinel
• sentinelTimer in sentinel.c
–Called every 100ms
–sentinelHandleRedisInstance
SentinelRedisInstance
• master
–If it is master, it is null.

• slaves
• sentinels
sentinelHandleDictOfRedisInstances
while((de = dictNext(di)) != NULL) {
sentinelRedisInstance *ri = dictGetVal(de);
sentinelHandleRedisInstance(ri);
if (ri->flags & SRI_MASTER) {
sentinelHandleDictOfRedisInstances(ri->slaves);
sentinelHandleDictOfRedisInstances(ri->sentinels);
……
}
}
sentinelHandleRedisInstance
• Reconnect to Instances
• Ping
• Asking Master State to other Sentinel
• Check SDOWN
• Check ODOWN
How to check Subjective Down
• When Sentinel get Ping Reply

–Set last_avail_time as current

• Check
–e = current –last_avail_time
–e > last_avail_time
•Subjective Down.
How to check Objective Down
• Ask to other sentinels is it down.
–sentinelAskMasterStateToOtherSentinels

• If other sentinels reply it is down.
–Count them, if it is bigger than Quorum.
–It is objective Down.
How to find Redis
INFO Command
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6380,state=online,offset=1,lag=0
master_repl_offset:1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:0
INFO Command
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
+redirect-master
How to find Sentinel
Find Sentinel
Subscribe SENTINEL_HELLO_CHANNEL
In Master

Publish Sentinel Information
In sentinelPingInstance
Add New Sentinel
In sentinelReceiveHelloMessages
Using Pub/sub
*4
$8
pmessage
$1
*
$18
__sentinel__:hello
$58
127.0.0.1:26379:7d717f945afde99e6f82f825de052f17cab7e6f3:1
Is Sentinel Really Good?
Not Mature #1
Sentinel Conf
port 26379
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 2000
sentinel can-failover mymaster yes
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 900000
Quorum Count
sentinel monitor mymaster 127.0.0.1 6379 2

We should check this
count.
Sentinel Conf
sentinel down-after-milliseconds mymaster 2000

If this value is Too small,
It can cause some trouble.
-sdown/+sdown loop
Compare with Zookeeper Conf
tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
Not Mature #2
Master

Slave

Sentinel
Master

Slave

Sentinel
Master

Master

Sentinel
Master

Master

Sentinel
Case #1
Master
Sentinel

Master

It’s OK.
Case #1
Master

Master

Sentinel
Case #2
Master

Slave

Sentinel
Case #2
Master

Slave

Sentinel

Sentinel can’t promote
Slave to Master
Why?
Sentinel Mechanism.
When master is changed to Slave,
Reconf with new Master.
Sentinel Mechanism.
When master is changed to Slave,
Reset information with new Master.
But, if new master failed, sentinel will
not get any information from it.
Sentinel Mechanism.
if ((ri->flags & SRI_MASTER) && role == SRI_SLAVE && ri->slave_master_host)
{
sentinelEvent(REDIS_WARNING,"+redirect-to-master",ri,
"%s %s %d %s %d",
ri->name, ri->addr->ip, ri->addr->port,
ri->slave_master_host, ri->slave_master_port);
sentinelResetMasterAndChangeAddress(ri,ri->slave_master_host,
ri->slave_master_port);
return; /* Don't process anything after this event. */
}
Not Mature #3
If redis is down, when
redis is loading data(RDB,
AOF), sentinel can’t
register redis.
Conclusion
Even though, Sentinel is
not mature.
It is useful.
Redis Sentinel Tips
1. Subscribe all Sentinels
And ignore duplicated
message
2. Sentinel has explicit
failover command
sentinel mymaster failover
But can’t select new
master
Hacking is easy.
https://github.com/antirez/redis/pull/1126
3. Make Sentinel.conf
same.
Sentinels can’t share
their status
Deploy conf to all
sentinels with Script
And restart all sentinels.
4. If you want not to
promote specific server
to master
Set Slave-Priority = 0
Thank you!
Just One more thing
Twemprox
Redis
Redis-sentinel

Sharded
Redis
Redis-Sentinel
TwemProxy Agent
http://www.codeproject.com/Articles/656965/R
edis-Sentinel-TwemProxy-Agent
Agent

Pub/Sub Shard
Redis Master

Restart
VRRP

Twemproxy

HA Proxy

Redis Slave
Redis Slave

Twemproxy

HA Proxy

Twemproxy

Shard

Sentinel

Redis Master
Redis Slave
Redis Slave

More Related Content

PDF
Redis acc
PDF
REDIS intro and how to use redis
PDF
Ceph issue 해결 사례
PDF
Storage managment using nagios
PDF
Redis persistence in practice
PDF
Corosync and Pacemaker
DOC
X64服务器 lnmp服务器部署标准 new
DOCX
Ansible ex407 and EX 294
Redis acc
REDIS intro and how to use redis
Ceph issue 해결 사례
Storage managment using nagios
Redis persistence in practice
Corosync and Pacemaker
X64服务器 lnmp服务器部署标准 new
Ansible ex407 and EX 294

What's hot (20)

PDF
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
PDF
Red Hat Enterprise Linux OpenStack Platform on Inktank Ceph Enterprise
PDF
DEVIEW - 오픈소스를 활용한 분산아키텍처 구현기술
PDF
Oracle cluster installation with grid and iscsi
PDF
Oracle cluster installation with grid and nfs
PDF
실시간 서비스 플랫폼 개발 사례
PPTX
[오픈소스컨설팅] Linux Network Troubleshooting
PPTX
RHCE Training
ODP
High Availability in 37 Easy Steps
PDF
PDF
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
PDF
PostgreSQL High-Availability and Geographic Locality using consul
PDF
Linux-HA with Pacemaker
PDF
Red Hat Certified Engineer (RHCE) EX294 Exam Questions
PPTX
This is redis - feature and usecase
PDF
Dockerを利用したローカル環境から本番環境までの構築設計
PDF
Dockertaipei 20150528-dockerswarm
PDF
Varnish presentation for the Symfony Zaragoza user group
PPTX
Herd your chickens: Ansible for DB2 configuration management
PDF
K8s上の containerized cloud foundryとcontainerized open stackをprometheusで監視してみる
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Red Hat Enterprise Linux OpenStack Platform on Inktank Ceph Enterprise
DEVIEW - 오픈소스를 활용한 분산아키텍처 구현기술
Oracle cluster installation with grid and iscsi
Oracle cluster installation with grid and nfs
실시간 서비스 플랫폼 개발 사례
[오픈소스컨설팅] Linux Network Troubleshooting
RHCE Training
High Availability in 37 Easy Steps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
PostgreSQL High-Availability and Geographic Locality using consul
Linux-HA with Pacemaker
Red Hat Certified Engineer (RHCE) EX294 Exam Questions
This is redis - feature and usecase
Dockerを利用したローカル環境から本番環境までの構築設計
Dockertaipei 20150528-dockerswarm
Varnish presentation for the Symfony Zaragoza user group
Herd your chickens: Ansible for DB2 configuration management
K8s上の containerized cloud foundryとcontainerized open stackをprometheusで監視してみる
Ad

Viewers also liked (20)

PDF
Simple cache architecture
PPTX
Redis tutoring
PDF
Mongo db 2.x to 3.x
KEY
Redis -- Memory as the New Disk
PDF
Redis acc 2015
PDF
Redis basicandroadmap
PDF
『풀스택 개발자를 위한 MEAN 스택 입문』 - 미리보기
PDF
Redis on AWS
PDF
NoSQL 동향
PPTX
Redis/Lessons learned
PPTX
Mongo db 최범균
PDF
Redis cluster
PPTX
몽고디비교육1일차
PDF
Cassandra vs. Redis
PDF
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
PDF
Mongo db 시작하기
PDF
The MongoDB Strikes Back / MongoDB 의 역습
PDF
Redis, another step on the road
PPTX
이것이 레디스다.
PDF
FullStack 개발자 만들기 과정 소개 (Android + MEAN Stack + Redis 다루기)
Simple cache architecture
Redis tutoring
Mongo db 2.x to 3.x
Redis -- Memory as the New Disk
Redis acc 2015
Redis basicandroadmap
『풀스택 개발자를 위한 MEAN 스택 입문』 - 미리보기
Redis on AWS
NoSQL 동향
Redis/Lessons learned
Mongo db 최범균
Redis cluster
몽고디비교육1일차
Cassandra vs. Redis
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Mongo db 시작하기
The MongoDB Strikes Back / MongoDB 의 역습
Redis, another step on the road
이것이 레디스다.
FullStack 개발자 만들기 과정 소개 (Android + MEAN Stack + Redis 다루기)
Ad

More from DaeMyung Kang (20)

PPTX
Count min sketch
PDF
PDF
Ansible
PDF
Why GUID is needed
PDF
How to use redis well
PPTX
The easiest consistent hashing
PDF
How to name a cache key
PDF
Integration between Filebeat and logstash
PDF
How to build massive service for advance
PDF
Massive service basic
PDF
Data Engineering 101
PDF
How To Become Better Engineer
PPTX
Kafka timestamp offset_final
PPTX
Kafka timestamp offset
PPTX
Data pipeline and data lake
PDF
Redis acl
PDF
Coffee store
PDF
Scalable webservice
PDF
Number system
PDF
webservice scaling for newbie
Count min sketch
Ansible
Why GUID is needed
How to use redis well
The easiest consistent hashing
How to name a cache key
Integration between Filebeat and logstash
How to build massive service for advance
Massive service basic
Data Engineering 101
How To Become Better Engineer
Kafka timestamp offset_final
Kafka timestamp offset
Data pipeline and data lake
Redis acl
Coffee store
Scalable webservice
Number system
webservice scaling for newbie

Recently uploaded (20)

PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
Teaching material agriculture food technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
A Presentation on Artificial Intelligence
Group 1 Presentation -Planning and Decision Making .pptx
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Programs and apps: productivity, graphics, security and other tools
Teaching material agriculture food technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
SOPHOS-XG Firewall Administrator PPT.pptx
Spectroscopy.pptx food analysis technology
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Reach Out and Touch Someone: Haptics and Empathic Computing
A Presentation on Artificial Intelligence

Redis sentinelinternals deview