예제 #1
0
 int ObStatManager::inc(const uint64_t mod_id, const uint64_t table_id, const int32_t index, const int64_t inc_value)
 {
   int ret = OB_ERROR;
   bool need_add_new = true;
   assert(mod_id < OB_MAX_MOD_NUMBER);
   for (int32_t i = 0; table_id != OB_INVALID_ID && mod_id != OB_INVALID_ID && i < table_stats_[mod_id].get_array_index(); i++)
   {
     if (data_holder_[mod_id][i].get_table_id() == table_id)
     {
       need_add_new = false;
       ret = data_holder_[mod_id][i].inc(index, inc_value);
     }
   }
   if (need_add_new && table_id != OB_INVALID_ID && mod_id != OB_INVALID_ID)
   {
     ObStat stat;
     stat.set_mod_id(mod_id);
     stat.set_table_id(table_id);
     ret = stat.set_value(index, inc_value);
     if (OB_SUCCESS == ret)
     {
       if ((ret = add_new_stat(stat)) == OB_ENTRY_EXIST)
       {
         ret = inc(mod_id, table_id, index, inc_value);
       }
     }
   }
   return ret;
 }
예제 #2
0
 int ObStatManager::inc(const uint64_t table_id, const int32_t index, const int64_t inc_value)
 {
   int ret = OB_ERROR;
   bool need_add_new = true;
   for (int32_t i = 0; table_id != OB_INVALID_ID && i < table_stats_.get_array_index(); i++)
   {
     if (data_holder_[i].get_table_id() == table_id)
     {
       need_add_new = false;
       ret = data_holder_[i].inc(index, inc_value);
     }
   }
   if (need_add_new && table_id != OB_INVALID_ID) 
   {
     ObStat stat;
     stat.set_table_id(table_id);
     ret = stat.set_value(index, inc_value);
     if (OB_SUCCESS == ret)
     {
       if (!table_stats_.push_back(stat))
       {
         TBSYS_LOG(WARN, "too much tables");
         ret = OB_ERROR;
       }
     }
   }
   return ret;
 }
예제 #3
0
TEST(ObStat,Serialize)
{
  ObStat stat;
  stat.set_table_id(1111);
  stat.set_value(3, 20);
  stat.inc(3);
  char buff[1024];
  int64_t pos = 0;
  EXPECT_EQ(1111, stat.get_table_id());
  EXPECT_EQ(21, stat.get_value(3));
  EXPECT_TRUE(OB_SUCCESS == stat.serialize(buff, 1024, pos));
  pos = 0;
  ObStat stat2;
  EXPECT_TRUE(OB_SUCCESS == stat2.deserialize(buff, 1024, pos));
  EXPECT_EQ(1111, stat2.get_table_id());
  EXPECT_EQ(21, stat2.get_value(3));

}