int ObScannerLoader::build_cell_info(int table_id, const ObRowkey& row_key, char *buf, ObScanner &param)
{
  ObCellInfo info;
  ObString tmpstr;
  uint64_t column_id = OB_INVALID_ID;
  char *p = NULL;

  info.reset();
  //info.table_name_ = table_name_;
  info.table_id_ = table_id;
  info.row_key_ = row_key;
  info.column_id_ = column_id;

  if(NULL == (p = strchr(buf, ':')))
  {
    p = buf;
    auto_set_val(info.value_, p);
  }
  else
  {
    *p = '\0';
    p++;
    info.column_id_ = atoi(buf);
    auto_set_val(info.value_, p);
  }
  TBSYS_LOG(DEBUG, "[%lu][%s] [%lu]:[%s]", info.table_id_,
      to_cstring(info.row_key_),  info.column_id_, p);

  actual_fullfilled_item_num_++;
  return param.add_cell(info);
}
int MockChunkServer::handle_get_table(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObGetParam param;
  if (OB_SUCCESS == ret)
  {
    ret = param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check param failed");
    }
  }

  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());

    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    // fake data cell
    ObCellInfo cell;
    ObScanner scanner;
    ObRowkey row_key;
    ObString column_name;
    char temp[256] = "";
    cell.table_id_ = 101; 
    for (uint64_t i = 0; i < 10; ++i)
    {
      snprintf(temp, 256, "chunk_%lu_get_row_key:%lu", i, i);
      row_key = make_rowkey(temp, &allocator_);
      cell.row_key_ = row_key;
      cell.column_id_ = i + 1;
      cell.value_.set_int(2234 + i);
      scanner.add_cell(cell);
    }
    scanner.set_is_req_fullfilled(true, 1);
    int32_t channel_id = ob_packet->getChannelId();
    ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    //
    ret = send_response(OB_GET_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  TBSYS_LOG(INFO, "handle get table result:ret[%d]", ret);
  return ret;
}
Пример #3
0
int ObFinalResult::get(const ObGetParam &get_param, ObScanner &scanner,bool ret_null)
{
  int err = OB_SUCCESS;
  ObRowInfo row_info;
  ObCellInfo cur_cell;
  map<ObRowInfo, vector<ObCellInfo> >::iterator target;
  bool prev_row_not_exist = false;
  for (int64_t get_idx = 0 ; OB_SUCCESS == err && get_idx < get_param.get_cell_size(); get_idx ++)
  {
    row_info.table_name_ = get_param[get_idx]->table_name_;
    row_info.row_key_ = get_param[get_idx]->row_key_;
    cur_cell = *(get_param[get_idx]);
    target = row_infos_->lower_bound(row_info);
    if (get_idx > 0 
        && prev_row_not_exist 
        && get_param[get_idx]->table_name_ == get_param[get_idx-1]->table_name_
        && get_param[get_idx]->row_key_ == get_param[get_idx-1]->row_key_
       )
    {
      continue;
    }
    if (row_infos_->end() ==  target 
        || row_info < target->first  
        || target->second.size() == 0)
    {
      prev_row_not_exist = true;
      cur_cell.value_.set_ext(ObActionFlag::OP_ROW_DOES_NOT_EXIST);
    }
    else
    {
      prev_row_not_exist = false;
      vector<ObCellInfo>::iterator beg = target->second.begin();
      for (;beg != target->second.end(); beg ++)
      {
        if (beg->column_name_ == cur_cell.column_name_)
        {
          cur_cell = *beg;
          break;
        }
      }
      if (target->second.end() == beg)
      {
        if (ret_null)
        {
          cur_cell.value_.set_null();
        }
        else
        {
          cur_cell.value_.set_ext(ObActionFlag::OP_NOP);
        }
      }
    }
    cur_cell.table_id_ = OB_INVALID_ID;
    cur_cell.column_id_ = OB_INVALID_ID;
    err = scanner.add_cell(cur_cell);
  }
  return err;
}
Пример #4
0
void gen_scanner(ObScanner& scanner)
{
  ObCellInfo cell_info;
  strcpy(t, "test_table");
  strcpy(c, "name");
  strcpy(rowkey, "10000");

  cell_info.table_name_.assign_ptr(t, static_cast<int32_t>(strlen(t)));
  //cell_info.table_id_ = 3;
  cell_info.column_name_.assign_ptr(c, static_cast<int32_t>(strlen(c)));
  //cell_info.column_id_ = 2;

  cell_info.row_key_.assign_ptr(rowkey, static_cast<int32_t>(strlen(rowkey)));

  cell_info.value_.set_int(3);

  ASSERT_EQ(OB_SUCCESS, scanner.add_cell(cell_info));

  strcpy(c, "value");
  cell_info.column_name_.assign_ptr(c, static_cast<int32_t>(strlen(c)));
  //cell_info.column_id_ = 3;

  cell_info.value_.set_varchar(ObString(0, static_cast<int32_t>(strlen(value_str)), (char*)value_str));

  ASSERT_EQ(OB_SUCCESS, scanner.add_cell(cell_info));

  cell_info.value_.set_int(3);
  strcpy(c, "name");
  cell_info.column_name_.assign_ptr(c, static_cast<int32_t>(strlen(c)));
  //cell_info.column_id_ = 2;

  strcpy(rowkey, "10001");
  cell_info.row_key_.assign_ptr(rowkey, static_cast<int32_t>(strlen(rowkey)));

  ASSERT_EQ(OB_SUCCESS, scanner.add_cell(cell_info));

  cell_info.value_.set_varchar(ObString(0, static_cast<int32_t>(strlen(value_str)), (char*)value_str));
  strcpy(c, "value");
  cell_info.column_name_.assign_ptr(c, static_cast<int32_t>(strlen(c)));
  //cell_info.column_id_ = 3;

  ASSERT_EQ(OB_SUCCESS, scanner.add_cell(cell_info));
}
Пример #5
0
void build_scanner(ObIterator &iter, ObScanner &scanner, char *buffer, const int64_t buf_len, int64_t &pos)
{
  ObCellInfo *ci = NULL;
  while(OB_SUCCESS == iter.next_cell())
  {
    if (OB_SUCCESS == iter.get_cell(&ci)
        && NULL != ci)
    {
      scanner.add_cell(*ci);
    }
  }
  scanner.serialize(buffer, buf_len, pos);
}
Пример #6
0
int ObMergerScannerEncoder::encode(const ObGetParam & get_param, const ObScanner & org_scanner,
    ObScanner & encoded_scanner)
{
  int ret = OB_SUCCESS;
  ObCellInfo * cur_cell = NULL;
  ObCellInfo * encode_cell = NULL;
  int64_t cell_index = 0;
  ObScanner & input = const_cast<ObScanner &> (org_scanner);
  while (OB_SUCCESS == (ret = input.next_cell()))
  {
    ret = input.get_cell(&cur_cell);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "get cell from org scanner failed:ret[%d]", ret);
      break;
    }
    // output(*cur_cell);
    encode_cell = get_param[cell_index];
    if (NULL == encode_cell)
    {
      ret = OB_ERROR;
      TBSYS_LOG(WARN, "check encode cell failed:index[%ld]", cell_index);
      break;
    }
    encode_cell->value_ = cur_cell->value_;
    ret = encoded_scanner.add_cell(*encode_cell);
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(WARN, "add cell to encoded scanner failed:ret[%d]", ret);
      break;
    }
    ++cell_index;
  }
  // double check size
  if (cell_index != get_param.get_cell_size())
  {
    ret = OB_ERROR;
    TBSYS_LOG(WARN, "check result scanner cell count not equal get param cell size:"
        "count[%ld], size[%ld]", cell_index, get_param.get_cell_size());
  }
  input.reset_iter();
  // fill all data succ
  if (OB_ITER_END == ret)
  {
    ret = OB_SUCCESS;
  }
  return ret;
}
    int ObGetScanProxy::fill_compact_data(ObIterator& iterator,ObScanner& scanner)
    {
      int ret = OB_SUCCESS;

      ObCellInfo* cell = NULL;
      bool is_row_changed = false;

      while (OB_SUCCESS == (ret = iterator.next_cell()))
      {
        ret = iterator.get_cell(&cell,&is_row_changed);
        if (OB_SUCCESS != ret || NULL == cell)
        {
          TBSYS_LOG(WARN, "failed to get cell, cell=%p, err=%d", cell, ret);
        }
        else
        {
          ret = scanner.add_cell(*cell, false, is_row_changed);
          if (OB_SIZE_OVERFLOW == ret)
          {
            //TODO
            TBSYS_LOG(INFO, "ObScanner size full, cannot add any cell.");
            scanner.rollback();
            ret = OB_SUCCESS;
            break;
          }
          else if (OB_SUCCESS != ret)
          {
            TBSYS_LOG(WARN, "failed to add cell to scanner, ret=%d", ret);
          }
        }

        if (OB_SUCCESS != ret)
        {
          break;
        }
      }

      if (OB_ITER_END == ret)
      {
        ret = OB_SUCCESS;
      }
      else if (OB_SUCCESS != ret)
      {
        TBSYS_LOG(WARN, "retor occurs while iterating, ret=%d", ret);
      }
      return ret;
    }
