Skip to content

Slave does not become master if original master never showed up or both restart #1073

Closed

Description

@alexfouche

Hi,

I have to scenarios where Sentinel does not promote a master. Some might say that this could be an akward situation that should not happen, but when in the cloud IAAS, it can happen rather frequently. For example instances go down, or reprovisionned. Or simply when your app and redis replicaset is started only a few hours of the day or intermittently. Whatever the reason, when the whole set of servers is started, Redis replicaset should be operational even if the redis-server which is master in its configuration does not show up for various reasons.

Below are 2 scenarios to reproduce the case

My setup is 2x redis servers, and 3x sentinels, on 3 different servers.

I am using the lastest redis-server from branch 2.6, currently at commit antirez@34a57a5

Scenario 1:

  • there are 2 redis servers configured as master slave, namely redis1 and redis2. They are not started
  • there are 3 sentinels that are running fine
  • i start redis2 which has slaveof redis1 in its configuration

-> BAD: sentinels do not promote redis2 to master

Scenario 2:

  • there are 2 redis servers configured as master slave, namely redis1 and redis2. They are not started
  • there are 3 sentinels that are running fine
  • i start redis1 which is master in its configuration. It shows up as master
  • i start redis2 which has slaveof redis1 in its configuration. It shows up as a slave and begins syncing
  • i stop redis1
  • sentinels promote redis2 to master, as expected
  • i stop redis2
  • i start redis2. It tries to sync but redis1 is still down

-> BAD: sentinels do not promote redis2 to master. The difference with scenario1 is that sentinels had the history and saw the topology of the redis replicaset, when both redis1 and redis2 were running, but they did not take it into account to promote redis2 as master.

