"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/expire.c" between
redis-6.2-rc3.tar.gz and redis-6.2.0.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

expire.c  (redis-6.2-rc3):expire.c  (redis-6.2.0)
skipping to change at line 86 skipping to change at line 86
return 0; return 0;
} }
} }
/* Try to expire a few timed out keys. The algorithm used is adaptive and /* Try to expire a few timed out keys. The algorithm used is adaptive and
* will use few CPU cycles if there are few expiring keys, otherwise * will use few CPU cycles if there are few expiring keys, otherwise
* it will get more aggressive to avoid that too much memory is used by * it will get more aggressive to avoid that too much memory is used by
* keys that can be removed from the keyspace. * keys that can be removed from the keyspace.
* *
* Every expire cycle tests multiple databases: the next call will start * Every expire cycle tests multiple databases: the next call will start
* again from the next db, with the exception of exists for time limit: in that * again from the next db. No more than CRON_DBS_PER_CALL databases are
* case we restart again from the last database we were processing. Anyway * tested at every iteration.
* no more than CRON_DBS_PER_CALL databases are tested at every iteration.
* *
* The function can perform more or less work, depending on the "type" * The function can perform more or less work, depending on the "type"
* argument. It can execute a "fast cycle" or a "slow cycle". The slow * argument. It can execute a "fast cycle" or a "slow cycle". The slow
* cycle is the main way we collect expired cycles: this happens with * cycle is the main way we collect expired cycles: this happens with
* the "server.hz" frequency (usually 10 hertz). * the "server.hz" frequency (usually 10 hertz).
* *
* However the slow cycle can exit for timeout, since it used too much time. * However the slow cycle can exit for timeout, since it used too much time.
* For this reason the function is also invoked to perform a fast cycle * For this reason the function is also invoked to perform a fast cycle
* at every event loop cycle, in the beforeSleep() function. The fast cycle * at every event loop cycle, in the beforeSleep() function. The fast cycle
* will try to perform less work, but will do it much more often. * will try to perform less work, but will do it much more often.
skipping to change at line 144 skipping to change at line 143
ACTIVE_EXPIRE_CYCLE_KEYS_PER_LOOP/4*effort, ACTIVE_EXPIRE_CYCLE_KEYS_PER_LOOP/4*effort,
config_cycle_fast_duration = ACTIVE_EXPIRE_CYCLE_FAST_DURATION + config_cycle_fast_duration = ACTIVE_EXPIRE_CYCLE_FAST_DURATION +
ACTIVE_EXPIRE_CYCLE_FAST_DURATION/4*effort, ACTIVE_EXPIRE_CYCLE_FAST_DURATION/4*effort,
config_cycle_slow_time_perc = ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC + config_cycle_slow_time_perc = ACTIVE_EXPIRE_CYCLE_SLOW_TIME_PERC +
2*effort, 2*effort,
config_cycle_acceptable_stale = ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE- config_cycle_acceptable_stale = ACTIVE_EXPIRE_CYCLE_ACCEPTABLE_STALE-
effort; effort;
/* This function has some global state in order to continue the work /* This function has some global state in order to continue the work
* incrementally across calls. */ * incrementally across calls. */
static unsigned int current_db = 0; /* Last DB tested. */ static unsigned int current_db = 0; /* Next DB to test. */
static int timelimit_exit = 0; /* Time limit hit in previous call? */ static int timelimit_exit = 0; /* Time limit hit in previous call? */
static long long last_fast_cycle = 0; /* When last fast cycle ran. */ static long long last_fast_cycle = 0; /* When last fast cycle ran. */
int j, iteration = 0; int j, iteration = 0;
int dbs_per_call = CRON_DBS_PER_CALL; int dbs_per_call = CRON_DBS_PER_CALL;
long long start = ustime(), timelimit, elapsed; long long start = ustime(), timelimit, elapsed;
/* When clients are paused the dataset should be static not just from the /* When clients are paused the dataset should be static not just from the
* POV of clients not being able to write, but also from the POV of * POV of clients not being able to write, but also from the POV of
* expires and evictions of keys not being performed. */ * expires and evictions of keys not being performed. */
skipping to change at line 510 skipping to change at line 509
* for *AT variants of the command, or the current time for relative expires). * for *AT variants of the command, or the current time for relative expires).
* *
* unit is either UNIT_SECONDS or UNIT_MILLISECONDS, and is only used for * unit is either UNIT_SECONDS or UNIT_MILLISECONDS, and is only used for
* the argv[2] parameter. The basetime is always specified in milliseconds. */ * the argv[2] parameter. The basetime is always specified in milliseconds. */
void expireGenericCommand(client *c, long long basetime, int unit) { void expireGenericCommand(client *c, long long basetime, int unit) {
robj *key = c->argv[1], *param = c->argv[2]; robj *key = c->argv[1], *param = c->argv[2];
long long when; /* unix time in milliseconds when the key will expire. */ long long when; /* unix time in milliseconds when the key will expire. */
if (getLongLongFromObjectOrReply(c, param, &when, NULL) != C_OK) if (getLongLongFromObjectOrReply(c, param, &when, NULL) != C_OK)
return; return;
int negative_when = when < 0;
if (unit == UNIT_SECONDS) when *= 1000; if (unit == UNIT_SECONDS) when *= 1000;
when += basetime; when += basetime;
if (((when < 0) && !negative_when) || ((when-basetime > 0) && negative_when)
) {
/* EXPIRE allows negative numbers, but we can at least detect an
* overflow by either unit conversion or basetime addition. */
addReplyErrorFormat(c, "invalid expire time in %s", c->cmd->name);
return;
}
/* No key, return zero. */ /* No key, return zero. */
if (lookupKeyWrite(c->db,key) == NULL) { if (lookupKeyWrite(c->db,key) == NULL) {
addReply(c,shared.czero); addReply(c,shared.czero);
return; return;
} }
if (checkAlreadyExpired(when)) { if (checkAlreadyExpired(when)) {
robj *aux; robj *aux;
int deleted = server.lazyfree_lazy_expire ? dbAsyncDelete(c->db,key) : int deleted = server.lazyfree_lazy_expire ? dbAsyncDelete(c->db,key) :
 End of changes. 4 change blocks. 
6 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)