Пример #8
0
TEST(TestObScanner, add_cell)
{
  ObScanner fem;
  fem.set_is_req_fullfilled(true, 1011);
  fem.set_data_version(170);

  char buf[BUFSIZ];
  int64_t pospos = 0;
  fem.serialize(buf, BUFSIZ, pospos);

  FILE *fd;
  fd = fopen("tmptest", "w+");
  fwrite(buf, 1, pospos, fd);
  fclose(fd);

  ObScanner os;
  ObScanner ost;
  /*** added by wushi ***/
  int64_t fullfilled_item = 0;
  int64_t tmp = 0;
  bool is_fullfilled = true;
  bool tmp_bool = false;
  /// initialize
  ASSERT_EQ(os.get_is_req_fullfilled(tmp_bool, fullfilled_item),0);
  EXPECT_FALSE(tmp_bool);
  ASSERT_EQ(fullfilled_item,0);
  /// set fullfilled
  is_fullfilled = true;
  fullfilled_item = 1000;
  os.set_is_req_fullfilled(is_fullfilled,fullfilled_item);
  ASSERT_EQ(os.get_is_req_fullfilled(tmp_bool, tmp),0);
  ASSERT_EQ(tmp_bool,is_fullfilled);
  ASSERT_EQ(tmp,fullfilled_item);

  /*** added by wushi ***/

  ObCellInfo oci;

  oci.table_name_.assign((char*)"table1", 6);
  oci.row_key_.assign((char*)"row1", 4);
  oci.column_name_.assign((char*)"column1", 7);
  oci.value_.set_int(0xff);

  ost.set_mem_size_limit(20);
  ASSERT_EQ(OB_SIZE_OVERFLOW, ost.add_cell(oci));
  os.set_mem_size_limit(1024 * 1024 * 2);
  ASSERT_EQ(OB_SUCCESS, os.add_cell(oci));

  oci.column_name_.assign((char*)"column2", 7);
  oci.value_.set_int(0xfe);
  ASSERT_EQ(OB_SUCCESS, os.add_cell(oci));

  ObScannerIterator iter = os.begin();
  ObCellInfo tci;
  ASSERT_EQ(OB_SUCCESS, iter.get_cell(tci));

  ASSERT_EQ(string("table1"), string(tci.table_name_.ptr(), tci.table_name_.length()));
  ASSERT_EQ(string("row1"), string(tci.row_key_.ptr(), tci.row_key_.length()));
  ASSERT_EQ(string("column1"), string(tci.column_name_.ptr(), tci.column_name_.length()));
  ASSERT_EQ(OB_SUCCESS, tci.value_.get_int(tmp));
  ASSERT_EQ(0xff, tmp);

  iter++;
  ASSERT_EQ(OB_SUCCESS, iter.get_cell(tci));

  ASSERT_EQ(string("table1"), string(tci.table_name_.ptr(), tci.table_name_.length()));
  ASSERT_EQ(string("row1"), string(tci.row_key_.ptr(), tci.row_key_.length()));
  ASSERT_EQ(string("column2"), string(tci.column_name_.ptr(), tci.column_name_.length()));
  ASSERT_EQ(OB_SUCCESS, tci.value_.get_int(tmp));
  ASSERT_EQ(0xfe, tmp);

  iter++;

  ASSERT_EQ(true, os.end() == iter);

  //ObCellInfo oci;
  char row_key_buffer[1024];

  oci.table_name_.assign((char*)"table1", 6);
  sprintf(row_key_buffer, "row1");
  oci.row_key_.assign(row_key_buffer, 4);
  oci.column_name_.assign((char*)"column1", 7);
  oci.value_.set_int(0xff);

  ASSERT_EQ(OB_SUCCESS, os.add_cell(oci));

  oci.table_name_.assign((char*)"table1", 6);
  sprintf(row_key_buffer, "row1");
  oci.row_key_.assign(row_key_buffer, 4);
  oci.column_name_.assign((char*)"column2", 7);
  oci.value_.set_int(0xee);

  os.set_mem_size_limit(20);
  ASSERT_EQ(OB_SIZE_OVERFLOW, os.add_cell(oci));
  os.set_mem_size_limit(1024 * 1024 * 2);
  ASSERT_EQ(OB_SUCCESS, os.add_cell(oci));

  oci.table_name_.assign((char*)"table1", 6);
  sprintf(row_key_buffer, "row2");
  oci.row_key_.assign(row_key_buffer, 4);
  oci.column_name_.assign((char*)"column1", 7);
  oci.value_.set_int(0xdd);

  ASSERT_EQ(OB_SUCCESS, os.add_cell(oci));

  oci.table_name_.assign((char*)"table2", 6);
  sprintf(row_key_buffer, "row2");
  oci.row_key_.assign(row_key_buffer, 4);
  oci.column_name_.assign((char*)"column1", 7);
  oci.value_.set_int(0xcc);

  ASSERT_EQ(OB_SUCCESS, os.add_cell(oci));

  oci.table_name_.assign((char*)"table3", 6);
  sprintf(row_key_buffer, "row2");
  oci.row_key_.assign(row_key_buffer, 4);
  oci.column_name_.assign((char*)"column1", 7);
  oci.value_.set_int(0xbb);

  ASSERT_EQ(OB_SUCCESS, os.add_cell(oci));

  fprintf(stdout, "size=%ld\n", os.get_serialize_size());
  char buffer[2048];
  int64_t pos = 0;
  ASSERT_EQ(OB_SUCCESS, os.serialize(buffer, 1024, pos));
  ASSERT_EQ(pos, os.get_serialize_size());
  fd = fopen("./test.data.before_rollback", "w+");
  fwrite(buffer, 1, 1024, fd);
  fclose(fd);

  for (iter = os.begin(); iter != os.end(); iter++)
  {
    ObCellInfo ci;
    ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n",
        ci.table_name_.length(), ci.table_name_.ptr(),
        ci.row_key_.length(), ci.row_key_.ptr(),
        ci.column_name_.length(), ci.column_name_.ptr());
  }
  fprintf(stdout, "==============================\n");
  while (OB_SUCCESS == os.next_cell())
  {
    ObCellInfo *ci = NULL;
    bool is_row_changed;
    ASSERT_EQ(OB_SUCCESS, os.get_cell(&ci, &is_row_changed));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s] "
            "table_id=[%lu] column_id=[%lu] row_changed=[%d]\n",
            ci->table_name_.length(), ci->table_name_.ptr(),
            ci->row_key_.length(), ci->row_key_.ptr(),
            ci->column_name_.length(),ci->column_name_.ptr(),
            ci->table_id_, ci->column_id_, is_row_changed);
  }
  os.reset_iter();
  fprintf(stdout, "==============================\n");

  ASSERT_EQ(OB_SUCCESS, os.rollback());

  fprintf(stdout, "size=%ld\n", os.get_serialize_size());
  pos = 0;
  ASSERT_EQ(OB_SUCCESS, os.serialize(buffer, 1024, pos));
  ASSERT_EQ(pos, os.get_serialize_size());
  fd = fopen("./test.data.after_rollback", "w+");
  fwrite(buffer, 1, 1024, fd);
  fclose(fd);

  for (iter = os.begin(); iter != os.end(); iter++)
  {
    ObCellInfo ci;
    ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n",
        ci.table_name_.length(), ci.table_name_.ptr(),
        ci.row_key_.length(), ci.row_key_.ptr(),
        ci.column_name_.length(), ci.column_name_.ptr());
    ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n",
        ci.table_name_.length(), ci.table_name_.ptr(),
        ci.row_key_.length(), ci.row_key_.ptr(),
        ci.column_name_.length(), ci.column_name_.ptr());
  }
  fprintf(stdout, "==============================\n");
  while (OB_SUCCESS == os.next_cell())
  {
    ObCellInfo *ci = NULL;
    bool is_row_changed;
    ASSERT_EQ(OB_SUCCESS, os.get_cell(&ci, &is_row_changed));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s] "
            "table_id=[%lu] column_id=[%lu] row_changed=[%d]\n",
            ci->table_name_.length(), ci->table_name_.ptr(),
            ci->row_key_.length(), ci->row_key_.ptr(),
            ci->column_name_.length(),ci->column_name_.ptr(),
            ci->table_id_, ci->column_id_, is_row_changed);
    ASSERT_EQ(OB_SUCCESS, os.get_cell(&ci, &is_row_changed));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s] "
            "table_id=[%lu] column_id=[%lu] row_changed=[%d]\n",
            ci->table_name_.length(), ci->table_name_.ptr(),
            ci->row_key_.length(), ci->row_key_.ptr(),
            ci->column_name_.length(),ci->column_name_.ptr(),
            ci->table_id_, ci->column_id_, is_row_changed);
  }
  os.reset_iter();
  fprintf(stdout, "==============================\n");

  pos = 0;
  ASSERT_EQ(OB_SUCCESS, os.deserialize(buffer, os.get_serialize_size(), pos));
  ASSERT_EQ(pos, os.get_serialize_size());

  for (iter = os.begin(); iter != os.end(); iter++)
  {
    ObCellInfo ci;
    ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n",
        ci.table_name_.length(), ci.table_name_.ptr(),
        ci.row_key_.length(), ci.row_key_.ptr(),
        ci.column_name_.length(), ci.column_name_.ptr());
    ASSERT_EQ(OB_SUCCESS, iter.get_cell(ci));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s]\n",
        ci.table_name_.length(), ci.table_name_.ptr(),
        ci.row_key_.length(), ci.row_key_.ptr(),
        ci.column_name_.length(), ci.column_name_.ptr());
  }
  fprintf(stdout, "==============================\n");
  while (OB_SUCCESS == os.next_cell())
  {
    ObCellInfo *ci = NULL;
    bool is_row_changed;
    ASSERT_EQ(OB_SUCCESS, os.get_cell(&ci, &is_row_changed));
    fprintf(stdout, "table_name=[%.*s] row_key=[%.*s] column_name=[%.*s] "
            "table_id=[%lu] column_id=[%lu] row_changed=[%d]\n",
            ci->table_name_.length(), ci->table_name_.ptr(),
            ci->row_key_.length(), ci->row_key_.ptr(),
            ci->column_name_.length(),ci->column_name_.ptr(),
            ci->table_id_, ci->column_id_, is_row_changed);
  }
  os.reset_iter();

  /// set fullfilled