Activity

  1. antirez commented on Apr 27, 2013

    @antirez
    Contributor

    Hello, long reply monday but to give you a fast feedback, may you retry scenario 2 with latest 2.6 branch commit? I believe we solved it. First case is a bit more dangerous and I'll comment in a detailed way. Cheers

  2. alexfouche commented on May 2, 2013

    @alexfouche
    Author

    I tried the commit antirez@d964979 but make test fails on Amazon 2012.09 : redis-server processes becomes defunct and unkillable, and make test never completes.
    So i will test Sentinel again some time later

  3. antirez commented on May 2, 2013

    @antirez
    Contributor

    Hello @alexfouche, you mean, your own test fails? or Redis "Make test"? Thank you.

  4. alexfouche commented on May 2, 2013

    @alexfouche
    Author

    make && make test . I did Not have failing tests, but it could not complete and created some redis-server processes which ended up defunct and one supposedly running, all unkillable. At the same time the make test is spilling out messages something like waiting forked redis XXXX to end or something like this. I'll try to resume this but much later

  5. antirez commented on May 2, 2013

    @antirez
    Contributor

    Nothing I'm aware of should break testing on EC2, maybe just out of memory or alike... I'll ask uses on twitter to replicate on some EC2 instance. Thanks.

  6. alexfouche commented on May 2, 2013

    @alexfouche
    Author

    That was a micro instance, because i was planning to do just sentinel tests and not load testing Redis, so memory or cpu deprivation might be the culprits there

    Alexandre Fouche
    Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

    On Thursday 2 May 2013 at 17:02, Salvatore Sanfilippo wrote:

    Nothing I'm aware of should break testing on EC2, maybe just out of memory or alike... I'll ask uses on twitter to replicate on some EC2 instance. Thanks.

    —
    Reply to this email directly or view it on GitHub (https://github.com/antirez/redis/issues/1073#issuecomment-17343116).

  7. karlseguin commented on May 2, 2013

    @karlseguin

    make test for antirez@d964979 worked fine on a m3.xlarge

    on a micro I got stuck in a "forcing process XXX to exit" after many tests (all?) had run.

    [ 1398.876661] Pid: 20414, comm: tclsh8.5 Tainted: G      D      3.5.0-21-generic #32-Ubuntu  
    [ 1398.876669] RIP: e030:[<ffffffff81148c93>]  [<ffffffff81148c93>] unmap_page_range+0x263/0x740
    [ 1398.876682] RSP: e02b:ffff880007aeda68  EFLAGS: 00050246
    [ 1398.876686] RAX: 0000000000000063 RBX: ffff880002f4f500 RCX: ffff880000000000
    [ 1398.876691] RDX: ffff880000000018 RSI: 00003ffffffff000 RDI: ffff880007aedbf0
    [ 1398.876696] RBP: ffff880007aedb48 R08: 0000000000000000 R09: 0000000000601000
    [ 1398.876700] R10: ffffffff81cd61c0 R11: 00007ffffffff000 R12: 0000000000600000
    [ 1398.876705] R13: 0000000000601000 R14: ffff880012e89018 R15: ffff880002f4f500
    [ 1398.876713] FS:  00002b22a2eae340(0000) GS:ffff880026400000(0000) knlGS:0000000000000000
    [ 1398.876719] CS:  e033 DS: 0000 ES: 0000 CR0: 000000008005003b
    [ 1398.876723] CR2: 00002b22a2eae610 CR3: 0000000001c0b000 CR4: 0000000000002620
    [ 1398.876729] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    [ 1398.876735] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000000
    [ 1398.876740] Process tclsh8.5 (pid: 20414, threadinfo ffff880007aec000, task ffff88001af19700)
    [ 1398.876745] Stack:
    [ 1398.876748]  ffff88002640b310 ffff88002640b958 0000000000007ff0 ffffea0000753140
    [ 1398.876757]  0000000000600fff 0000000000601000 0000000000600fff ffff880015aa1000
    [ 1398.876764]  0000000000600fff 0000000000601000 ffff88001af19700 ffff8800127cd000
    [ 1398.876772] Call Trace:
    [ 1398.876778]  [<ffffffff811491fb>] unmap_single_vma+0x8b/0xd0
    [ 1398.876784]  [<ffffffff81149a12>] unmap_vmas+0x52/0xa0
    [ 1398.876790]  [<ffffffff81150fa2>] exit_mmap+0x92/0x150
    [ 1398.876797]  [<ffffffff816839ee>] ? _raw_spin_lock_irqsave+0x2e/0x40
    [ 1398.876804]  [<ffffffff8104eef4>] mmput+0x74/0x110
    [ 1398.876809]  [<ffffffff8105778a>] exit_mm+0x10a/0x130
    [ 1398.876814]  [<ffffffff81057909>] do_exit+0x159/0x8e0
    [ 1398.876819]  [<ffffffff8114b139>] ? handle_mm_fault+0x259/0x320
    [ 1398.876824]  [<ffffffff810583ef>] do_group_exit+0x3f/0xa0
    [ 1398.876830]  [<ffffffff81067e19>] get_signal_to_deliver+0x1b9/0x5d0
    [ 1398.876838]  [<ffffffff810132bf>] do_signal+0x3f/0x610
    [ 1398.876844]  [<ffffffff8168408a>] ? error_exit+0x2a/0x60
    [ 1398.876849]  [<ffffffff81683bb8>] ? retint_restore_args+0x5/0x6
    [ 1398.876854]  [<ffffffff81013938>] do_notify_resume+0x88/0xc0
    [ 1398.876860]  [<ffffffff8168bc22>] int_signal+0x12/0x17
    [ 1398.876864] Code: 03 00 00 48 b8 fb 0f 00 00 00 c0 ff ff 48 21 f8 48 83 f8 63 0f 85 3d 03 00 00 48 8b 7d a8 4c 89 75 b0 4d 89 fe 48 8b 1f 49 89 df <48> c7 45 c4 00 00 00 00 c7 45 cc 00 00 00 00 49 8b 3e ff 14 25 
    [ 1398.876919] RIP  [<ffffffff81148c93>] unmap_page_range+0x263/0x740
    [ 1398.876926]  RSP <ffff880007aeda68>
    [ 1398.876940] ---[ end trace e3ccd3d1c4c9e113 ]---
    [ 1398.876945] Fixing recursive fault but reboot is needed!
    

    Similar stuff for redis-server

  8. antirez commented on May 2, 2013

    @antirez
    Contributor

    This sounds like a kernel panic or alike :-) Btw it is likely the result of out of memory.

    Probably it is still possible to run the Redis test in micro instances using:

    ./runtest --clients 1

    This is usually automatically triggered when a very slow box is detected, but probably not in that case.

    TL;DR for the original poster @alexfouche, this is not a Redis issue and you can skip testing at all if you want to try the Sentinel improvements later at some point.

  9. antirez commented on May 2, 2013

    @antirez
    Contributor

    p.s. @karlseguin thank you! Very appreciated.

  10. alexfouche commented on May 6, 2013

    @alexfouche
    Author

    I tested with 2.6.13, and i do not see it fixed. Here is scenario2 from Sentinel point of view:

    Sentinels started, redis1 and 2 stopped

    [12589] 06 May 09:13:52.064 # +sdown master redis2 10.222.241.222 6379
    [12589] 06 May 09:13:52.064 # +sdown master redis1 10.124.27.16 6379
    

    Starting of redis1

    [12589] 06 May 09:14:09.030 * +sentinel sentinel 10.222.241.222:26379 10.222.241.222 26379 @ redis1 10.124.27.16 6379
    [12589] 06 May 09:14:09.031 * +sentinel sentinel 10.220.229.230:26379 10.220.229.230 26379 @ redis1 10.124.27.16 6379
    [12589] 06 May 09:14:09.057 # -sdown master redis1 10.124.27.16 6379
    

    Starting of redis2

    [12589] 06 May 09:14:33.453 # +redirect-to-master redis2 10.222.241.222 6379 realtimeredis1.bla.tld 6379
    [12589] 06 May 09:14:34.208 * +sentinel sentinel 10.222.241.222:26379 10.222.241.222 26379 @ redis2 10.124.27.16 6379
    [12589] 06 May 09:14:34.410 * +sentinel sentinel 10.220.229.230:26379 10.220.229.230 26379 @ redis2 10.124.27.16 6379
    [12589] 06 May 09:14:38.960 * +slave slave 10.222.241.222:6379 10.222.241.222 6379 @ redis1 10.124.27.16 6379
    [12589] 06 May 09:14:43.473 * +slave slave 10.222.241.222:6379 10.222.241.222 6379 @ redis2 10.124.27.16 6379
    

    Stopping of redis1, redis2 is promoted

    [12589] 06 May 09:15:06.186 # +sdown master redis2 10.124.27.16 6379
    [12589] 06 May 09:15:06.386 # +odown master redis2 10.124.27.16 6379 #quorum 2/2
    [12589] 06 May 09:15:06.890 # +sdown master redis1 10.124.27.16 6379
    [12589] 06 May 09:15:07.091 # +odown master redis1 10.124.27.16 6379 #quorum 2/2
    [12589] 06 May 09:15:17.194 # +failover-detected master redis1 10.124.27.16 6379
    [12589] 06 May 09:15:17.294 # +failover-end master redis1 10.124.27.16 6379
    [12589] 06 May 09:15:17.294 # +switch-master redis1 10.124.27.16 6379 10.222.241.222 6379
    [12589] 06 May 09:15:17.500 # +failover-detected master redis2 10.124.27.16 6379
    [12589] 06 May 09:15:17.596 # +failover-end master redis2 10.124.27.16 6379
    [12589] 06 May 09:15:17.596 # +switch-master redis2 10.124.27.16 6379 10.222.241.222 6379
    [12589] 06 May 09:15:17.633 * +sentinel sentinel 10.222.241.222:26379 10.222.241.222 26379 @ redis1 10.222.241.222 6379
    [12589] 06 May 09:15:17.732 * +sentinel sentinel 10.222.241.222:26379 10.222.241.222 26379 @ redis2 10.222.241.222 6379
    [12589] 06 May 09:15:17.736 * +sentinel sentinel 10.220.229.230:26379 10.220.229.230 26379 @ redis1 10.222.241.222 6379
    [12589] 06 May 09:15:17.736 * +sentinel sentinel 10.220.229.230:26379 10.220.229.230 26379 @ redis2 10.222.241.222 6379
    [12589] 06 May 09:15:19.303 # +sdown slave 10.124.27.16:6379 10.124.27.16 6379 @ redis1 10.222.241.222 6379
    [12589] 06 May 09:15:19.604 # +sdown slave 10.124.27.16:6379 10.124.27.16 6379 @ redis2 10.222.241.222 6379
    

    Stopping of redis2

    [12589] 06 May 09:15:41.623 # +sdown master redis1 10.222.241.222 6379
    [12589] 06 May 09:15:41.924 # +sdown master redis2 10.222.241.222 6379
    [12589] 06 May 09:15:42.124 # +odown master redis2 10.222.241.222 6379 #quorum 3/2
    [12589] 06 May 09:15:42.831 # +odown master redis1 10.222.241.222 6379 #quorum 3/2
    

    Start of redis2. redis2 is NOT promoted

    [12589] 06 May 09:16:20.601 * +reboot master redis2 10.222.241.222 6379
    [12589] 06 May 09:16:20.602 # +redirect-to-master redis2 10.222.241.222 6379 realtimeredis1.bla.tld 6379
    [12589] 06 May 09:16:20.602 * +reboot master redis1 10.222.241.222 6379
    [12589] 06 May 09:16:20.602 # +redirect-to-master redis1 10.222.241.222 6379 realtimeredis1.bla.tld 6379
    [12589] 06 May 09:16:22.610 # +sdown master redis2 10.124.27.16 6379
    [12589] 06 May 09:16:22.611 # +sdown master redis1 10.124.27.16 6379
    
  11. Atreyee commented on May 20, 2013

    @Atreyee

    Hi,

    I too am on redis-2.6.13 and also see the scenario2 that @alexfouche pointed out. Unless the master is brought back again, the situation does not change.

  12. orangey commented on Oct 21, 2013

    @orangey

    Scenario 1 problem still exists in redis-2.6.16

  13. technicallyfeasible commented on Dec 5, 2013

    @technicallyfeasible

    I have the same issue with version 2.8.2 but only 2 sentinels and 2 servers. Each server has one redis instance and one sentinel instance running. The quorum needed to detect odown is just 1 in this case and is detected fine.
    However, when I just kill the master server, thus leaving just 1 redis and 1 sentinel instance then this instance repeatedly tries to promote the old master but never tries to promote the previous slave.

  14. antirez commented on Dec 5, 2013

    @antirez
    Contributor

    @technicallyfeasible new Sentinel requires majority in order to perform the failover, whatever the quorum for the ODOWN is set.

  15. technicallyfeasible commented on Dec 5, 2013

    @technicallyfeasible

    @antirez so that means running only 2 or fewer sentinels will never work since there cannot be a majority (if one goes down for 2)?
    This is never mentioned in the documentation and good to know. It somewhat limits usability.

  16. antirez commented on Dec 5, 2013

    @antirez
    Contributor

    Running two Sentinels works great as long as no Sentinel becomes not available at the same time the master becomes not available. In the new documentation online it is mentioned in:

    • The Sentinel documentation, section "Configuring Sentinel".
    • The Sentinel example sentinel.conf provided with the 2.8.x source code.

    You probably read the old documentation of Sentinel, at the same url as before there is the new one with more information.

    I totally understand your point of view, if you have just two physical servers you can't reach majority if one is partitioned away, however this makes the new Sentinel implementation much more reliable.

    Note that it is totally fine to run the third Sentinel in the front end servers. If one Redis server fails, the majority and the failover will be performed by the other Redis server and the other instance running in the front end.

  17. technicallyfeasible commented on Dec 5, 2013

    @technicallyfeasible

    Thank you for the clarification. I have a somewhat even smaller setup at the moment where I have 2 frontend servers which use redis simply as an in memory cache for signalr. I run sentinel on the same instances and this creates the unsupported case you describe that 1 sentinel instance will always go down together with one redis instance and possibly the master.
    I will think about a solution to this case and possibly just add another server. I will work great then, great work!

  18. antirez commented on Dec 5, 2013

    @antirez
    Contributor

    Your situation is basically unsolvable unfortunately! If Sentinel would promote the master without agreement you could end with split-brain condition where both the sides are masters and receiving writes... big inconsistency times ;-)
    Thanks.

  19. karlseguin commented on Dec 6, 2013

    @karlseguin

    If I may, it also doesn't seem like the best fit for Sentinel. I'd set up the two redis servers to be independent and do consistent hashing on the web boxes (many drivers support this by default, though you might need to catch connection failures and rebuild the ring yourself)

  20. ramerang commented on Jun 21, 2016

    @ramerang

    we hit the split-brain condition and the apps ran into writing to two different masters.
    Our Setup: Redis1 Master & Redis2 Slave in Primary DC. Redis3 Slave & Redis4 Slave in Secondary DC.
    Scenario -
    -Network disruption happened between the DCs and lost communication.
    -Secondary DC Redis3 Slave could not reach the master, has been elected as new master
    -Network connectivity has been restored, Apps found two masters and started writing to both
    -Fortunately the election happened again so quickly, old master stayed back in its role, the new master stepped back as slave. unfortunately there happened to be a minor disruption in the App.

    Does Sentinel is the solution for this scenario? we don't use Sentinel as of now.
    Whom we need to consider to be working smarter in this case? App which connecting to Redis or Redis itself? Please advise. Thanks.

  21. antirez commented on Jul 5, 2016

    @antirez
    Contributor

    @ramerang Hello, Sentinel attempts to avoid this kind of issues only in a best effort way, there is no guarantee that the old master will not get writes that will be lost. However Redis can be configured (check the Sentinel doc for more info) in order for isolated masters to stop accepting writes ASAP (in a configurable number of seconds) when they cannot reach the other slaves, so that isolated masters will be unlikely to accept writes.

    In practical terms this means that Sentinel + proper Redis configuration will attempt (in a best effort way) to:

    1. Avoid to accept writes in old-master + clients in the same partition.
    2. Attempt to reconfigure the returning master ASAP as slave when it returns back.
    3. Update the clients configuration ASAP after a failover, if the clients follow the Sentinel client protocol.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions