Permalink
Browse files

[memcached] fixed to reset item's clsid by destination slab size

Reviewed By: sgrimm
Test Plan: mc078.sf2p testing
  • Loading branch information...
1 parent b233d85 commit d5721808ea2744cf9ee09e612c5e93e981cff086 hzhao committed Oct 22, 2007
Showing with 19 additions and 7 deletions.
  1. +8 −4 src/items.c
  2. +2 −1 src/items.h
  3. +9 −2 src/slabs.c
View
12 src/items.c
@@ -160,7 +160,7 @@ item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_tim
return it;
}
-void item_free(item *it) {
+void item_free(item *it, bool to_freelist) {
size_t ntotal = ITEM_ntotal(it);
assert((it->it_flags & ITEM_LINKED) == 0);
assert(it != heads[it->slabs_clsid]);
@@ -171,7 +171,7 @@ void item_free(item *it) {
it->slabs_clsid = 0;
it->it_flags |= ITEM_SLABBED;
DEBUG_REFCNT(it, 'F');
- slabs_free(it, ntotal);
+ if (to_freelist) slabs_free(it, ntotal);
}
/**
@@ -247,6 +247,10 @@ int do_item_link(item *it) {
}
void do_item_unlink(item *it, long flags) {
+ do_item_unlink_impl(it, flags, true);
+}
+
+void do_item_unlink_impl(item *it, long flags, bool to_freelist) {
if ((it->it_flags & ITEM_LINKED) != 0) {
it->it_flags &= ~ITEM_LINKED;
STATS_LOCK();
@@ -258,7 +262,7 @@ void do_item_unlink(item *it, long flags) {
}
assoc_delete(ITEM_key(it), it->nkey);
item_unlink_q(it);
- if (it->refcount == 0) item_free(it);
+ if (it->refcount == 0) item_free(it, to_freelist);
}
}
@@ -270,7 +274,7 @@ void do_item_remove(item *it) {
}
assert((it->it_flags & ITEM_DELETED) == 0 || it->refcount != 0);
if (it->refcount == 0 && (it->it_flags & ITEM_LINKED) == 0) {
- item_free(it);
+ item_free(it, true);
}
}
View
3 src/items.h
@@ -8,11 +8,12 @@
void item_init(void);
/*@null@*/
item *do_item_alloc(char *key, const size_t nkey, const int flags, const rel_time_t exptime, const int nbytes);
-void item_free(item *it);
+void item_free(item *it, bool to_freelist);
bool item_size_ok(const size_t nkey, const int flags, const int nbytes);
int do_item_link(item *it); /** may fail if transgresses limits */
void do_item_unlink(item *it, long flags);
+void do_item_unlink_impl(item *it, long flags, bool to_freelist);
void do_item_remove(item *it);
void do_item_update(item *it); /** update LRU time to current and reposition */
int do_item_replace(item *it, item *new_it);
View
11 src/slabs.c
@@ -366,8 +366,7 @@ int do_slabs_reassign(unsigned char srcid, unsigned char dstid) {
for (iter = slab; iter < slab_end; iter += p->size) {
item *it = (item *)iter;
if (it->slabs_clsid) {
- do_item_unlink(it, UNLINK_IS_EVICT);
- it->slabs_clsid = 0;
+ do_item_unlink_impl(it, UNLINK_IS_EVICT, false);
}
}
@@ -388,6 +387,14 @@ int do_slabs_reassign(unsigned char srcid, unsigned char dstid) {
dp->end_page_ptr = slab;
dp->end_page_free = dp->perslab;
dp->rebalanced_to++;
+
+ /* watch out that "dp->size", we are resetting clsid by new sizes */
+ for (iter = slab; iter < slab_end; iter += dp->size) {
+ item *it = (item *)iter;
+ if (it->slabs_clsid) {
+ it->slabs_clsid = 0;
+ }
+ }
return 1;
}

0 comments on commit d572180

Please sign in to comment.