//  ASSERT_EQ(os.get_is_req_fullfilled(tmp_bool, tmp),0);
//  ASSERT_EQ(tmp_bool,is_fullfilled);
//  ASSERT_EQ(tmp,fullfilled_item);
  {
    ObRange range;
    range.border_flag_.set_inclusive_start();
    range.start_key_.assign((char*)"11111", 5);
    range.end_key_.assign((char*)"22222", 5);
    ObRange range2;
    range2.border_flag_.set_inclusive_start();
    range2.start_key_.assign((char*)"11111", 5);
    range2.end_key_.assign((char*)"22222", 5);

    int64_t pos = 0;
    int64_t data_len = 0;
    is_fullfilled = true;
    fullfilled_item = 1212;
    ObScanner os1;
    ObScanner os2;
    ASSERT_EQ(os1.set_is_req_fullfilled(is_fullfilled, fullfilled_item),0);
    os1.set_data_version(100);
    ASSERT_EQ(os1.set_range(range),0);
    range.border_flag_.set_inclusive_end();
    char buf[1024];
    ASSERT_EQ(os1.serialize(buf,sizeof(buf),pos),0);
    data_len = pos;
    pos = 0;
    ASSERT_EQ(os2.deserialize(buf, data_len, pos),0);
    memset(buf, 0x00, 1024);

    ASSERT_EQ(os2.get_is_req_fullfilled(tmp_bool, tmp),0);
    EXPECT_EQ(is_fullfilled, tmp_bool);
    ASSERT_EQ(fullfilled_item, tmp);
    ASSERT_EQ(os1.get_data_version(),100);

    ObRange range3;
    ASSERT_EQ(OB_SUCCESS, os2.get_range(range3));
    ASSERT_EQ(range2.border_flag_.get_data(), range3.border_flag_.get_data());
    ASSERT_EQ(string(range3.start_key_.ptr(), range3.start_key_.length()),
              string(range2.start_key_.ptr(), range2.start_key_.length()));
    ASSERT_EQ(string(range3.end_key_.ptr(), range3.end_key_.length()),
              string(range2.end_key_.ptr(), range2.end_key_.length()));

    const int times = 1000000;
    ObScanner os3;
    ObCellInfo cinull;
    cinull.table_name_.assign((char*)"hello", 5);
    cinull.value_.set_ext(ObActionFlag::OP_INSERT);
    ASSERT_EQ(OB_ERROR, os3.add_cell(cinull));
    cinull.value_.set_ext(ObActionFlag::OP_DEL_ROW);
    ASSERT_EQ(OB_SUCCESS, os3.add_cell(cinull));
    cinull.value_.set_ext(ObActionFlag::OP_ROW_DOES_NOT_EXIST);
    ASSERT_EQ(OB_SUCCESS, os3.add_cell(cinull));
    int i = 0;
    for (; i < times; i++)
    {
      if (OB_SUCCESS != os3.add_cell(oci))
      {
        break;
      }
    }
    const int64_t buf_len = 1 << 22;
    char* buff = (char*)ob_malloc(buf_len);
    int64_t ppos = 0;
    int64_t len = os3.get_serialize_size();
    ASSERT_EQ(OB_BUF_NOT_ENOUGH, os3.serialize(buff, len - 4, ppos));
    ASSERT_EQ(OB_SUCCESS, os3.serialize(buff, buf_len, ppos));

    int64_t npos = 0;
    ObScanner os4;
    ASSERT_EQ(OB_ERROR, os4.deserialize(buff, 10, npos));
    ASSERT_EQ(OB_SUCCESS, os4.deserialize(buff, ppos, npos));
    ASSERT_EQ(npos, ppos);
    int64_t otmp;
    oci.value_.get_int(otmp);
    ObCellInfo *oo;
    int t = 0;
    ASSERT_EQ(OB_SUCCESS, os4.next_cell());
    ASSERT_EQ(OB_SUCCESS, os4.get_cell(&oo));
    ASSERT_EQ(0, oo->row_key_.length());
    ASSERT_EQ(string(cinull.table_name_.ptr(), cinull.table_name_.length()), string(oo->table_name_.ptr(), oo->table_name_.length()));
    ASSERT_EQ(OB_SUCCESS, oo->value_.get_ext(tmp));
    ASSERT_EQ(+ObActionFlag::OP_DEL_ROW, tmp);

    ASSERT_EQ(OB_SUCCESS, os4.next_cell());
    ASSERT_EQ(OB_SUCCESS, os4.get_cell(&oo));
    ASSERT_EQ(string(cinull.table_name_.ptr(), cinull.table_name_.length()), string(oo->table_name_.ptr(), oo->table_name_.length()));
    ASSERT_EQ(OB_SUCCESS, oo->value_.get_ext(tmp));
    ASSERT_EQ(+ObActionFlag::OP_ROW_DOES_NOT_EXIST, tmp);

    while (OB_SUCCESS == os4.next_cell())
    {
      ASSERT_EQ(OB_SUCCESS, os4.get_cell(&oo));

      t++;

      ASSERT_EQ(string(oci.table_name_.ptr(), oci.table_name_.length()), string(oo->table_name_.ptr(), oo->table_name_.length()));
      ASSERT_EQ(string(oci.row_key_.ptr(), oci.row_key_.length()), string(oo->row_key_.ptr(), oo->row_key_.length()));
      ASSERT_EQ(string(oci.column_name_.ptr(), oci.column_name_.length()), string(oo->column_name_.ptr(), oo->column_name_.length()));
      ASSERT_EQ(OB_SUCCESS, oo->value_.get_int(tmp));
      ASSERT_EQ(otmp, tmp);
    }

    ASSERT_EQ(t, i);

    ob_free(buff);
  }

  ObCellInfo st;

  st.table_name_.assign((char*)"table1", 6);
  st.row_key_.assign((char*)"row1", 4);
  st.column_name_.assign((char*)"column1", 7);
  st.value_.set_int(0xff);

  ObScanner ss;
  ss.add_cell(st);

  st.table_name_.assign((char*)"table2", 6);
  st.row_key_.assign((char*)"row1", 4);
  st.column_name_.assign((char*)"column1", 7);
  st.value_.set_int(0xff);

  ss.add_cell(st);

  ObCellInfo *sto;
  bool is_row_changed;

  ASSERT_EQ(OB_SUCCESS, ss.next_cell());
  ASSERT_EQ(OB_SUCCESS, ss.get_cell(&sto, &is_row_changed));
  ASSERT_EQ(true, is_row_changed);
  ASSERT_EQ(OB_SUCCESS, ss.next_cell());
  ASSERT_EQ(OB_SUCCESS, ss.get_cell(&sto, &is_row_changed));
  ASSERT_EQ(true, is_row_changed);
  ASSERT_EQ(OB_ITER_END, ss.next_cell());
}
Пример #9
0
int MockRootServer::handle_get_root(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }
  
  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());
    
    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    // fake location cell
    ObScanner scanner;
    char table[128] = "";
    char rowkey[128] = "";
    char temp[128] = "";
    ObCellInfo cell;
    
    // the first row
    sprintf(table, "root_table");
    cell.table_name_.assign(table, static_cast<int32_t>(strlen(table)));
    
    sprintf(rowkey, "row_100");
    cell.row_key_.assign(rowkey, static_cast<int32_t>(strlen(rowkey)));
    
    sprintf(temp, "2_ipv4");
    cell.column_name_.assign(temp, static_cast<int32_t>(strlen(temp)));
    cell.value_.set_int(16777343);
    scanner.add_cell(cell);
    
    sprintf(temp, "2_port");
    cell.column_name_.assign(temp, static_cast<int32_t>(strlen(temp)));
    cell.value_.set_int(10240);
    scanner.add_cell(cell);
    
    // the second row
    sprintf(rowkey, "row_200");
    cell.row_key_.assign(rowkey, static_cast<int32_t>(strlen(rowkey)));
    for (int i = 1; i <= 3; ++i)
    {
      sprintf(temp, "%d_ipv4", i);
      cell.column_name_.assign(temp, static_cast<int32_t>(strlen(temp)));
      cell.value_.set_int(16777343);
      scanner.add_cell(cell);
      
      sprintf(temp, "%d_port", i);
      cell.column_name_.assign(temp, static_cast<int32_t>(strlen(temp)));
      cell.value_.set_int(12341);
      scanner.add_cell(cell);
    }
    
    // the third row
    sprintf(rowkey, "row_999");
    cell.row_key_.assign(rowkey, static_cast<int32_t>(strlen(rowkey)));
    for (int i = 1; i <= 3; ++i)
    {
      sprintf(temp, "%d_ipv4", i);
      cell.column_name_.assign(temp, static_cast<int32_t>(strlen(temp)));
      cell.value_.set_int(16777343);
      scanner.add_cell(cell);
      
      sprintf(temp, "%d_port", i);
      cell.column_name_.assign(temp, static_cast<int32_t>(strlen(temp)));
      cell.value_.set_int(12341);
      scanner.add_cell(cell);
    }
    
    int32_t channel_id = ob_packet->getChannelId();
    ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    ret = send_response(OB_REPORT_TABLETS_RESPONSE, 1, out_buffer, connection, channel_id);
    TBSYS_LOG(INFO, "send get root response:ret[%d]", ret);
  }
  
  TBSYS_LOG(INFO, "handle get root table result:ret[%d]", ret);
  return ret;
}
Пример #10
0
TEST(TestObScanner, get_row)
{
  ObScanner scanner;
  const int table_num = 10;
  const int row_num = 20;
  const int column_num = 10;
  buffer table_name[table_num];
  buffer row_key[row_num];
  buffer column_name[column_num];
  for (int i = 0; i < table_num; i++)
  {
    table_name[i].assigne("T").appende(i);
  }
  for (int i = 0; i < row_num; i++)
  {
    row_key[i].assigne("R").appende(i);
  }
  for (int i = 0; i < column_num; i++)
  {
    column_name[i].assigne("C").appende(i);
  }

  for (int i = 0; i < table_num; i++)
  {
    for (int j = 0; j < row_num; j++)
    {
      for (int k = 0; k < column_num; k++)
      {
        ObCellInfo cell;
        cell.table_name_ = table_name[i].get_obstring();
        cell.row_key_ = row_key[j].get_obstring();
        cell.column_name_ = column_name[k].get_obstring();
        cell.value_.set_int(1);
        scanner.add_cell(cell);
      }
    }
  }

  ObScanner::RowIterator it = scanner.row_begin();
  ASSERT_EQ(it ==  scanner.row_begin(), true);

  for (int i = 0; i < table_num; i++)
  {
    for (int j = 0; j < row_num; j++)
    {
      ObCellInfo *row;
      int64_t num = 0;
      ASSERT_EQ(OB_SUCCESS, scanner.next_row());
      ASSERT_EQ(OB_SUCCESS, scanner.get_row(&row, &num));
      ASSERT_EQ(column_num, num);
    }
  }
  ASSERT_EQ(OB_ITER_END, scanner.next_row());

  buffer buf(1 << 21);
  scanner.serialize(buf.ptre(), buf.capacity(), buf.length());
  printf("%ld\n", buf.length());
  ObScanner dscanner;
  int64_t pos = 0;
  dscanner.deserialize(buf.ptre(), buf.length(), pos);

  for (int i = 0; i < table_num; i++)
  {
    for (int j = 0; j < row_num; j++)
    {
      ObCellInfo *row;
      int64_t num = 0;
      ASSERT_EQ(OB_SUCCESS, dscanner.next_row());
      ASSERT_EQ(OB_SUCCESS, dscanner.get_row(&row, &num));
      ASSERT_EQ(column_num, num);
    }
  }
  ASSERT_EQ(OB_ITER_END, dscanner.next_row());

  scanner.clear();
  scanner.set_mem_size_limit(256);
  int j = 0, k = 0;

  int err = OB_SUCCESS;
  for (; j < row_num; j++)
  {
    for (k = 0; k < column_num; k++)
    {
      ObCellInfo cell;
      cell.table_name_ = table_name[0].get_obstring();
      cell.row_key_ = row_key[j].get_obstring();
      cell.column_name_ = column_name[k].get_obstring();
      cell.value_.set_int(1);
      if (OB_SUCCESS != (err = scanner.add_cell(cell)))
      {
        break;
      }
    }
    if (OB_SUCCESS != err)
    {
      break;
    }
  }
  if (OB_SUCCESS != err)
  {
    scanner.rollback();
  }

  for (int i = 0; i < j; i++)
  {
    ObCellInfo *row;
    int64_t num = 0;
    ASSERT_EQ(OB_SUCCESS, scanner.next_row());
    ASSERT_EQ(OB_SUCCESS, scanner.get_row(&row, &num));
    ASSERT_EQ(column_num, num);
  }
  ASSERT_EQ(OB_ITER_END, scanner.next_row());

  buf.length() = 0;
  scanner.serialize(buf.ptre(), buf.capacity(), buf.length());
  printf("%ld\n", buf.length());
  dscanner.reset();
  pos = 0;
  dscanner.deserialize(buf.ptre(), buf.length(), pos);
  printf("row_num=%ld\n", dscanner.get_row_num());

  for (int i = 0; i < j; i++)
  {
    ObCellInfo *row;
    int64_t num = 0;
    ASSERT_EQ(OB_SUCCESS, dscanner.next_row());
    ASSERT_EQ(OB_SUCCESS, dscanner.get_row(&row, &num));
    ASSERT_EQ(column_num, num);
  }
  ASSERT_EQ(OB_ITER_END, dscanner.next_row());
}
Пример #11
0
TEST(TestObScanner, row_num)
{
  ObScanner scanner;
  const int table_num = 3;
  const int row_num = 20;
  const int column_num = 5;
  buffer table_name[table_num];
  buffer row_key[row_num];
  buffer column_name[column_num];
  for (int i = 0; i < table_num; i++)
  {
    table_name[i].assigne("T").appende(i);
  }
  for (int i = 0; i < row_num; i++)
  {
    row_key[i].assigne("R").appende(i);
  }
  for (int i = 0; i < column_num; i++)
  {
    column_name[i].assigne("C").appende(i);
  }

  for (int i = 0; i < table_num; i++)
  {
    for (int j = 0; j < row_num; j++)
    {
      for (int k = 0; k < column_num; k++)
      {
        ObCellInfo cell;
        cell.table_name_ = table_name[i].get_obstring();
        cell.row_key_ = row_key[j].get_obstring();
        cell.column_name_ = column_name[k].get_obstring();
        cell.value_.set_int(1);
        scanner.add_cell(cell);
      }
    }
  }

  ASSERT_EQ(scanner.get_row_num(), table_num * row_num);
  ASSERT_EQ(scanner.get_cell_num(), table_num * row_num * column_num);
  scanner.set_whole_result_row_num(1000);

  buffer buf(1 << 21);
  scanner.serialize(buf.ptre(), buf.capacity(), buf.length());
  printf("%ld\n", buf.length());
  ObScanner dscanner;
  int64_t pos = 0;
  dscanner.deserialize(buf.ptre(), buf.length(), pos);

  EXPECT_EQ(dscanner.get_row_num(), table_num * row_num);
  EXPECT_EQ(dscanner.get_cell_num(), table_num * row_num * column_num);
  EXPECT_EQ(dscanner.get_whole_result_row_num(), 1000);

  scanner.clear();
  scanner.set_mem_size_limit(256);
  int j = 0, k = 0;

  int err = OB_SUCCESS;
  for (; j < row_num; j++)
  {
    k = 0;
    for (; k < column_num; k++)
    {
      ObCellInfo cell;
      cell.table_name_ = table_name[0].get_obstring();
      cell.row_key_ = row_key[j].get_obstring();
      cell.column_name_ = column_name[k].get_obstring();
      cell.value_.set_int(1);
      if (OB_SUCCESS != (err = scanner.add_cell(cell)))
      {
        break;
      }
    }
    if (OB_SUCCESS != err)
    {
      break;
    }
  }
  if (OB_SUCCESS != err)
  {
    scanner.rollback();
  }

  EXPECT_EQ(scanner.get_row_num(), j);
  EXPECT_EQ(scanner.get_cell_num(), j * column_num);

  buf.length() = 0;
  scanner.serialize(buf.ptre(), buf.capacity(), buf.length());
  printf("%ld\n", buf.length());
  dscanner.reset();
  pos = 0;
  dscanner.deserialize(buf.ptre(), buf.length(), pos);

  EXPECT_EQ(dscanner.get_row_num(), j);
  EXPECT_EQ(dscanner.get_cell_num(), j * column_num);
}
Пример #12
0
int MockUpdateServer::handle_get_table(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObGetParam param;
  if (OB_SUCCESS == ret)
  {
    ret = param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check param failed");
    }
  }

  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());

    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    // fake data cell
    ObCellInfo cell;
    ObScanner scanner;
    ObString row_key;
    ObString column_name;
    char temp[256] = "";
    ObString table_name;
    char * name = "update_test_table";
    table_name.assign(name, strlen(name));
    cell.table_name_ = table_name;
    for (uint64_t i = 0; i < 10; ++i)
    {
      snprintf(temp, 256, "update_%lu_get_row_key:%lu", i, i);
      row_key.assign(temp, strlen(temp));
      cell.row_key_ = row_key;
      column_name.assign(temp, strlen(temp));
      cell.column_name_ = column_name;
      cell.value_.set_int(2234 + i);
      scanner.add_cell(cell);
    }

    int32_t channel_id = ob_packet->getChannelId();
    ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    //
    ret = send_response(OB_SCAN_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  TBSYS_LOG(INFO, "handle scan root table result:ret[%d]", ret);
  return ret;
}
Пример #13
0
int MockUpdateServer::handle_mock_get(ObPacket *ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObGetParam get_param;
  if (OB_SUCCESS == ret)
  {
    ret = get_param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check param failed");
    }
  }

  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());

    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    // fake cell
    ObCellInfo cell;
    ObScanner scanner;
    ObString row_key;
    ObString column_name;
    for (int32_t i = 0; i < get_param.get_cell_size(); i ++)
    {
      cell.table_id_ = get_param[i]->table_id_;
      cell.column_id_ = get_param[i]->column_id_;
      if (mock::join_table_id == cell.table_id_)
      {
        if (mock::join_column1_id == cell.column_id_)
        {
          row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey));
          cell.column_id_ = mock::join_column1_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::join_column1_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::join_column1_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else if (mock::join_column2_id == cell.column_id_)
        {
          row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey));
          cell.column_id_ = mock::join_column2_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::join_column2_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::join_column2_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else if (0 == cell.column_id_)
        {
          row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey));
          cell.column_id_ = mock::join_column1_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::join_column1_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::join_column1_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
          if (OB_SUCCESS == ret)
          {
            row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey));
            cell.column_id_ = mock::join_column2_id;
            cell.row_key_ = row_key;
            cell.value_.set_int(mock::join_column2_ups_value_1,true);
            ret = scanner.add_cell(cell);
            if (OB_SUCCESS == ret)
            {
              cell.value_.set_int(mock::join_column2_ups_value_2,true);
              ret = scanner.add_cell(cell);
            }
          }
          cell.column_id_ = 0;
        }
        else
        {
          TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_,
                    cell.column_id_);
          ret = OB_ERR_UNEXPECTED;
        }
      }
      else if (mock::table_id == cell.table_id_)
      {
        if (mock::column1_id == cell.column_id_)
        {
          row_key.assign((char*)mock::rowkey,strlen(mock::rowkey));
          cell.column_id_ = mock::column1_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::column1_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::column1_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else if (mock::column2_id == cell.column_id_)
        {
          row_key.assign((char*)mock::rowkey,strlen(mock::rowkey));
          cell.column_id_ = mock::column2_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::column2_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::column2_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_,
                    cell.column_id_);
          ret = OB_ERR_UNEXPECTED;
        }
      }
      else
      {
        TBSYS_LOG(ERROR, "unexpected table id [tableid:%lu]", cell.table_id_);
        ret = OB_ERR_UNEXPECTED;
      }
    }


    if (OB_SUCCESS == ret)
    {
      int64_t fullfilled_item_num = 0;
      if(0 == cell.column_id_)
      {
        fullfilled_item_num = 1;
      }
      else
      {
        fullfilled_item_num = 2;
      }
      ret = scanner.set_is_req_fullfilled(true,fullfilled_item_num);
      //scanner.set_timestamp(mock::schema_timestamp);
    }
    int32_t channel_id = ob_packet->getChannelId();
    ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    ret = send_response(OB_GET_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  TBSYS_LOG(INFO, "handle scan root table result:ret[%d]", ret);
  return ret;
}
Пример #14
0
int ObFinalResult::scan(const ObScanParam &scan_param, ObScanner &scanner) 
{
  UNUSED(scanner);
  int err = OB_SUCCESS;
  char max_key_buf[512];
  memset(max_key_buf,0xff, sizeof(max_key_buf));
  ObString max_key;
  max_key.assign(max_key_buf,sizeof(max_key_buf));
  ObRowInfo start;
  ObRowInfo end;
  map<ObRowInfo, vector<ObCellInfo> >::iterator start_it;
  map<ObRowInfo, vector<ObCellInfo> >::iterator end_it;
  ObCellInfo cur_cell;
  start.table_name_ = scan_param.get_table_name();
  end.table_name_ = scan_param.get_table_name();
  if (!scan_param.get_range()->border_flag_.is_min_value())
  {
    start.row_key_ = scan_param.get_range()->start_key_;
  }
  if (!scan_param.get_range()->border_flag_.is_max_value())
  {
    end.row_key_ = scan_param.get_range()->end_key_;
  }
  else
  {
    end.row_key_ = max_key;
  }
  if (scan_param.get_range()->border_flag_.inclusive_start())
  {
    start_it = row_infos_->lower_bound(start);
  }
  else
  {
    start_it = row_infos_->upper_bound(start);
  }
  if (scan_param.get_range()->border_flag_.inclusive_end())
  {
    end_it = row_infos_->upper_bound(end);
  }
  else
  {
    end_it = row_infos_->lower_bound(end);
  }
  for (;start_it != end_it && OB_SUCCESS == err; start_it ++)
  {
    for (int64_t scan_idx = 0; 
        scan_idx < scan_param.get_column_name_size() && OB_SUCCESS == err;
        scan_idx ++)
    {
      vector<ObCellInfo>::iterator cell_it = start_it->second.begin();
      cur_cell.table_name_ = scan_param.get_table_name();
      cur_cell.row_key_ = start_it->first.row_key_;
      cur_cell.column_name_ = scan_param.get_column_name()[scan_idx];
      cur_cell.value_.set_null();
      for (;cell_it != start_it->second.end(); cell_it ++)
      {
        if (cell_it->column_name_ == scan_param.get_column_name()[scan_idx])
        {
          break;
        }
      }
      if (cell_it != start_it->second.end())
      {
        cur_cell.value_ = cell_it->value_;
      }
      err = scanner.add_cell(cur_cell);
    }
  }
  return err;
}
Пример #15
0
int MockChunkServer::handle_scan_table(ObPacket * ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObScanParam param;
  if (OB_SUCCESS == ret)
  {
    ret = param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check param failed");
    }
  }

  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());

    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    // fake cell
    ObCellInfo cell;
    ObScanner scanner;
    ObRowkey row_key;
    ObString column_name;
    char temp[256] = "";
