int ObMergerSortedOperator::add_sharding_result(ObScanner & sharding_res, const ObNewRange &query_range,
  bool &is_finish)
{
  int err = OB_SUCCESS;
  if ((OB_SUCCESS == err) && (NULL == scan_param_))
  {
    TBSYS_LOG(WARN,"operator was not initialized yet [scan_param_:%p]", scan_param_);
    err = OB_INVALID_ARGUMENT;
  }
  if ((OB_SUCCESS == err) && (sharding_result_count_ >= MAX_SHARDING_RESULT_COUNT))
  {
    TBSYS_LOG(WARN,"array is full [MAX_SHARDING_RESULT_COUNT:%ld,sharding_result_count_:%ld]",
      MAX_SHARDING_RESULT_COUNT, sharding_result_count_);
    err = OB_ARRAY_OUT_OF_RANGE;
  }
  /// @todo (wushi [email protected]) check fullfill item number and size property
  bool is_fullfilled = false;
  int64_t fullfilled_item_num = 0;
  ObRowkey last_row_key;
  ObNewRange cs_tablet_range;
  if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = sharding_res.get_is_req_fullfilled(is_fullfilled,fullfilled_item_num))))
  {
    TBSYS_LOG(WARN,"fail to get fullfilled info from sharding result [err:%d]", err);
  }
  if (OB_SUCCESS == err)
  {
    if (OB_SUCCESS == (err = sharding_res.get_last_row_key(last_row_key)))
    {
    }
    else if (OB_ENTRY_NOT_EXIST == err)
    {
      err = OB_SUCCESS;
    }
    else
    {
      TBSYS_LOG(WARN,"fail to get last rowkey from sharding result [err:%d]", err);
    }
  }

  if (OB_SUCCESS == err)
  {
    if (is_fullfilled)
    {
      if ((OB_SUCCESS == err) && (OB_SUCCESS != (err = sharding_res.get_range(cs_tablet_range))))
      {
        TBSYS_LOG(WARN,"fail to get tablet range from sharding result [err:%d]", err);
      }
      if (OB_SUCCESS == err)
      {
        if (ScanFlag::FORWARD == scan_param_->get_scan_direction())
        {
          last_row_key = cs_tablet_range.end_key_;
        }
        else
        {
          last_row_key = cs_tablet_range.start_key_;
        }
      }
    }
    if (OB_SUCCESS == err)
    {
      fullfilled_item_num = sharding_res.get_row_num();
      sharding_result_arr_[sharding_result_count_].init(sharding_res,query_range,*scan_param_, last_row_key, fullfilled_item_num);
      sharding_result_count_ ++;
    }
  }
  is_finish = false;
  if (OB_SUCCESS == err)
  {
    sort(is_finish, &sharding_res);
  }
  TBSYS_LOG(DEBUG, "add sharding result. is_finish=%d, err=%d", is_finish, err);
  return err;
}
Ejemplo n.º 2
0
    int ObGetScanProxy::cs_scan(const ObScanParam& scan_param, ObScanner& scanner, 
                                ObIterator* it_out[],int64_t& it_size)
    {
      int ret = OB_SUCCESS;
      int64_t it_num = 0;

      if ((NULL == it_out) || it_size <= 0)
      {
        ret = OB_INVALID_ARGUMENT;
      }

      if ((OB_SUCCESS == ret) && ((ret = tablet_manager_.scan(scan_param, scanner)) != OB_SUCCESS))
      {
        TBSYS_LOG(WARN, "failed to scan data from local chunk server, ret=%d", ret);        
      }

      if (OB_SUCCESS == ret)
      {
        ObSSTableScanner *sstable_scanner = 
          GET_TSI_MULT(ObSSTableScanner, TSI_CS_SSTABLE_SCANNER_1);
        if (NULL == sstable_scanner)
        {
          TBSYS_LOG(ERROR, "failed to get thread local sstable scanner, "
                           "sstable_scanner=%p", 
                    sstable_scanner);
          ret = OB_ALLOCATE_MEMORY_FAILED;
        }
        else
        {
          tablet_range_.reset();
          ret = scanner.get_range(tablet_range_);
          if (OB_SUCCESS == ret)
          {
            it_out[it_num++] = sstable_scanner;
          }
          else 
          {
            TBSYS_LOG(WARN, "failed to get tablet range from scanner, ret=%d", ret);
          }
        }
      }

      if (OB_SUCCESS == ret)
      {
        int64_t query_version = 0;
        const ObVersionRange version_range = scan_param.get_version_range();
        if (!version_range.border_flag_.is_max_value() && version_range.end_version_ != 0)
        {
          query_version = version_range.end_version_;
        }
        ObTablet*& scan_tablet            = tablet_manager_.get_cur_thread_scan_tablet();
        int32_t compactsstable_num        = scan_tablet->get_compactsstable_num();

        if (compactsstable_num > 0)
        {
          ObCompactSSTableMemNode* mem_node = scan_tablet->get_compactsstable_list();
          ObCompactMemIteratorArray *its    = GET_TSI_MULT(ObCompactMemIteratorArray,TSI_CS_COMPACTSSTABLE_ITERATOR_1);
          ColumnFilter* cf                  = GET_TSI_MULT(ColumnFilter,TSI_CS_COLUMNFILTER_1);          
          ObCompactSSTableMem* mem          = NULL;          
          int64_t major_version             = 0;
          int32_t i                         = 0;          

          if ((NULL == mem_node) || (NULL == cf) || (NULL == its))
          {
            TBSYS_LOG(WARN,"unexpect error,mem_node=%p,cf=%p,its=%p",mem_node,cf,its);
            ret = OB_ALLOCATE_MEMORY_FAILED;
          }
          else
          {
            cf->clear();
          }

          if ((OB_SUCCESS == ret) && (NULL == (cf = ColumnFilter::build_columnfilter(scan_param, cf))))
          {
            TBSYS_LOG(WARN,"build columnfilter failed");
            ret = OB_ERROR;
          }

          for(i=0; (mem_node != NULL) && (i < compactsstable_num) && (OB_SUCCESS == ret) && (it_num < it_size);++i)
          {
            mem = &mem_node->mem_;
            if (NULL == mem)
            {
              TBSYS_LOG(WARN,"unexpect error,compact mem is null");
              ret = OB_ERROR;
            }
            else
            {
              //query version just have major version
              major_version = mem->get_version_range().major_version_;
              if ((0 == query_version) || (query_version > 0 && major_version <= query_version))
              {
                if ((ret = its->iters_[i].init(mem)) != OB_SUCCESS)
                {
                  TBSYS_LOG(WARN,"init iterator of compact mem failed,ret=%d",ret);
                }
                else if ((ret = its->iters_[i].set_scan_param(*scan_param.get_range(),cf,
                                                              scan_param.get_scan_direction() == ScanFlag::BACKWARD))
                         != OB_SUCCESS)
                {
                  TBSYS_LOG(WARN,"set scan param failed,ret=%d",ret);
                }
                else
                {
                  it_out[it_num++] = &its->iters_[i];
                  //set data version to the last compact sstable version
                  scanner.set_data_version(mem->get_data_version());
                  FILL_TRACE_LOG("add compact iterator to merger,it_num:%ld,version:%ld",it_num,mem->get_data_version());
                }
              }
              else
              {
                break; //got enough data
              }
            }
            mem_node = mem_node->next_;
          } //end for
        } //end compactsstable_num > 0
      }

      if (OB_SUCCESS == ret)
      {
        it_size = it_num;
      }

      return ret;
    }
 int get_next_param(
     const ObScanParam &org_scan_param, const ObScanner &prev_scan_result, 
     ObScanParam *scan_param, ObMemBuf &range_buffer)
 {
   int err = OB_SUCCESS;
   const ObReadParam &org_read_param = org_scan_param;
   ObReadParam *read_param = scan_param;
   ObNewRange tablet_range; 
   const ObNewRange *org_scan_range = NULL;
   ObNewRange cur_range;
   if(NULL != scan_param)
   {
     scan_param->reset();
     *read_param = org_read_param;
   }
   bool request_fullfilled = false;
   int64_t fullfilled_row_num = 0;
   err = prev_scan_result.get_is_req_fullfilled(request_fullfilled,fullfilled_row_num);
   if (OB_SUCCESS == err)
   {
     org_scan_range = org_scan_param.get_range();
     if (NULL == org_scan_range)
     {
       TBSYS_LOG(WARN, "unexpected error, can't get range from org scan param");
       err  = OB_INVALID_ARGUMENT;
     }
   }
   
   ObRowkey last_row_key;
   if (OB_SUCCESS == err)
   {
     if (request_fullfilled)
     {
       err = prev_scan_result.get_range(tablet_range);
       if (OB_SUCCESS == err)
       {
         if (true == is_finish_scan(org_scan_param, tablet_range))
         {
           err = OB_ITER_END;
         }
         else if (ScanFlag::FORWARD == org_scan_param.get_scan_direction()) 
         {
           last_row_key = tablet_range.end_key_;
         }
         else
         {
           last_row_key = tablet_range.start_key_;
         }
       }
     }
     else
     {
       err = prev_scan_result.get_last_row_key(last_row_key);
       if (OB_ENTRY_NOT_EXIST == err)
       {
         /// first time, remain unchanged
       }
       else if (OB_SUCCESS != err)
       {
         TBSYS_LOG(WARN, "unexpected error, scanner should contain at least one cell");
       }
     }
   }
 
   if (OB_SUCCESS == err && NULL != scan_param)
   {
     cur_range =*org_scan_range;
     // forward
     if (ScanFlag::FORWARD == org_scan_param.get_scan_direction())
     {
       cur_range.start_key_ = last_row_key;
       cur_range.border_flag_.unset_inclusive_start();
     }
     else
     {
       cur_range.end_key_ = last_row_key;
       if (request_fullfilled)
       {
         // tablet range start key
         cur_range.border_flag_.set_inclusive_end();
       }
       else
       {
         // the smallest rowkey
         cur_range.border_flag_.unset_inclusive_end();
       }
     }
   }
 
   // first time remain unchanged
   if (OB_ENTRY_NOT_EXIST == err)
   {
     cur_range =*org_scan_range;
     err = OB_SUCCESS;
   }
   
   if (OB_SUCCESS == err && NULL != scan_param)
   {
     err = allocate_range_buffer(cur_range, range_buffer);
   }
 
   if (OB_SUCCESS == err && NULL != scan_param)
   {
     scan_param->set(org_scan_param.get_table_id(), org_scan_param.get_table_name(), cur_range);
     for (int32_t cell_idx = 0; 
         cell_idx < org_scan_param.get_column_id_size() && OB_SUCCESS == err;
         cell_idx ++)
     {
       err = scan_param->add_column(org_scan_param.get_column_id()[cell_idx]);
     }
     if(OB_SUCCESS == err)
     {
       scan_param->set_scan_size(GET_SCAN_SIZE(org_scan_param.get_scan_size()));
       scan_param->set_scan_flag(org_scan_param.get_scan_flag());
     }
   }
   return err;
 }