How to delete all keys under sentinel watch?

338 views
Skip to first unread message

Clo Min

unread,
Sep 21, 2014, 4:52:42 AM9/21/14
to redi...@googlegroups.com
Hi all,

When I do a FLUSHDB that takes longer than the sentinels timeout (down-after-milliseconds parameter), the sentinels think the master is down and perform a failover. When the old master is back from the FLUSHDB, the sentinels demote it to slave (i.e., the effect of FLUSHDB is canceled).

- is this the expected behaviour?
- how to delete all keys of a master under sentinel watch?

Thanks,

Josiah Carlson

unread,
Sep 23, 2014, 6:19:51 PM9/23/14
to redi...@googlegroups.com
The simplest solution would be to increase your 'down-after-milliseconds' option in your Sentinel configurations, but that may increase the amount of time you have to wait for a failure to be detected.

As an alternative, you can fetch a subset of your keyspace at a time, and delete the keys in chunks. It is not atomic (if someone writes data while you are clearing your data, that data may or may not survive the cleaning)

Here is a simple Python function that will clean out 100 keys at a time (by default) from a provided db connection:

def clean(conn, count=100, match=None):
    cursor = '0'
    while cursor != 0:
        cursor, keys = conn.scan(cursor, match=match, count=count)
        if keys:
            conn.delete(*keys)

That function should prevent the sentinel timeouts you've been experiencing, but as I mentioned before, if other writes occur, you may or may not have the newly written data after the clean() function completes.

 - Josiah


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Georgios Davaris

unread,
Mar 3, 2015, 5:32:54 PM3/3/15
to redi...@googlegroups.com
If your application can cope with only one redis-server, I would suggest stopping all the redis-server slaves and then doing a FLUSHDB on the master.
Then just bring them up one by one and they should sync the changes from the master.
Reply all
Reply to author
Forward
0 new messages