When does the state of the slave change when syncing with master?

40 views
Skip to first unread message

M S

unread,
Sep 29, 2011, 11:17:22 AM9/29/11
to Redis DB
The connection between the slave and the master is sometimes broken,
and the slave reconnects automatically (thanks for that feature).

When doing tests I have monitored the number of keys in the slave's
database, and I see the number of keys reduced to 0 and steadily
growing until it matches the master.

My question is what happens when a client connects to the slave while
it is syncing after a reconnection. Does the slave keep a copy of the
previous state and serve old data until it is synced? If so perhaps
the number of keys returned by "info" should remain unchanged until
the sync is done.

Josiah Carlson

unread,
Oct 6, 2011, 4:58:54 PM10/6/11
to redi...@googlegroups.com
On Thu, Sep 29, 2011 at 8:17 AM, M S <mstro...@gmail.com> wrote:
> The connection between the slave and the master is sometimes broken,
> and the slave reconnects automatically (thanks for that feature).
>
> When doing tests I have monitored the number of keys in the slave's
> database, and I see the number of keys reduced to 0 and steadily
> growing until it matches the master.
>
> My question is what happens when a client connects to the slave while
> it is syncing after a reconnection. Does the slave keep a copy of the
> previous state and serve old data until it is synced? If so perhaps

It does not keep a copy of the previous state at all.

> the number of keys returned by "info" should remain unchanged until
> the sync is done.

You can monitor the info command to watch for when the slave is done
syncing (there is a specific info field that I can't remember right
now that tells you when it is ready).

Regards,
- Josiah

M S

unread,
Oct 10, 2011, 7:52:39 AM10/10/11
to Redis DB
On 6 Okt, 22:58, Josiah Carlson <josiah.carl...@gmail.com> wrote:
> On Thu, Sep 29, 2011 at 8:17 AM, M S <mstrofpp...@gmail.com> wrote:
> > My question is what happens when a client connects to the slave while
> > it is syncing after a reconnection. Does the slave keep a copy of the
> > previous state and serve old data until it is synced? If so perhaps
>
> It does not keep a copy of the previous state at all.
>

If that's the case, it reduces the usability of Redis significantly
for my use case. I use Redis as a database, and not a cache like
Memcached, so it's important that the slaves have a minimum
consistency. The database contains several million items so it is
acceptable that there is some lag when new items are added, but to go
from 15 million to 0 and then wait 30 minutes until it is synchronized
with the master will cause a lot of issues.

Is there a way to disable Redis' synchronization when reconnecting to
master? I would rather risk outdated information than the current
behaviour.

Josiah Carlson

unread,
Oct 10, 2011, 11:59:30 AM10/10/11
to redi...@googlegroups.com
On Mon, Oct 10, 2011 at 4:52 AM, M S <mstro...@gmail.com> wrote:
> On 6 Okt, 22:58, Josiah Carlson <josiah.carl...@gmail.com> wrote:
>> On Thu, Sep 29, 2011 at 8:17 AM, M S <mstrofpp...@gmail.com> wrote:
>> > My question is what happens when a client connects to the slave while
>> > it is syncing after a reconnection. Does the slave keep a copy of the
>> > previous state and serve old data until it is synced? If so perhaps
>>
>> It does not keep a copy of the previous state at all.
>>
>
> If that's the case, it reduces the usability of Redis significantly
> for my use case. I use Redis as a database, and not a cache like
> Memcached, so it's important that the slaves have a minimum
> consistency. The database contains several million items so it is
> acceptable that there is some lag when new items are added, but to go
> from 15 million to 0 and then wait 30 minutes until it is synchronized
> with the master will cause a lot of issues.

If it's taking 30 minutes to load your data, it sounds like a
potential network issue. It used to take us 15 minutes to load a Redis
database that was 45 gigs in memory from a local disk (it had about
300 million items of various types and sizes).

Also, 30 minutes to load the data across the network, and you are
having issues that lead to Redis disconnecting... it sounds to me like
the network between your machines may not be great. Is it
multi-datacenter? Have you done long-term connectivity tests? How big
is your dump.rdb on the master?

> Is there a way to disable Redis' synchronization when reconnecting to
> master? I would rather risk outdated information than the current
> behaviour.

You mean, is there any way to prevent Redis from dropping the old data
it has in memory before loading the new dump from the master? No.
There is no way. It was discussed before, but it was ultimately
rejected because the memory doubling would be confusing to other
users.

One thing you could do is if your clients make a read request against
a slave, and that is missing data, you could hit the master. If you
are in the same datacenter, that shouldn't be too bad, as hopefully
your slaves aren't down very often. If it is multi-datacenter, then
you have other problems.

If you are multi-datacenter, you may want to consider using OpenVPN to
bridge the two (or more) datacenters. On the one hand, it will be a
bit slower. On the other hand, OpenVPN does some other stuff that
keeps connections open even in some nasty scenarios. For example, I've
created OpenVPN connections from California through Texas (Rackspace)
to Virginia (EC2). I suspend my computer, drive 45 minutes home, and
bring my computer back up. Once my computer gets DHCP again at home,
2-3 seconds later I am left with the same blinking prompt and console
that I had when I left work.

Regards,
- Josiah

Reply all
Reply to author
Forward
0 new messages