Fix FLASH eviction issue, the algo relies on correct key count
Former-commit-id: dc260a7f44fe197b9b0022d044d559be88bf91be
This commit is contained in:
parent
1e49dfe8e7
commit
ca3c4474c2
@ -22,7 +22,7 @@ public:
|
|||||||
virtual void retrieve(const char *key, size_t cchKey, callbackSingle fn) const = 0;
|
virtual void retrieve(const char *key, size_t cchKey, callbackSingle fn) const = 0;
|
||||||
virtual size_t clear() = 0;
|
virtual size_t clear() = 0;
|
||||||
virtual bool enumerate(callback fn) const = 0;
|
virtual bool enumerate(callback fn) const = 0;
|
||||||
virtual size_t count(bool fStrict) const = 0;
|
virtual size_t count() const = 0;
|
||||||
|
|
||||||
virtual void beginWriteBatch() {} // NOP
|
virtual void beginWriteBatch() {} // NOP
|
||||||
virtual void endWriteBatch() {} // NOP
|
virtual void endWriteBatch() {} // NOP
|
||||||
|
@ -2195,7 +2195,7 @@ dict_iter redisDbPersistentData::random()
|
|||||||
size_t redisDbPersistentData::size() const
|
size_t redisDbPersistentData::size() const
|
||||||
{
|
{
|
||||||
if (m_spstorage != nullptr)
|
if (m_spstorage != nullptr)
|
||||||
return m_spstorage->count(false);
|
return m_spstorage->count();
|
||||||
|
|
||||||
return dictSize(m_pdict)
|
return dictSize(m_pdict)
|
||||||
+ (m_pdbSnapshot ? (m_pdbSnapshot->size() - dictSize(m_pdictTombstone)) : 0);
|
+ (m_pdbSnapshot ? (m_pdbSnapshot->size() - dictSize(m_pdictTombstone)) : 0);
|
||||||
|
@ -492,14 +492,6 @@ int freeMemoryIfNeeded(void) {
|
|||||||
|
|
||||||
mem_freed = 0;
|
mem_freed = 0;
|
||||||
|
|
||||||
size_t maxKeys = 0;
|
|
||||||
size_t totalKeysFreed = 0;
|
|
||||||
for (int i = 0; i < cserver.dbnum; ++i)
|
|
||||||
maxKeys += g_pserver->db[i]->size();
|
|
||||||
|
|
||||||
// A random search is n log n, so if we run longer than this we know we're not going to terminate
|
|
||||||
maxKeys = static_cast<size_t>(maxKeys * (log2(maxKeys)));
|
|
||||||
|
|
||||||
if (g_pserver->maxmemory_policy == MAXMEMORY_NO_EVICTION)
|
if (g_pserver->maxmemory_policy == MAXMEMORY_NO_EVICTION)
|
||||||
goto cant_free; /* We need to free memory, but policy forbids. */
|
goto cant_free; /* We need to free memory, but policy forbids. */
|
||||||
|
|
||||||
@ -640,7 +632,6 @@ int freeMemoryIfNeeded(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keys_freed++;
|
keys_freed++;
|
||||||
totalKeysFreed++;
|
|
||||||
|
|
||||||
/* When the memory to free starts to be big enough, we may
|
/* When the memory to free starts to be big enough, we may
|
||||||
* start spending so much time here that is impossible to
|
* start spending so much time here that is impossible to
|
||||||
@ -663,16 +654,6 @@ int freeMemoryIfNeeded(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When using FLASH we're not actually evicting and we leave around the key
|
|
||||||
// its possible we tried to evict the whole database and failed to free enough memory
|
|
||||||
// quit if this happens
|
|
||||||
if (totalKeysFreed >= maxKeys)
|
|
||||||
{
|
|
||||||
latencyEndMonitor(latency);
|
|
||||||
latencyAddSampleIfNeeded("eviction-cycle",latency);
|
|
||||||
goto cant_free;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keys_freed <= 0) {
|
if (keys_freed <= 0) {
|
||||||
latencyEndMonitor(latency);
|
latencyEndMonitor(latency);
|
||||||
latencyAddSampleIfNeeded("eviction-cycle",latency);
|
latencyAddSampleIfNeeded("eviction-cycle",latency);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user