Beispiel #1
0
/*
 * Stores an item in the cache (high level, obeys set/add/replace semantics)
 */
enum store_item_type store_item(item *item, int comm, conn* c) {
    enum store_item_type ret;

    pthread_mutex_lock(&cache_lock);
    ret = do_store_item(item, comm, c);
    pthread_mutex_unlock(&cache_lock);
    return ret;
}
Beispiel #2
0
/*
 * Stores an item in the cache (high level, obeys set/add/replace semantics)
 */
enum store_item_type store_item(item *item, int comm, conn* c) {
    enum store_item_type ret;
    uint32_t hv;

    hv = hash(ITEM_key(item), item->nkey);
    item_lock(hv);
    ret = do_store_item(item, comm, c, hv);
    item_unlock(hv);
    return ret;
}
/*
 * Stores an item in the cache (high level, obeys set/add/replace semantics)
 */
enum store_item_type store_item(item *item, int comm, conn* c) { //注意该函数外层在该函数执行完后一般会调用一次item_remove
    enum store_item_type ret;
    uint32_t hv;

    hv = hash(ITEM_key(item), item->nkey);
    item_lock(hv);
    ret = do_store_item(item, comm, c, hv);
    item_unlock(hv);
    return ret;
}
Beispiel #4
0
/*
 * Stores an item in the cache (high level, obeys set/add/replace semantics)
 */
ENGINE_ERROR_CODE store_item(struct default_engine *engine,
                             hash_item *item, uint64_t *cas,
                             ENGINE_STORE_OPERATION operation,
                             const void *cookie) {
    ENGINE_ERROR_CODE ret;

    pthread_mutex_lock(&engine->cache_lock);
    ret = do_store_item(engine, item, cas, operation, cookie);
    pthread_mutex_unlock(&engine->cache_lock);
    return ret;
}
Beispiel #5
0
int LRU_list::store_item(base_item* item, Conn* c) {
    int ret;
    uint32_t hv;

    hv = hashtable.hash(item->data, item->nkey);
    //区域锁
    hashtable.hash_lock(hv);
    ret = do_store_item(item, c, hv);
    hashtable.hash_unlock(hv); 
    
    return ret;
}
Beispiel #6
0
/*
 * Stores an item in the cache (high level, obeys set/add/replace semantics)
 * 在缓存中存储一个数据项
 */
enum store_item_type store_item(item *item, int comm, conn* c) {
    enum store_item_type ret;
    uint32_t hv;

    // 先做一次哈希计算
    hv = hash(ITEM_key(item), item->nkey, 0);

    item_lock(hv);
    // 正真存储数据的方法 do_store_item()
    ret = do_store_item(item, comm, c, hv);
    item_unlock(hv);
    return ret;
}
Beispiel #7
0
/*
 * Stores an item in the cache (high level, obeys set/add/replace semantics)
 */
ENGINE_ERROR_CODE store_item(struct default_engine *engine,
                             hash_item *item, uint64_t *cas,
                             ENGINE_STORE_OPERATION operation,
                             const void *cookie) {
    ENGINE_ERROR_CODE ret;
    hash_item* stored_item = NULL;

    cb_mutex_enter(&engine->items.lock);
    ret = do_store_item(engine, item, operation, cookie, &stored_item);
    if (ret == ENGINE_SUCCESS) {
        *cas = item_get_cas(stored_item);
    }
    cb_mutex_exit(&engine->items.lock);
    return ret;
}
Beispiel #8
0
static ENGINE_ERROR_CODE do_arithmetic(struct default_engine *engine,
                                       const void* cookie,
                                       const hash_key* key,
                                       const bool increment,
                                       const bool create,
                                       const uint64_t delta,
                                       const uint64_t initial,
                                       const rel_time_t exptime,
                                       item **result_item,
                                       uint8_t datatype,
                                       uint64_t *result)
{
   hash_item *item = do_item_get(engine, key);
   ENGINE_ERROR_CODE ret;

   if (item == NULL) {
      if (!create) {
         return ENGINE_KEY_ENOENT;
      } else {
         char buffer[128];
         int len = snprintf(buffer, sizeof(buffer), "%"PRIu64,
                            (uint64_t)initial);
         if (len < 0 || len >= sizeof(buffer)) {
             return ENGINE_ENOMEM;
         }

         item = do_item_alloc(engine, key, 0, exptime, len, cookie,
                              datatype);
         if (item == NULL) {
            return ENGINE_ENOMEM;
         }
         memcpy((void*)item_get_data(item), buffer, len);
         if ((ret = do_store_item(engine, item, OPERATION_ADD, cookie,
                                  (hash_item**)result_item)) == ENGINE_SUCCESS) {
             *result = initial;
         } else {
             do_item_release(engine, item);
         }
      }
   } else {
      ret = do_add_delta(engine, item, increment, delta, result_item, result,
                         cookie);
   }

   return ret;
}