static void do_item_unlink(struct demo_engine *engine, hash_item *it, enum item_unlink_cause cause) { /* cause: item unlink cause will be used, later */ const char *key = dm_item_get_key(it); size_t stotal = ITEM_stotal(engine, it); MEMCACHED_ITEM_UNLINK(key, it->nkey, it->nbytes); if ((it->iflag & ITEM_LINKED) != 0) { /* unlink the item from hash table */ dm_assoc_delete(engine, it->hval, key, it->nkey); it->iflag &= ~ITEM_LINKED; /* update item statistics */ pthread_mutex_lock(&engine->stats.lock); engine->stats.curr_bytes -= stotal; engine->stats.curr_items -= 1; pthread_mutex_unlock(&engine->stats.lock); /* free the item if no one reference it */ if (it->refcount == 0) { do_item_free(engine, it); } } }
void do_item_unlink(item *it) { MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes); if ((it->it_flags & ITEM_LINKED) != 0) { it->it_flags &= ~ITEM_LINKED; STATS_LOCK(); stats.curr_bytes -= ITEM_ntotal(it); stats.curr_items -= 1; STATS_UNLOCK(); assoc_delete(ITEM_key(it), it->nkey); item_unlink_q(it); if (it->refcount == 0) item_free(it); } }
/* FIXME: Is it necessary to keep this copy/pasted code? */ void do_item_unlink_nolock(item *it, const uint32_t hv) { MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes); if ((it->it_flags & ITEM_LINKED) != 0) { it->it_flags &= ~ITEM_LINKED; STATS_LOCK(); stats.curr_bytes -= ITEM_ntotal(it); stats.curr_items -= 1; STATS_UNLOCK(); assoc_delete(ITEM_key(it), it->nkey, hv); item_unlink_q(it); do_item_remove(it); } }
/* slawek */ void do_item_unlink_nolock_nostat(item *it, const uint32_t hv, uint64_t *items_removed, uint64_t *bytes_removed) { MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes); if ((it->it_flags & ITEM_LINKED) != 0) { it->it_flags &= ~ITEM_LINKED; *items_removed += 1; *bytes_removed += ITEM_ntotal(it); assoc_delete(ITEM_key(it), it->nkey, hv); item_unlink_q(it); do_item_remove(it); } }
/* FIXME: Is it necessary to keep this copy/pasted code? */ void do_item_unlink_nolock(item *it, const uint32_t hv) { syslog(LOG_INFO, "[%s:%s:%d]", __FILE__, __func__, __LINE__); MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes); if ((it->it_flags & ITEM_LINKED) != 0) { it->it_flags &= ~ITEM_LINKED; STATS_LOCK(); stats.curr_bytes -= ITEM_ntotal(it); stats.curr_items -= 1; STATS_UNLOCK(); assoc_delete(ITEM_key(it), it->nkey, hv); item_unlink_q(it); do_item_remove(it); } }
//将item从hashtable和LRU链中移除,而且还释放掉 item 所占的内存 (其实只是把 item 放到空闲链表中),是do_item_link的逆操作 void do_item_unlink(item *it, const uint32_t hv) { MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes); mutex_lock(&cache_lock);//执行同步 if ((it->it_flags & ITEM_LINKED) != 0) {//判断状态值,保证item还在LRU队列中 it->it_flags &= ~ITEM_LINKED;//修改状态值 STATS_LOCK();//更新统计信息 stats.curr_bytes -= ITEM_ntotal(it); stats.curr_items -= 1; STATS_UNLOCK(); assoc_delete(ITEM_key(it), it->nkey, hv);//从Hash表中删除 item_unlink_q(it);//将item从slabclass对应的LRU队列摘除 do_item_remove(it);//释放 item 所占的内存 } mutex_unlock(&cache_lock); }
void do_item_unlink(item *it, const uint32_t hv) { syslog(LOG_INFO, "[%s:%s:%d]", __FILE__, __func__, __LINE__); MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes); mutex_lock(&cache_lock); if ((it->it_flags & ITEM_LINKED) != 0) { it->it_flags &= ~ITEM_LINKED;//设置为非linked STATS_LOCK(); stats.curr_bytes -= ITEM_ntotal(it); stats.curr_items -= 1; STATS_UNLOCK(); assoc_delete(ITEM_key(it), it->nkey, hv); //从hash表中删除 item_unlink_q(it); //从LRU链中删除 do_item_remove(it); } mutex_unlock(&cache_lock); }
void do_item_unlink(struct default_engine *engine, hash_item *it) { MEMCACHED_ITEM_UNLINK(item_get_key(it), it->nkey, it->nbytes); if ((it->iflag & ITEM_LINKED) != 0) { it->iflag &= ~ITEM_LINKED; pthread_mutex_lock(&engine->stats.lock); engine->stats.curr_bytes -= ITEM_ntotal(engine, it); engine->stats.curr_items -= 1; pthread_mutex_unlock(&engine->stats.lock); assoc_delete(engine, engine->server.core->hash(item_get_key(it), it->nkey, 0), item_get_key(it), it->nkey); item_unlink_q(engine, it); if (it->refcount == 0) { item_free(engine, it); } } }
//从哈希表和LRU中删除 void do_item_unlink(item *it, const uint32_t hv) { MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes); mutex_lock(&cache_lock); if ((it->it_flags & ITEM_LINKED) != 0) { it->it_flags &= ~ITEM_LINKED; STATS_LOCK(); stats.curr_bytes -= ITEM_ntotal(it); stats.curr_items -= 1; STATS_UNLOCK(); //从哈希表中删除 assoc_delete(ITEM_key(it), it->nkey, hv); //从链表中删除 item_unlink_q(it); //向slab归还这个item do_item_remove(it); } mutex_unlock(&cache_lock); }
void do_item_unlink(struct default_engine *engine, hash_item *it) { const hash_key* key = item_get_key(it); MEMCACHED_ITEM_UNLINK(hash_key_get_client_key(key), hash_key_get_client_key_len(key), it->nbytes); if ((it->iflag & ITEM_LINKED) != 0) { it->iflag &= ~ITEM_LINKED; cb_mutex_enter(&engine->stats.lock); engine->stats.curr_bytes -= ITEM_ntotal(engine, it); engine->stats.curr_items -= 1; cb_mutex_exit(&engine->stats.lock); assoc_delete(engine, crc32c(hash_key_get_key(key), hash_key_get_key_len(key), 0), key); item_unlink_q(engine, it); if (it->refcount == 0 || engine->scrubber.force_delete) { item_free(engine, it); } } }