#if 1
    cell.table_id_ = 101;
    for (uint64_t i = 0; i < 10; ++i)
    {
      snprintf(temp, 256, "chunk_%lu_scan_row_key:%lu", i, i);
      row_key = make_rowkey(temp, &allocator_);
      cell.row_key_ = row_key;
      cell.column_id_ = i + 1;
      cell.value_.set_int(2234 + i);
      scanner.add_cell(cell);
    }
#else
    cell.table_id_ = 123;
    for (uint64_t i = 100; i < 200; ++i)
    {
      snprintf(temp, 256, "row_%lu", i);
      row_key = make_rowkey(temp, &allocator_);
      cell.row_key_ = row_key;
      cell.column_id_ = 101;
      cell.value_.set_int(2234 + i);
      scanner.add_cell(cell);
    }
#endif

    /* begin add by xiaochu */
    //Scanner Range must be set other wise the ms client will report error
    ObNewRange range;
    /*
    /// This will cause rowkey mismatch
    //char *start= "chunk_0_scan_row_key:0";
    //char *end  = "chunk_9_scan_row_key:9";
    */
    char *start= (char*)"row_100";
    char *end  = (char*)"row_200";
    range.start_key_ = make_rowkey(start, &allocator_);;
    range.end_key_ = make_rowkey(end, &allocator_);
    range.table_id_ = 103;
    scanner.set_range(range);
    scanner.set_is_req_fullfilled(true, 10);
    /* end add by xiaochu */

    int32_t channel_id = ob_packet->getChannelId();
    ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    ObScannerIterator iter;
    for (iter = scanner.begin(); iter != scanner.end(); ++iter)
    {
      iter.get_cell(cell);
      printf("server_temp:%s\n", to_cstring(cell.row_key_));
    }//
    ret = send_response(OB_SCAN_RESPONSE, 1, out_buffer, connection, channel_id);
  }
  TBSYS_LOG(INFO, "handle scan table result:ret[%d]", ret);
  return ret;
}
Пример #16
0
int MockUpdateServer::handle_mock_scan(ObPacket *ob_packet)
{
  int ret = OB_SUCCESS;
  ObDataBuffer* data = ob_packet->get_buffer();
  if (NULL == data)
  {
    ret = OB_ERROR;
  }

  ObScanParam scan_param;
  if (OB_SUCCESS == ret)
  {
    ret = scan_param.deserialize(data->get_data(), data->get_capacity(), data->get_position());
    if (ret != OB_SUCCESS)
    {
      TBSYS_LOG(ERROR, "%s", "check scan_param failed");
    }
  }

  tbnet::Connection* connection = ob_packet->get_connection();
  ThreadSpecificBuffer::Buffer* thread_buffer = response_packet_buffer_.get_buffer();
  if (NULL == thread_buffer)
  {
    ret = OB_ERROR;
  }
  else
  {
    thread_buffer->reset();
    ObDataBuffer out_buffer(thread_buffer->current(), thread_buffer->remain());

    ObResultCode result_msg;
    result_msg.result_code_ = ret;
    ret = result_msg.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());

    // fake cell
    ObCellInfo cell;
    ObScanner scanner;
    ObString row_key;
    ObString column_name;
    cell.table_id_ = scan_param.get_table_id();
    if (mock::join_table_id == cell.table_id_)
    {
      for (int32_t i = 0; i < scan_param.get_column_id_size(); i++)
      {
        if (mock::join_column1_id == scan_param.get_column_id()[i])
        {
          row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey));
          cell.column_id_ = mock::join_column1_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::join_column1_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::join_column1_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else if (mock::join_column2_id == scan_param.get_column_id()[i])
        {
          row_key.assign((char*)mock::join_rowkey,strlen(mock::join_rowkey));
          cell.column_id_ = mock::join_column2_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::join_column2_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::join_column2_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_,
                    scan_param.get_column_id()[i]);
          ret = OB_ERR_UNEXPECTED;
        }
      }
    }
    else if (mock::table_id == cell.table_id_)
    {
      for (int32_t i = 0; i < scan_param.get_column_id_size(); i++)
      {
        if (mock::column1_id == scan_param.get_column_id()[i])
        {
          row_key.assign((char*)mock::rowkey,strlen(mock::rowkey));
          cell.column_id_ = mock::column1_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::column1_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::column1_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else if (mock::column2_id == scan_param.get_column_id()[i])
        {
          row_key.assign((char*)mock::rowkey,strlen(mock::rowkey));
          cell.column_id_ = mock::column2_id;
          cell.row_key_ = row_key;
          cell.value_.set_int(mock::column2_ups_value_1,true);
          ret = scanner.add_cell(cell);
          if (OB_SUCCESS == ret)
          {
            cell.value_.set_int(mock::column2_ups_value_2,true);
            ret = scanner.add_cell(cell);
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "unepxected column id [tableid:%lu,columnid:%lu]", cell.table_id_,
                    scan_param.get_column_id()[i]);
          ret = OB_ERR_UNEXPECTED;
        }
      }
    }
    else
    {
      TBSYS_LOG(ERROR, "unexpected table id [tableid:%lu]", cell.table_id_);
      ret = OB_ERR_UNEXPECTED;
    }

    if (OB_SUCCESS == ret)
    {
      ret = scanner.set_is_req_fullfilled(true,1);
      // scanner.set_timestamp(mock::schema_timestamp);
    }
    int64_t pos = 0;
    char range_buf[512];
    ObString range_str;
    if (OB_SUCCESS == ret)
    {
      ObRange range;
      range.border_flag_.set_min_value();
      range.border_flag_.set_max_value();
      ret = range.serialize(range_buf,sizeof(range_buf),pos);
      if (OB_SUCCESS == ret)
      {
        range_str.assign(range_buf,pos);
        // ret = scanner.set_ext_info(range_str);
      }
      pos = 0;
      TBSYS_LOG(INFO, "pos:%ld,ret:%d",pos, 
                range.deserialize(range_str.ptr(),range_str.length(),pos));
    }
    int32_t channel_id = ob_packet->getChannelId();
    if (OB_SUCCESS == ret)
    {
      ret = scanner.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
    }
    if (OB_SUCCESS == ret)
    {
      ret = send_response(OB_GET_RESPONSE, 1, out_buffer, connection, channel_id);
    }
  }
  TBSYS_LOG(INFO, "handle scan root table result:ret[%d]", ret);
  return ret;
}
Пример #17
0
    int ObGetScanProxy::get_compact_row(ObTablet& tablet,ObRowkey& rowkey,const int64_t compactsstable_version,
                                        const ColumnFilter *cf,
                                        ObScanner& compact_scanner)
    {

      int32_t compactsstable_num        = tablet.get_compactsstable_num();
      ObCompactSSTableMemNode* mem_node = tablet.get_compactsstable_list();
      ObCompactMemIteratorArray *its    = GET_TSI_MULT(ObCompactMemIteratorArray,TSI_CS_COMPACTSSTABLE_ITERATOR_1);
      ObCompactSSTableMem* mem          = NULL;
      int ret                           = OB_SUCCESS;
      int32_t m                         = 0;
      uint64_t table_id                 = OB_INVALID_ID;
      bool add_row_not_exist            = false;
      ObMerger merger;

      for(m=0; (OB_SUCCESS == ret) &&
            (mem_node != NULL) && (m < compactsstable_num); )
      {
        mem = &mem_node->mem_;
        if (NULL == mem)
        {
          TBSYS_LOG(WARN,"unexpect error,compactsstable is null");
          ret = OB_ERROR;
        }
        else if (ObVersion::compare(mem->get_data_version(),compactsstable_version) <= 0)
        {
          if (OB_INVALID_ID == table_id)
          {
            table_id = mem->get_table_id();
          }
          if (!mem->is_row_exist(rowkey))
          {
            //row not exists,do nothing            
            TBSYS_LOG(DEBUG,"row not exist,%s", to_cstring(rowkey));
            add_row_not_exist = true;
          }
          else if ((ret = its->iters_[m].init(mem)) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN,"init iterator failed,ret=%d",ret);
          }
          else if ((ret = its->iters_[m].set_get_param(rowkey,cf)) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN,"set get param failed,ret=%d",ret);
          }
          else if ((ret = merger.add_iterator(&(its->iters_[m]))) != OB_SUCCESS)
          {
            TBSYS_LOG(WARN,"add iterator to merger failed,ret=%d",ret);
          }          
          else
          {
            ++m;
            //success
          }
        }
        else
        {
          break; //got enough data
        }
        mem_node = mem_node->next_;
      }

      if ((m > 0) && (OB_SUCCESS == ret))
      {
        if ((ret = fill_compact_data(merger,compact_scanner)) != OB_SUCCESS)
        {
          TBSYS_LOG(WARN,"fill compact data failed,ret=%d",ret);
        }
      }
      else if ((OB_SUCCESS == ret) && add_row_not_exist)
      {
        //not exist
        ObCellInfo cell;
        cell.table_id_ = table_id;
        cell.column_id_ = OB_INVALID_ID;
        cell.value_.set_ext(ObActionFlag::OP_ROW_DOES_NOT_EXIST);
        cell.row_key_ = rowkey;
        if ((ret = compact_scanner.add_cell(cell,false,true)) != OB_SUCCESS)
        {
          TBSYS_LOG(WARN,"add not exist cell failed,ret=%d",ret);
        }
      }
      return ret;
    }
