MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / getIdle

Function getIdle

src/evict.cpp:103–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103unsigned long long getIdle(robj *obj, const expireEntry *e) {
104 unsigned long long idle;
105 /* Calculate the idle time according to the policy. This is called
106 * idle just because the code initially handled LRU, but is in fact
107 * just a score where an higher score means better candidate. */
108 if (g_pserver->maxmemory_policy & MAXMEMORY_FLAG_LRU) {
109 idle = (obj != nullptr) ? estimateObjectIdleTime(obj) : 0;
110 } else if (g_pserver->maxmemory_policy & MAXMEMORY_FLAG_LFU) {
111 /* When we use an LRU policy, we sort the keys by idle time
112 * so that we expire keys starting from greater idle time.
113 * However when the policy is an LFU one, we have a frequency
114 * estimation, and we want to evict keys with lower frequency
115 * first. So inside the pool we put objects using the inverted
116 * frequency subtracting the actual frequency to the maximum
117 * frequency of 255. */
118 idle = 255-LFUDecrAndReturn(obj);
119 } else if (g_pserver->maxmemory_policy == MAXMEMORY_VOLATILE_TTL) {
120 /* In this case the sooner the expire the better. */
121 if (e != nullptr)
122 idle = ULLONG_MAX - e->when();
123 else
124 idle = 0;
125 } else if (g_pserver->maxmemory_policy & MAXMEMORY_FLAG_ALLKEYS) {
126 idle = ULLONG_MAX;
127 } else {
128 serverPanic("Unknown eviction policy in storage eviction");
129 }
130 return idle;
131}
132
133/* LRU approximation algorithm
134 *

Callers 2

processEvictionCandidateFunction · 0.85
performEvictionsFunction · 0.85

Calls 3

estimateObjectIdleTimeFunction · 0.85
LFUDecrAndReturnFunction · 0.85
whenMethod · 0.45

Tested by

no test coverage detected