You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Very large keyspaces cause SAVE/BGSAVE to write an empty RDB file #1929
OS: Ubuntu 12.04 x86_64, Linux 3.11.0-13-generic
Redis version: 2.6.16, built with GCC 4.8.1 (though it may affect all versions)
I traced this bug to an issue in the way dict and dictIterator interact. In dictNext the condition (iter->index >= (signed) ht->size) checks if the iterator has finished iterating the first table in the dict, but this can cause issues in a 64-bit environment because iter->index is an int (32-bit) and ht->size is an unsigned long (64-bit). The comparison is done in 32 bits (the opcode is cmp 8(%r12), %eax as built on my system), so if ht->size is 0x80000000, it's actually perceived as a negative number, which makes dictNext return NULL as if the dict was empty.
This means the rdb saving procedure writes a file consisting of just the rdb header, a db selector, and end opcode even though the db contains many millions of keys, which breaks persistence and replication. It probably also affects commands that iterate the keyspace like SCAN and KEYS.
I think the fix would be to change the type of dictIterator::index to long, to match the size of dictht::size.
Actually it looks like it's more than that - the (signed) cast in the condition implicitly means (signed int), when it really should be (signed long). Without long, ht->size is still read as a 32-bit value. It looks like casts like (signed) and (unsigned) are used in several places in the redis codebase; I think these should all include long or int for the same reason.
Not sure if we're doing it wrong or what, but we also have several nodes with key counts that would trigger this problem, but we don't SAVE/BGSAVE at all, so it wouldn't ever affect us.
p.s. note that Redis dict.c remains inherently not ready to properly handle so large datasets because the hash functions outputs are 32 bit. It only works because of the chaining nature of the hash table, but performances will start to suffer once the chains start to get longer.
Activity
dictIterator::index: int -> long to avoid overflows. Closes redis#1929
jcspencer commentedon Aug 12, 2014
Fixed in #1930.
fuzziqersoftware commentedon Aug 12, 2014
Actually it looks like it's more than that - the
(signed)cast in the condition implicitly means(signed int), when it really should be(signed long). Withoutlong,ht->sizeis still read as a 32-bit value. It looks like casts like(signed)and(unsigned)are used in several places in the redis codebase; I think these should all includelongorintfor the same reason.mattsta commentedon Aug 12, 2014
Did you re-discover this or were you just testing https://github.com/antirez/redis/issues/1814?
If two people independently discovered Redis can't save/restore billions of keys in one instance yet... what kind of datasets are you using?!
michael-grunder commentedon Aug 12, 2014
Not sure if we're doing it wrong or what, but we also have several nodes with key counts that would trigger this problem, but we don't SAVE/BGSAVE at all, so it wouldn't ever affect us.
We use it mostly to store cat gifs, naturally.
Cast to right type in dictNext().
antirez commentedon Aug 26, 2014
Thanks, the issue was fixed in the following two commits:
The rehashing index was also of the wrong type.
antirez commentedon Aug 26, 2014
p.s. note that Redis dict.c remains inherently not ready to properly handle so large datasets because the hash functions outputs are 32 bit. It only works because of the chaining nature of the hash table, but performances will start to suffer once the chains start to get longer.
Fix dictRehash assert casting type.
Cast to right type in dictNext().
Fix dictRehash assert casting type.
Cast to right type in dictNext().
Fix dictRehash assert casting type.