Skip to content

Commit a8c4a82

Browse files
committed
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.
1 parent 2b3312e commit a8c4a82

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: memcached.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -3249,6 +3249,16 @@ static inline int make_ascii_get_suffix(char *suffix, item *it, bool return_cas)
32493249
return (p - suffix) + 2;
32503250
}
32513251

3252+
#define IT_REFCOUNT_LIMIT 60000
3253+
static inline item* limited_get(char *key, size_t nkey, conn *c) {
3254+
item *it = item_get(key, nkey, c, DO_UPDATE);
3255+
if (it && it->refcount > IT_REFCOUNT_LIMIT) {
3256+
item_remove(it);
3257+
it = NULL;
3258+
}
3259+
return it;
3260+
}
3261+
32523262
/* ntokens is overwritten here... shrug.. */
32533263
static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, bool return_cas) {
32543264
char *key;
@@ -3273,7 +3283,7 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens,
32733283
return;
32743284
}
32753285

3276-
it = item_get(key, nkey, c, DO_UPDATE);
3286+
it = limited_get(key, nkey, c);
32773287
if (settings.detail_enabled) {
32783288
stats_prefix_record_get(key, nkey, NULL != it);
32793289
}

0 commit comments

Comments
 (0)