LOCAL_CACHE_TEMPLATE typename LOCAL_CACHE_CLASS::result LOCAL_CACHE_CLASS::get(const KeyT& key, ValueT& value) { // lock if (capacity < 1) { return MISS; } tbsys::CThreadGuard guard(&mutex); entry_cache_iterator iter = cache.find(&key); if (iter == cache.end()) { return MISS; } // adjust lru list lru.splice(lru.begin(), lru, iter->second); // whatever, find entry, fill value fill_value(iter, value); // check whether entry was expired uint64_t now = tbutil::Time::now().toMilliSeconds(); assert(expire != 0); if (now - entry_utime(iter) > expire) { // expired set_entry_utime(iter->second, now); return EXPIRED; } else { // fresh entry return HIT; } }
rc_t ShoreYCSBEnv::xct_populate_db(const int /* xct_id */, populate_db_input_t& pin) { assert (_pssm); assert (_initialized); tuple_guard<ycsbtable_man_impl> tuple(ycsbtable_man); rep_row_t areprow(ycsbtable_man->ts()); rep_row_t areprowkey(ycsbtable_man->ts()); areprow.set(ycsbtable_man->table()->maxsize()); areprowkey.set(ycsbtable_man->table()->maxsize()); tuple->_rep = &areprow; tuple->_rep_key = &areprowkey; W_DO(db()->begin_xct()); uint64_t key = pin.firstKey; char field[FieldSize]; for (unsigned i = 0; i < pin.count; i++) { tuple->set_value(0, key); for (int j = 1; j <= FieldCount; j++) { fill_value(field); tuple->set_value(j, field); } W_DO(ycsbtable_man->add_tuple(_pssm, tuple)); key++; } W_DO(db()->commit_xct()); return RCOK; }
update_input_t create_update_input(int sf, int specificPrefix, int tspread) { update_input_t input; input.key = get_key(sf, specificPrefix, tspread); input.field_number = URand(1, 10); fill_value(input.value); return input; }
LOCAL_CACHE_TEMPLATE typename LOCAL_CACHE_CLASS::result LOCAL_CACHE_CLASS::put_if_absent(const KeyT &key, const ValueT &val, ValueT &curtVal) { if (capacity < 1) { return MISS; } result res = MISS; // lock tbsys::CThreadGuard guard(&mutex); entry_cache_iterator iter = cache.find(&key); internal_entry *entry = NULL; if (iter == cache.end()) { res = MISS; // not found // evict entry while (cache.size() >= capacity) { assert(capacity >= 1); const internal_entry *evict = evict_one(); assert(evict != NULL); // free entry drop_entry(evict); } // insert new one // allocate internal_entry, relase after evict or in clear() entry = make_entry(key, val); if (entry == NULL) { return SETERROR; } lru.push_front(entry); cache[entry->get_key()] = lru.begin(); curtVal = val; } else { res = HIT; // found, already exists // adjust lru list lru.splice(lru.begin(), lru, iter->second); // update entry value and utime // update first, some meta info fill_value(iter, curtVal); uint64_t now = tbutil::Time::now().toMilliSeconds(); assert(expire != 0); if (now - entry_utime(iter) > expire) { // expired set_entry_utime(iter->second, now); res = EXPIRED; } } return res; }
void fill(const double x, const T weight = 1) { fill_value(x, weight); }
static void fill_c(struct cut_option *op, const char *d) { fill_value(&(op->c), d); }