Skip to content
Permalink
Browse files Browse the repository at this point in the history
Don't overflow item refcount on get
Counts as a miss if the refcount is too high. ASCII multigets are the only
time refcounts can be held for so long.

doing a dirty read of refcount. is aligned.

trying to avoid adding an extra refcount branch for all calls of item_get due
to performance. might be able to move it in there after logging refactoring
simplifies some of the branches.
  • Loading branch information
dormando committed May 23, 2017
1 parent 2b3312e commit a8c4a82
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion memcached.c
Expand Up @@ -3249,6 +3249,16 @@ static inline int make_ascii_get_suffix(char *suffix, item *it, bool return_cas)
return (p - suffix) + 2;
}

#define IT_REFCOUNT_LIMIT 60000
static inline item* limited_get(char *key, size_t nkey, conn *c) {
item *it = item_get(key, nkey, c, DO_UPDATE);
if (it && it->refcount > IT_REFCOUNT_LIMIT) {
item_remove(it);
it = NULL;
}
return it;
}

/* ntokens is overwritten here... shrug.. */
static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, bool return_cas) {
char *key;
Expand All @@ -3273,7 +3283,7 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens,
return;
}

it = item_get(key, nkey, c, DO_UPDATE);
it = limited_get(key, nkey, c);
if (settings.detail_enabled) {
stats_prefix_record_get(key, nkey, NULL != it);
}
Expand Down

0 comments on commit a8c4a82

Please sign in to comment.