예제 #1
0
void LRURowStorage<ROW, V>::insert_inactive(int32_t row_id,
    const ROW<V>& new_row) {
  // Sanity check.
  int num_rows = inactive_list_.size() + active_list_.size();
  CHECK_LE(num_rows, this->capacity_)
    << "Number of rows exceed storage size.";

  // If necessary, make space...
  if (num_rows == this->capacity_) {
    // ...by purging the least-recently-used element (head of list).
    VLOG(1) << "Evicting row " << inactive_list_.right.begin()->second
      << " to insert row " << row_id;
    inactive_list_.right.erase(inactive_list_.right.begin());
  }

  // Create a new record from the key and the value
  // bimap's list_view defaults to inserting this at
  // the list tail (considered most-recently-used).
  int threshold_count = static_cast<int>(num_row_access_to_active_ *
    new_row.get_num_columns());  // Compute the threshold count.
  AccessStatsRow new_inactive_row = boost::tuples::make_tuple(new_row, 0,
      threshold_count);
  inactive_list_.insert(
    typename AccessCountMapList::value_type(row_id, new_inactive_row));
  VLOG(1) << "Inserted new row (row id = " << row_id << ") of size "
    << new_row.get_num_columns() << " with threshold count = "
    << threshold_count;
}
예제 #2
0
int LRURowStorage<ROW, V>::PutRow(int32_t row_id,
    const ROW<V>& new_row) {
  // Look for row_id in active_list_.
  const typename MapList::left_iterator ait = active_list_.left.find(row_id);
  if (ait != active_list_.left.end()) {
    // We found row_id in active_list_. Update it.
    ait->second = new_row;

    // Now move it to the end of the list (most recent)
    active_list_.right.relocate(
      active_list_.right.end(),
      active_list_.project_right(ait));
    return 0;   // replace existing row.
  }

  // Look for row_id in inactive_list_.
  const inactive_list_left_iter_t iit = inactive_list_.left.find(row_id);
  if (iit != inactive_list_.left.end()) {
    // We found row_id in inactive_list_.
    AccessStatsRow& row_tuple = iit->second;

    // Update it.
    row_tuple.template get<AccessStatsRowTuple::DATA>() = new_row;
    row_tuple.template get<AccessStatsRowTuple::CURR_COUNT>() +=
      new_row.get_num_columns();
    // Recompute the threshold count.
    row_tuple.template get<AccessStatsRowTuple::THRESHOLD>() =
      static_cast<int>(num_row_access_to_active_ * new_row.get_num_columns());

    PromoteInactiveRowOrRelocate(iit);
    return 0;   // replace existing row.
  }

  // Not found in either list, put it in inactive_list_.
  insert_inactive(row_id, new_row);
  return 1;   // inserting new row.
}