diff --git a/src/storage/rocksdb.cpp b/src/storage/rocksdb.cpp index e98408dcf..fe2e7cbf5 100644 --- a/src/storage/rocksdb.cpp +++ b/src/storage/rocksdb.cpp @@ -26,7 +26,7 @@ bool FInternalKey(const char *key, size_t cch) std::string getPrefix(unsigned int hashslot) { - HASHSLOT_PREFIX_TYPE slot = (HASHSLOT_PREFIX_TYPE)hashslot; + HASHSLOT_PREFIX_TYPE slot = HASHSLOT_PREFIX_ENDIAN((HASHSLOT_PREFIX_TYPE)hashslot); char *hash_char = (char *)&slot; return std::string(hash_char, HASHSLOT_PREFIX_BYTES); } @@ -209,14 +209,14 @@ bool RocksDBStorageProvider::enumerate_hashslot(callback fn, unsigned int hashsl for (it->Seek(prefix); it->Valid(); it->Next()) { if (FInternalKey(it->key().data(), it->key().size())) continue; - if (*(HASHSLOT_PREFIX_TYPE *)it->key().data() != hashslot) + if (HASHSLOT_PREFIX_RECOVER(*(HASHSLOT_PREFIX_TYPE *)it->key().data()) != hashslot) break; ++count; bool fContinue = fn(it->key().data()+HASHSLOT_PREFIX_BYTES, it->key().size()-HASHSLOT_PREFIX_BYTES, it->value().data(), it->value().size()); if (!fContinue) break; } - bool full_iter = !it->Valid() || (*(HASHSLOT_PREFIX_TYPE *)it->key().data() != hashslot); + bool full_iter = !it->Valid() || (HASHSLOT_PREFIX_RECOVER(*(HASHSLOT_PREFIX_TYPE *)it->key().data()) != hashslot); if (full_iter && count != g_pserver->cluster->slots_keys_count[hashslot]) { printf("WARNING: rocksdb hashslot count mismatch"); diff --git a/src/storage/rocksdb.h b/src/storage/rocksdb.h index 3cf084115..094e085b4 100644 --- a/src/storage/rocksdb.h +++ b/src/storage/rocksdb.h @@ -4,11 +4,14 @@ #include "../IStorage.h" #include #include +#include #include "../fastlock.h" #define INTERNAL_KEY_PREFIX "\x00\x04\x03\x00\x05\x02\x04" #define HASHSLOT_PREFIX_TYPE uint16_t #define HASHSLOT_PREFIX_BYTES sizeof(HASHSLOT_PREFIX_TYPE) +#define HASHSLOT_PREFIX_ENDIAN htole16 +#define HASHSLOT_PREFIX_RECOVER le16toh static const char count_key[] = INTERNAL_KEY_PREFIX "__keydb__count\1"; static const char version_key[] = INTERNAL_KEY_PREFIX "__keydb__version\1"; static const char meta_key[] = INTERNAL_KEY_PREFIX "__keydb__metadata\1";