Пример #1
0
int fill_sstable_schema(ObSchemaManagerV2 &mgr, const uint64_t table_id, ObSSTableSchema& sstable_schema)
{
  int ret = OB_SUCCESS;
  int32_t cols = 0;
  int32_t size = 0;
  ObSSTableSchemaColumnDef column_def;

  sstable_schema.reset();

  const ObColumnSchemaV2 *col = mgr.get_table_schema( table_id,size);

  if (NULL == col || size <= 0)
  {
    TBSYS_LOG(ERROR,"cann't find this table:%lu",table_id);
    ret = OB_ERROR;
  }
  else
  {
    for (int col_index = 0; col_index < size && OB_SUCCESS == ret; ++col_index)
    {
      memset(&column_def,0,sizeof(column_def));
      column_def.table_id_ = static_cast<uint32_t>(table_id);
      column_def.column_group_id_ = static_cast<uint16_t>((col + col_index)->get_column_group_id());
      column_def.column_name_id_ = static_cast<uint16_t>((col + col_index)->get_id());
      column_def.column_value_type_ = (col + col_index)->get_type();
      if ( (ret = sstable_schema.add_column_def(column_def)) != OB_SUCCESS )
      {
        TBSYS_LOG(ERROR,"add column_def(%u,%u,%u) failed col_index : %d",column_def.table_id_,
          column_def.column_group_id_,column_def.column_name_id_,col_index);
      }
      ++cols;
    }
  }

  if ( 0 == cols && OB_SUCCESS == ret ) //this table has moved to updateserver
  {
    ret = OB_CS_TABLE_HAS_DELETED;
  }
  return ret;
}
Пример #2
0
      TEST_F(TestObSSTableSchema, test_reset_scheam)
      {
        ObSSTableSchema schema;
        ObSSTableSchemaColumnDef column_def;
        const ObSSTableSchemaColumnDef *column = NULL;
        int ret = OB_SUCCESS;
        for (int i = 0; i < DEFAULT_COLUMN_DEF_SIZE; ++i)
        {
          column_def.column_group_id_ = 2;
          column_def.column_name_id_ = i + 2;
          if (OB_MAX_COLUMN_NUMBER > i)
          {
            column_def.table_id_ = 1000;
          }
          else
          {
            column_def.table_id_ = 1001;
          }
          column_def.column_value_type_ = ObNullType;
          ret = schema.add_column_def(column_def);
          EXPECT_EQ(OB_SUCCESS, ret);
        }

        EXPECT_EQ(DEFAULT_COLUMN_DEF_SIZE, schema.get_column_count());

        for (int i = 0; i < DEFAULT_COLUMN_DEF_SIZE; ++i)
        {
          column = schema.get_column_def(i);
          EXPECT_EQ(i + 2, (int32_t)column->column_name_id_);
          EXPECT_EQ(2, (int32_t)column->column_group_id_);
          if (OB_MAX_COLUMN_NUMBER > i)
          {
            EXPECT_EQ(1000, (int32_t)column->table_id_);
          }
          else
          {
            EXPECT_EQ(1001, (int32_t)column->table_id_);
          }
          EXPECT_EQ(ObNullType, column->column_value_type_);
        }

        schema.reset();

        for (int i = 0; i < DEFAULT_COLUMN_DEF_SIZE; ++i)
        {
          column_def.column_group_id_ = 2;
          column_def.column_name_id_ = i + 2;
          if (OB_MAX_COLUMN_NUMBER > i)
          {
            column_def.table_id_ = 1000;
          }
          else
          {
            column_def.table_id_ = 1001;
          }
          column_def.column_value_type_ = ObNullType;
          ret = schema.add_column_def(column_def);
          EXPECT_EQ(OB_SUCCESS, ret);
        }

        EXPECT_EQ(DEFAULT_COLUMN_DEF_SIZE, schema.get_column_count());

        for (int i = 0; i < DEFAULT_COLUMN_DEF_SIZE; ++i)
        {
          column = schema.get_column_def(i);
          EXPECT_EQ(i + 2, (int32_t)column->column_name_id_);
          EXPECT_EQ(2, (int32_t)column->column_group_id_);
          if (OB_MAX_COLUMN_NUMBER > i)
          {
            EXPECT_EQ(1000, (int32_t)column->table_id_);
          }
          else
          {
            EXPECT_EQ(1001, (int32_t)column->table_id_);
          }
          EXPECT_EQ(ObNullType, column->column_value_type_);
        }
      }