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