add lookup limit to active subkey expire
Former-commit-id: b44f504ced6b8259fd5b6553cec932b512e5dfa2
This commit is contained in:
parent
9c2a85e8c8
commit
c8144daafa
@ -68,11 +68,12 @@ void activeExpireCycleExpireFullKey(redisDb *db, const char *key) {
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
int activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now, int &tried) {
|
||||
if (!e.FFat())
|
||||
{
|
||||
activeExpireCycleExpireFullKey(db, e.key());
|
||||
return;
|
||||
++tried;
|
||||
return 1;
|
||||
}
|
||||
|
||||
expireEntryFat *pfat = e.pfatentry();
|
||||
@ -86,6 +87,7 @@ void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
|
||||
while (!pfat->FEmpty())
|
||||
{
|
||||
++tried;
|
||||
if (pfat->nextExpireEntry().when > now)
|
||||
break;
|
||||
|
||||
@ -93,7 +95,7 @@ void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
if (pfat->nextExpireEntry().spsubkey == nullptr)
|
||||
{
|
||||
activeExpireCycleExpireFullKey(db, e.key());
|
||||
return;
|
||||
return ++deleted;
|
||||
}
|
||||
|
||||
switch (val->type)
|
||||
@ -103,7 +105,7 @@ void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
deleted++;
|
||||
if (setTypeSize(val) == 0) {
|
||||
activeExpireCycleExpireFullKey(db, e.key());
|
||||
return;
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -113,7 +115,7 @@ void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
deleted++;
|
||||
if (hashTypeLength(val) == 0) {
|
||||
activeExpireCycleExpireFullKey(db, e.key());
|
||||
return;
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -123,7 +125,7 @@ void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
deleted++;
|
||||
if (zsetLength(val) == 0) {
|
||||
activeExpireCycleExpireFullKey(db, e.key());
|
||||
return;
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -138,7 +140,7 @@ void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
decrRefCount(val);
|
||||
}, true /*fLock*/, true /*fForceQueue*/);
|
||||
}
|
||||
return;
|
||||
return deleted;
|
||||
|
||||
case OBJ_LIST:
|
||||
default:
|
||||
@ -151,6 +153,9 @@ void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
|
||||
pfat->popfrontExpireEntry();
|
||||
fTtlChanged = true;
|
||||
if ((tried % ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP) == 0) {
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pfat->FEmpty() && fTtlChanged)
|
||||
@ -177,6 +182,7 @@ void activeExpireCycleExpire(redisDb *db, expireEntry &e, long long now) {
|
||||
{
|
||||
removeExpire(db, &objKey);
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
int parseUnitString(const char *sz)
|
||||
@ -376,16 +382,14 @@ void activeExpireCycleCore(int type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t expired = 0;
|
||||
size_t tried = 0;
|
||||
int expired = 0;
|
||||
int tried = 0;
|
||||
long long check = ACTIVE_EXPIRE_CYCLE_FAST_DURATION; // assume a check is roughly 1us. It isn't but good enough
|
||||
db->expireitr = db->setexpire->enumerate(db->expireitr, now, [&](expireEntry &e) __attribute__((always_inline)) {
|
||||
if (e.when() < now)
|
||||
{
|
||||
activeExpireCycleExpire(db, e, now);
|
||||
++expired;
|
||||
expired += activeExpireCycleExpire(db, e, now, tried);
|
||||
}
|
||||
++tried;
|
||||
|
||||
if ((tried % ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP) == 0)
|
||||
{
|
||||
@ -493,8 +497,8 @@ void expireSlaveKeys(void) {
|
||||
if (itr != db->setexpire->end())
|
||||
{
|
||||
if (itr->when() < start) {
|
||||
activeExpireCycleExpire(g_pserver->db+dbid,*itr,start);
|
||||
expired = 1;
|
||||
int tried = 0;
|
||||
expired = activeExpireCycleExpire(g_pserver->db+dbid,*itr,start,tried);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user