Ejemplo n.º 1
0
int TabletManagerIniter::create_tablet(const ObRange& range,
                                       const ObSSTableId& sst_id, bool serving,
                                       const int64_t version)
{
    int ret = OB_SUCCESS;

    if (range.empty())
    {
        TBSYS_LOG(ERROR, "create_tablet error, input range is empty.");
        ret = OB_INVALID_ARGUMENT;
    }

    if (OB_SUCCESS == ret)
    {
        ObTablet* tablet = NULL;
        // find tablet if exist?
        ObMultiVersionTabletImage &image =  tablet_mgr_.get_serving_tablet_image() ;
        ret = image.acquire_tablet(range, ObMultiVersionTabletImage::SCAN_FORWARD, version, tablet);
        if (OB_SUCCESS == ret)
        {
            TBSYS_LOG(ERROR, "tablet already exists! dump input and exist:");
            range.hex_dump(TBSYS_LOG_LEVEL_ERROR);
            tablet->get_range().hex_dump(TBSYS_LOG_LEVEL_ERROR);
            ret = OB_ERROR;
            tablet = NULL;
            image.release_tablet(tablet);
        }
        else
        {
            ret = image.alloc_tablet_object(range, version, tablet);
            if (OB_SUCCESS == ret)
            {
                ret = tablet->add_sstable_by_id(sst_id);
            }
            if (OB_SUCCESS == ret)
            {
                tablet->set_disk_no(sst_id.sstable_file_id_ & DISK_NO_MASK);
                ret = image.add_tablet(tablet, true, true);
            }
        }
    }

    return ret;
}
Ejemplo n.º 2
0
int scan_test_case_common(
  BaseClient& client,
  const ObServer& server,
  const int64_t  table_id,
  const char* start_key_ptr,
  const char* end_key_ptr,
  const int64_t input_key_size,
  const bool is_hex
  )
{
  ObScanParam input;


  int64_t key_size = input_key_size;
  if (is_hex)
  {
    key_size = input_key_size / 2;
  }

  char start_key[input_key_size];
  char end_key[input_key_size];
  char range_str[OB_RANGE_STR_BUFSIZ];


  memset(start_key, 0, input_key_size);
  memset(end_key, 0, input_key_size);
  if (is_hex)
  {
    str_to_hex(start_key_ptr, static_cast<int32_t>(input_key_size), start_key, static_cast<int32_t>(key_size));
    str_to_hex(end_key_ptr, static_cast<int32_t>(input_key_size), end_key, static_cast<int32_t>(key_size));
  }
  else
  {
    memcpy(start_key, start_key_ptr, key_size);
    memcpy(end_key, end_key_ptr, key_size);
  }


  ObString ob_table_name(0, 0, NULL);

  ObRange range;
  range.table_id_= 0;
  range.start_key_.assign_ptr(start_key, static_cast<int32_t>(key_size));
  range.end_key_.assign_ptr(end_key, static_cast<int32_t>(key_size));
  range.border_flag_.set_inclusive_start();
  range.border_flag_.set_inclusive_end();

  range.to_string(range_str, OB_RANGE_STR_BUFSIZ);
  range.hex_dump();
  fprintf(stderr, "input scan range = %s\n", range_str);


  input.set(table_id, ob_table_name, range);
  input.set_scan_size(100000);
  input.add_column((uint64_t)0ull);


  ObScanner scanner;
  int64_t start = tbsys::CTimeUtil::getTime();
  int ret = rpc_cs_scan(client.client_, server, input, scanner);
  int64_t end = tbsys::CTimeUtil::getTime();
  fprintf(stderr,"rpc_cs_scan time consume:%ld\n", end - start);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"ret:%d\n", ret);
  }
  else
  {
    dump_scanner(scanner);
  }
  
  return ret;
}
Ejemplo n.º 3
0
int scan_test_case(
    BaseClient& client,
    const ObServer& server,
    const uint64_t table_id,
    const int64_t user_id,
  const int8_t item_type,
  const int32_t column_size
  )
{
  ObScanParam input;


  const int32_t key_size = 17;
  char start_key[key_size] ;
  char end_key[key_size] ;

  int64_t pos = 0;
  
  encode_i64(start_key, key_size, pos, user_id);
  if (item_type <= 1)
    encode_i8(start_key, key_size, pos, item_type);
  else
    encode_i8(start_key, key_size, pos, 0x0);
  memset(start_key + pos, 0x0, key_size - pos);

  pos = 0;
  encode_i64(end_key, key_size, pos, user_id);
  if ( item_type <= 1)
    encode_i8(end_key, key_size, pos, item_type);
  else
    encode_i8(end_key, key_size, pos, static_cast<int8_t>(0xFF));

  memset(end_key + pos, 0xFF, key_size - pos);

  hex_dump(start_key, key_size);
  hex_dump(end_key, key_size);


  ObString ob_table_name;
  ObRange range;
  range.table_id_= table_id;
  range.start_key_.assign_ptr(start_key, key_size);
  range.end_key_.assign_ptr(end_key, key_size);
  range.border_flag_.set_inclusive_start();
  range.border_flag_.set_inclusive_end();

  range.hex_dump();

  input.set(table_id, ob_table_name, range);
  input.set_scan_size(100000);

  for (int i = 0; i < column_size; ++i)
  {
    input.add_column(i + 2);
  }

  ObScanner scanner;
  int64_t start = tbsys::CTimeUtil::getTime();
  int ret = rpc_cs_scan(client.client_, server, input, scanner);
  int64_t end = tbsys::CTimeUtil::getTime();
  fprintf(stderr,"rpc_cs_scan time consume:%ld\n", end - start);
  if (OB_SUCCESS != ret)
  {
    fprintf(stderr,"ret:%d\n", ret);
  }
  else
  {
    dump_scanner(scanner);
  }
  
  return ret;
}
Ejemplo n.º 4
0
// waring:all return cell in a row must be same as root table's columns,
//        and the second row is this row allocated chunkserver list
int ObMergerRootRpcProxy::scan_root_table(ObMergerTabletLocationCache * cache, 
    const uint64_t table_id, const ObString & row_key, const ObServer & addr,
    ObMergerTabletLocationList & location)
{
  assert(location.get_buffer() != NULL);
  int ret = OB_SUCCESS;
  bool find_right_tablet = false;
  ObScanner scanner;
  // root table id = 0
  ret = rpc_stub_->fetch_tablet_location(rpc_timeout_, root_server_, 0,
      table_id, row_key, scanner);
  if (ret != OB_SUCCESS)
  {
    TBSYS_LOG(WARN, "fetch tablet location failed:table_id[%lu], length[%d], ret[%d]",
        table_id, row_key.length(), ret);
    hex_dump(row_key.ptr(), row_key.length(), true);
  }
  else
  {
    ObRange range;
    range.border_flag_.unset_inclusive_start();
    range.border_flag_.set_inclusive_end();
    ObString start_key;
    ObString end_key; 
    ObServer server;
    ObCellInfo * cell = NULL;
    bool row_change = false;
    ObScannerIterator iter = scanner.begin();
    TBSYS_LOG(DEBUG, "%s", "parse scanner result for get some tablet locations");
    // all return cell in a row must be same as root table's columns
    ++iter;
    while ((iter != scanner.end()) 
        && (OB_SUCCESS == (ret = iter.get_cell(&cell, &row_change))) && !row_change)
    {
      if (NULL == cell)
      {
        ret = OB_INNER_STAT_ERROR;
        break;
      }
      start_key.assign(cell->row_key_.ptr(), cell->row_key_.length());
      ++iter;
    }

    if (ret == OB_SUCCESS)
    {
      int64_t ip = 0;
      int64_t port = 0;
      bool second_row = true;
      // next cell
      ObMergerTabletLocationList list;
      for (++iter; iter != scanner.end(); ++iter)
      {
        ret = iter.get_cell(&cell, &row_change);
        if (ret != OB_SUCCESS)
        {
          TBSYS_LOG(ERROR, "get cell from scanner iterator failed:ret[%d]", ret);
          break;
        }
        else if (row_change) // && (iter != last_iter))
        {
          range.table_id_ = table_id;
          if (NULL == start_key.ptr())
          {
            range.border_flag_.set_min_value();
          }
          else
          {
            range.border_flag_.unset_min_value();
            range.start_key_ = start_key;
          }
          range.border_flag_.unset_max_value();
          range.end_key_ = end_key;
          start_key = end_key;
          end_key.assign(cell->row_key_.ptr(), cell->row_key_.length());
          list.set_timestamp(tbsys::CTimeUtil::getTime()); 
          list.sort(addr);
          // not deep copy the range
          list.set_tablet_range(range);
          // the second row is this row allocated chunkserver list
          if (second_row)
          {
            second_row = false;
            if ((row_key <= range.end_key_) && (row_key > range.start_key_))
            {
              find_right_tablet = true;
              location = list;
              assert(location.get_buffer() != NULL);
              location.set_tablet_range(range);
            }
            else
            {
              ret = OB_DATA_NOT_SERVE;
              TBSYS_LOG(ERROR, "check range not include this key:ret[%d]", ret);
              hex_dump(row_key.ptr(), row_key.length());
              range.hex_dump();
              break;
            }
          }
          // add to cache
          if (OB_SUCCESS != cache->set(range, list))
          {
            TBSYS_LOG(WARN, "%s", "add the range to cache failed");
          }
          list.clear();
        }
        else
        {
          end_key.assign(cell->row_key_.ptr(), cell->row_key_.length());
          if ((cell->column_name_.compare("1_port") == 0) 
              || (cell->column_name_.compare("2_port") == 0) 
              || (cell->column_name_.compare("3_port") == 0))
          {
            ret = cell->value_.get_int(port);
          }
          else if ((cell->column_name_.compare("1_ipv4") == 0)
              || (cell->column_name_.compare("2_ipv4") == 0)
              || (cell->column_name_.compare("3_ipv4") == 0))
          {
            ret = cell->value_.get_int(ip);
            if (OB_SUCCESS == ret)
            {
              if (port == 0)
              {
                TBSYS_LOG(WARN, "check port failed:ip[%ld], port[%ld]", ip, port);
              }
              server.set_ipv4_addr(static_cast<int32_t>(ip), static_cast<int32_t>(port));
              ObTabletLocation addr(0, server);
              if (OB_SUCCESS != (ret = list.add(addr)))
              {
                TBSYS_LOG(ERROR, "add addr failed:ip[%ld], port[%ld], ret[%d]", 
                    ip, port, ret);
                break;
              }
              else
              {
                TBSYS_LOG(DEBUG, "add addr succ:ip[%ld], port[%ld]", ip, port);
              }
              ip = port = 0;
            }
          }

          if (ret != OB_SUCCESS)
          {
            TBSYS_LOG(ERROR, "check get value failed:ret[%d]", ret);
            break;
          }
        }
      }

      // for the last row 
      if ((OB_SUCCESS == ret) && (start_key != end_key))
      {
        range.table_id_ = table_id;
        if (NULL == start_key.ptr())
        {
          range.border_flag_.set_min_value();
        }
        else
        {
          range.border_flag_.unset_min_value();
          range.start_key_ = start_key;
        }
        range.border_flag_.unset_max_value();
        range.end_key_ = end_key;
        list.set_timestamp(tbsys::CTimeUtil::getTime());
        // not deep copy the range
        list.set_tablet_range(range);
        list.sort(addr);
        // double check add all range->locationlist to cache
        if ((row_key <= range.end_key_) && (row_key > range.start_key_))
        {
          find_right_tablet = true;
          location = list;
          // deep copy range
          assert(location.get_buffer() != NULL);
          location.set_tablet_range(range);
        }
        else if (second_row)
        {
          range.hex_dump();
          ret = OB_DATA_NOT_SERVE;
          TBSYS_LOG(ERROR, "check range not include this key:ret[%d]", ret);
        }
        // add to list to cache
        if (OB_SUCCESS != cache->set(range, list))
        {
          range.hex_dump();
          TBSYS_LOG(WARN, "%s", "add the range to cache failed");
        }
      }
    }
    else
    {
      TBSYS_LOG(ERROR, "check get first row cell failed:ret[%d]", ret);
    }
  }

  if ((OB_SUCCESS == ret) && (0 == location.size()))
  {
    TBSYS_LOG(ERROR, "check get location size failed:table_id[%ld], find[%d], count[%ld]",
        table_id, find_right_tablet, location.size());
    hex_dump(row_key.ptr(), row_key.length());
    ret = OB_INNER_STAT_ERROR;
  }
  ms_get_counter_set().inc(ObMergerCounterIds::C_SCAN_ROOT_TABLE);
  return ret;
}