Пример #18
0
int ObMergerGetRequest::fill_result(ObScanner & scanner, ObGetParam &org_param,
  bool &got_all_result)
{
  int err = OB_SUCCESS;
  ObInnerCellInfo *cur_cell = NULL;
  bool size_over_flow = false;
  bool row_changed = false;
  int64_t got_cell_count = 0;
  if (!sealed_)
  {
    TBSYS_LOG(WARN,"request not finished yet");
    err  = OB_INVALID_ARGUMENT;
  }

  for (int64_t i = 0; (i < cur_row_cell_cnt_) && (OB_SUCCESS == err); i ++, poped_cell_count_ ++)
  {
    if ((OB_SUCCESS != (err = scanner.add_cell(row_cells_[i]))))
    {
      TBSYS_LOG(WARN,"fail to add cell to scanner [err:%d]", err);
    }
  }
  while ((OB_SUCCESS == err) && (!size_over_flow))
  {
    if ((OB_SUCCESS != (err = merger_operator_.next_cell())) && (OB_ITER_END != err))
    {
      TBSYS_LOG(WARN,"fail to call next_cell [err:%d]", err);
    }
    if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = merger_operator_.get_cell(&cur_cell, &row_changed))))
    {
      TBSYS_LOG(WARN,"fail to get cell from ObGetMerger [err:%d]", err);
    }
    if (OB_SUCCESS == err)
    {
      got_cell_count ++;
    }
    if ((OB_SUCCESS == err) && row_changed)
    {
      cur_row_cell_cnt_ = 0;
      last_not_exist_cell_.table_id_ = OB_INVALID_ID;
    }
    if ((OB_SUCCESS == err)
      && ((cur_cell->value_.get_ext() == ObActionFlag::OP_ROW_DOES_NOT_EXIST)
      || (cur_cell->value_.get_ext() == ObActionFlag::OP_DEL_TABLE)))
    {
      if ((OB_INVALID_ID != last_not_exist_cell_.table_id_) && (last_not_exist_cell_.table_id_ == cur_cell->table_id_)
        && (last_not_exist_cell_.row_key_ == cur_cell->row_key_))
      {
        poped_cell_count_ ++;
        continue ;
      }
      else
      {
        last_not_exist_cell_ = *cur_cell;
      }
    }

    if ((OB_SUCCESS == err) && (cur_row_cell_cnt_ >= MAX_ROW_COLUMN_COUNT))
    {
      TBSYS_LOG(WARN,"row cell count is too large [cur_row_cell_cnt_:%ld, MAX_ROW_COLUMN_COUNT:%ld]",
        cur_row_cell_cnt_, MAX_ROW_COLUMN_COUNT);
      //err = OB_ARRAY_OUT_OF_RANGE;
      cur_row_cell_cnt_ = 0;
    }
    if (OB_SUCCESS == err)
    {
      row_cells_[cur_row_cell_cnt_].table_id_ = OB_INVALID_ID;
      row_cells_[cur_row_cell_cnt_].table_name_ = org_param[poped_cell_count_]->table_name_;
      row_cells_[cur_row_cell_cnt_].column_name_ = org_param[poped_cell_count_]->column_name_;
      row_cells_[cur_row_cell_cnt_].column_id_ = OB_INVALID_ID;
      row_cells_[cur_row_cell_cnt_].row_key_ = cur_cell->row_key_;
      row_cells_[cur_row_cell_cnt_].value_ = cur_cell->value_;
      ++cur_row_cell_cnt_;
    }
    if (OB_SUCCESS == err)
    {
      if ((OB_SUCCESS != (err = scanner.add_cell(row_cells_[cur_row_cell_cnt_ - 1]))) && (OB_SIZE_OVERFLOW != err))
      {
        TBSYS_LOG(WARN,"fail to add cell to result [err:%d]", err);
      }
      else if (OB_SIZE_OVERFLOW == err)
      {
        if (OB_SUCCESS != (err = scanner.rollback()))
        {
          TBSYS_LOG(WARN,"fail to rollback ObScanner [err:%d]", err);
        }
        else
        {
          size_over_flow = true;
          poped_cell_count_ -= cur_row_cell_cnt_ - 1;
          got_cell_count -= cur_row_cell_cnt_;
        }
      }
      else if (OB_SUCCESS == err)
      {
        poped_cell_count_ ++;
      }
    }
  }
  if (OB_ITER_END == err)
  {
    err = OB_SUCCESS;
  }
  if (OB_SUCCESS == err)
  {
    got_all_result = !size_over_flow;
  }
  if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = scanner.set_is_req_fullfilled(got_all_result,got_cell_count))))
  {
    TBSYS_LOG(WARN,"fail to set fullfill infomation [err:%d]", err);
  }
  return err;
}
Пример #19
0
int ObFakeSqlUpsRpcProxy2::gen_new_scanner(uint64_t table_id, int64_t start_rowkey, int64_t end_rowkey, ObBorderFlag border_flag, ObNewScanner &new_scanner, bool is_fullfilled)
{
    int ret = OB_SUCCESS;
    char rowkey_buf[100];
    ObString rowkey_str;
    ObObj rowkey_obj;
    ObRowkey rowkey;

    ObScanner scanner;

    ObNewRange range;
    range.table_id_ = table_id;
    range.border_flag_ = border_flag;
    gen_new_range(start_rowkey, end_rowkey, range_buf_, range);

    if(OB_SUCCESS != (ret = scanner.set_range(range)))
    {
        TBSYS_LOG(WARN, "scanner set range fail:ret[%d]", ret);
    }

    ObUpsRow ups_row;
    ObRowDesc row_desc;
    ObObj value;

    if(OB_SUCCESS == ret)
    {
        for(uint64_t i = 0; OB_SUCCESS == ret && i<COLUMN_NUMS; i++)
        {
            if(OB_SUCCESS != (ret = row_desc.add_column_desc(TABLE_ID, i+OB_APP_MIN_COLUMN_ID)))
            {
                TBSYS_LOG(WARN, "add column desc fail:ret[%d]", ret);
            }
        }
        ups_row.set_row_desc(row_desc);
    }

    int64_t start = border_flag.inclusive_start() ? start_rowkey : start_rowkey + 1;
    int64_t end = border_flag.inclusive_end() ? end_rowkey : end_rowkey - 1;

    ObCellInfo cell_info;


    if(OB_SUCCESS == ret)
    {
        for(int64_t i=start; OB_SUCCESS == ret && i<=end; i++)
        {
            sprintf(rowkey_buf, "rowkey_%05ld", i);
            rowkey_str.assign_ptr(rowkey_buf, (int32_t)strlen(rowkey_buf));
            rowkey_obj.set_varchar(rowkey_str);
            rowkey.assign(&rowkey_obj, 1);

            for(int64_t j=0; OB_SUCCESS == ret && j<COLUMN_NUMS; j++)
            {
                cell_info.table_id_ = TABLE_ID;
                cell_info.row_key_ = rowkey;
                cell_info.column_id_ = j+OB_APP_MIN_COLUMN_ID;
                cell_info.value_.set_int(i * 1000 + j);
                if(OB_SUCCESS != (ret = scanner.add_cell(cell_info)))
                {
                    TBSYS_LOG(WARN, "scanner add cell fail:ret[%d]", ret);
                }
            }
        }
    }


    int64_t fullfilled_cell_num = (end - start + 1) * COLUMN_NUMS;

    if(OB_SUCCESS == ret)
    {
        if(OB_SUCCESS != (ret = scanner.set_is_req_fullfilled(is_fullfilled, fullfilled_cell_num)))
        {
            TBSYS_LOG(WARN, "set fullfilled fail:ret[%d]", ret);
        }
        else if(OB_SUCCESS != (ret = ObNewScannerHelper::convert(scanner, &row_desc, new_scanner)))
        {
            TBSYS_LOG(WARN, "convert scanner to new scanner fail:ret[%d]", ret);
        }
    }

    return ret;
}