ObStatManager & ObStatManager::operate(const ObStatManager &operand, OpFunc op) { if (server_type_ == operand.server_type_) { for (int32_t mod = 0; mod < OB_MAX_MOD_NUMBER; mod++) { for (int32_t i = 0; i < table_stats_[mod].get_array_index(); i++) { ObStat *stat = table_stats_[mod].at(i); ObStat *operand_stat = NULL; int has_table = operand.get_stat(stat->get_mod_id(), stat->get_table_id(), operand_stat); int64_t op_value = 0; // if operand has status value of same table, then apply op, otherwise keep old values. if (OB_SUCCESS == has_table && NULL != operand_stat) { for (int32_t index = 0; index < ObStat::MAX_STATICS_PER_TABLE; ++index) { op_value = op(stat->get_value(index) , operand_stat->get_value(index)); stat->set_value(index, op_value); } } } } } return *this; }
int ObStatManager::add_new_stat(const ObStat& stat) { int ret = OB_SUCCESS; uint64_t table_id = stat.get_table_id(); uint64_t mod_id = stat.get_mod_id(); if (table_id != OB_INVALID_ID && mod_id != OB_INVALID_ID) { tbsys::CThreadGuard guard(&lock_); for (int32_t i = 0; i < table_stats_[mod_id].get_array_index(); i++) { if (data_holder_[mod_id][i].get_table_id() == table_id) { ret = OB_ENTRY_EXIST; break; } } if (ret != OB_ENTRY_EXIST) { if (!table_stats_[mod_id].push_back(stat)) { TBSYS_LOG(WARN, "too much tables"); ret = OB_ERROR; } } } return ret; }