Exemplo n.º 1
0
void total_scan(const char *fname, PageArena<char> &allocer, MockClient &client, const char *version_range)
{
  ObScanner scanner;
  ObScanParam scan_param;
  read_scan_param(fname, SCAN_PARAM_SECTION, allocer, scan_param);
  scan_param.set_version_range(str2range(version_range));
  scan_param.set_is_read_consistency(false);

  int64_t total_fullfilled_num = 0;
  int64_t total_row_counter = 0;
  int64_t total_timeu = 0;
  while (true)
  {
    int64_t timeu = tbsys::CTimeUtil::getTime();
    int err = client.ups_scan(scan_param, scanner, timeout);
    timeu = tbsys::CTimeUtil::getTime() - timeu;
    if (OB_SUCCESS != err)
    {
      fprintf(stdout, "[%s] err=%d\n", __FUNCTION__, err);
      break;
    }
    else
    {
      int64_t row_counter = 0;
      while (OB_SUCCESS == scanner.next_cell())
      {
        ObCellInfo *ci = NULL;
        bool is_row_changed = false;
        scanner.get_cell(&ci, &is_row_changed);
        //fprintf(stdout, "%s\n", updateserver::print_cellinfo(ci, "CLI_SCAN"));
        if (is_row_changed)
        {
          row_counter++;
        }
      }
      bool is_fullfilled = false;
      int64_t fullfilled_num = 0;
      ObRowkey last_rk;
      scanner.get_last_row_key(last_rk);
      scanner.get_is_req_fullfilled(is_fullfilled, fullfilled_num);
      fprintf(stdout, "[SINGLE_SCAN] is_fullfilled=%s fullfilled_num=%ld row_counter=%ld timeu=%ld last_row_key=[%s]\n",
              STR_BOOL(is_fullfilled), fullfilled_num, row_counter, timeu, to_cstring(last_rk));
      total_fullfilled_num += fullfilled_num;
      total_row_counter += row_counter;
      total_timeu += timeu;
      if (is_fullfilled)
      {
        break;
      }
      else
      {
        const_cast<ObNewRange*>(scan_param.get_range())->start_key_ = last_rk;
        const_cast<ObNewRange*>(scan_param.get_range())->border_flag_.unset_min_value();
        const_cast<ObNewRange*>(scan_param.get_range())->border_flag_.unset_inclusive_start();
      }
    }
  }
  fprintf(stdout, "[TOTAL_SCAN] total_fullfilled_num=%ld total_row_counter=%ld total_timeu=%ld\n",
          total_fullfilled_num, total_row_counter, total_timeu);
}
// Hybrid policy in async mode.
// If BIT_CNN_RECEIVED is set, then we use cnn confidence.
// If BIT_CNN_RECEIVED is not set, then we use fast rollout confidence. In this case, if BIT_CNN_SENT is not set, then after policy selection, we will resend the situation to DCNN server.
BOOL async_policy(ThreadInfo *info, TreeBlock *bl, const Board *board, BlockOffset *offset, TreeBlock **child_chosen) {
  TreeHandle *s = info->s;

  if (bl->terminal_status != S_EMPTY) return FALSE;
  BOOL use_cnn_policy = cnn_data_get_evaluated_bit(&bl->cnn_data, BIT_CNN_RECEIVED);
  char buf[30];

  const float C = 1.4142;
  // Find the node with highest noisy winrate score
  float best_score = -1.0;
  Stone player = board->_next_player;

  PRINT_DEBUG("Async_policy. b = %lx, use_cnn_policy = %s, n = %d\n", (uint64_t)bl, STR_BOOL(use_cnn_policy), bl->n);
  for (int i = 0; i < bl->n; ++i) {
    float black_win = ((float)bl->data.stats[i].black_win) + 0.5;
    unsigned int n = bl->data.stats[i].total + 1;
    unsigned int n_parent = bl->parent->data.stats[bl->parent_offset].total + 1;

    float log_n_parent = log2((float)n_parent);
    float winning_rate = ((float)black_win) / n;
    if (player == S_WHITE) winning_rate = 1 - winning_rate;

    float confidence = use_cnn_policy ? bl->cnn_data.confidences[i] : bl->cnn_data.fast_confidences[i];
    float this_score = winning_rate + add_uct_prior(info, confidence, n, n_parent);

    PRINT_DEBUG("[%d]: %s, score = %f, n = %d, n_parent = %d, winning_rate = %f, conf = %f, winning_rate+prior = %f\n",
        i, get_move_str(bl->data.moves[i], player, buf), this_score, n, n_parent, winning_rate, confidence, this_score);
    //
    // float this_score = winning_rate + bl->cnn_data.confidences[i] + thread_randf(info) * sigma;
    // float this_score = winning_rate + thread_randf(info);
    if (this_score > best_score) {
      best_score = this_score;
      *offset = i;
      *child_chosen = bl->children[i].child;
    }
  }
  PRINT_DEBUG("Best score = %f, best index = %d, best move = %s\n", best_score, *offset, get_move_str(bl->data.moves[*offset], player, buf));

  if (! s->common_params->cpu_only) {
    if (use_cnn_policy) {
      info->use_cnn ++;
    } else {
      send_to_cnn(info, bl, board);
    }
  }
  info->use_async ++;

  if (best_score < 0) {
    // No node is selected.
    return FALSE;
  }

  return TRUE;
}
Exemplo n.º 3
0
void print_scanner(ObScanner &scanner)
{
  int64_t row_counter = 0;
  while (OB_SUCCESS == scanner.next_cell())
  {
    ObCellInfo *ci = NULL;
    bool is_row_changed = false;
    scanner.get_cell(&ci, &is_row_changed);
    fprintf(stdout, "%s\n", common::print_cellinfo(ci, "CLI_SCAN"));
    if (is_row_changed)
    {
      row_counter++;
    }
  }
  bool is_fullfilled = false;
  int64_t fullfilled_num = 0;
  ObRowkey last_rk;
  scanner.get_last_row_key(last_rk);
  scanner.get_is_req_fullfilled(is_fullfilled, fullfilled_num);
  fprintf(stdout, "is_fullfilled=%s fullfilled_num=%ld row_counter=%ld last_row_key=[%s]\n",
          STR_BOOL(is_fullfilled), fullfilled_num, row_counter, to_cstring(last_rk));
}
Exemplo n.º 4
0
int param_get(const char *fname, MockClient &client)
{
  int err = OB_SUCCESS;
  int fd = open(fname, O_RDONLY);
  if (-1 == fd)
  {
    fprintf(stdout, "open [%s] fail errno=%u\n", fname, errno);
    err = OB_ERROR;
  }
  else
  {
    struct stat st;
    fstat(fd, &st);
    char *buf = (char*)malloc(st.st_size);
    if (NULL == buf)
    {
      fprintf(stdout, "malloc buf fail size=%ld\n", st.st_size);
       err = OB_ERROR;
    }
    else
    {
      ssize_t __attribute__((unused)) ret = read(fd, buf, st.st_size);
      int64_t pos = 0;
      ObGetParam get_param;
      if (OB_SUCCESS != get_param.deserialize(buf, st.st_size, pos))
      {
        fprintf(stdout, "deserialize get_param fail\n");
        err = OB_ERROR;
      }
      else
      {
        get_param.set_is_read_consistency(false);
        ObScanner scanner;
        int err = client.ups_get(get_param, scanner, timeout);
        fprintf(stdout, "[%s] err=%d\n", __FUNCTION__, err);
        if (OB_SUCCESS == err)
        {
          int64_t row_counter = 0;
          while (OB_SUCCESS == scanner.next_cell())
          {
            ObCellInfo *ci = NULL;
            bool is_row_changed = false;
            scanner.get_cell(&ci, &is_row_changed);
            fprintf(stdout, "%s\n", common::print_cellinfo(ci, "CLI_GET"));
            if (is_row_changed)
            {
              row_counter++;
            }
          }
          bool is_fullfilled = false;
          int64_t fullfilled_num = 0;
          ObRowkey last_rk;
          scanner.get_last_row_key(last_rk);
          scanner.get_is_req_fullfilled(is_fullfilled, fullfilled_num);
          fprintf(stdout, "is_fullfilled=%s fullfilled_num=%ld row_counter=%ld last_row_key=[%s]\n",
                  STR_BOOL(is_fullfilled), fullfilled_num, row_counter, to_cstring(last_rk));
        }
      }
      free(buf);
    }
    close(fd);
  }
  return err;
}
Exemplo n.º 5
0
 const char *print_obj(const ObObj &obj)
 {
   static const int64_t BUFFER_SIZE = 128 * 1024;
   static __thread char buffers[2][BUFFER_SIZE];
   static __thread int64_t i = 0;
   char *buffer = buffers[i++ % 2];
   buffer[0] = '\0';
   switch (obj.get_type())
   {
     case ObNullType:
       snprintf(buffer, BUFFER_SIZE, "obj_type=null");
       break;
     case ObIntType:
       {
         bool is_add = false;
         int64_t tmp = 0;
         obj.get_int(tmp, is_add);
         snprintf(buffer, BUFFER_SIZE, "obj_type=int value=%ld is_add=%s", tmp, STR_BOOL(is_add));
       }
       break;
     case ObDateTimeType:
       {
         bool is_add = false;
         ObDateTime tmp = 0;
         obj.get_datetime(tmp, is_add);
         snprintf(buffer, BUFFER_SIZE, "obj_type=data_time value=%s is_add=%s", time2str(tmp), STR_BOOL(is_add));
       }
       break;
     case ObPreciseDateTimeType:
       {
         bool is_add = false;
         ObDateTime tmp = 0;
         obj.get_precise_datetime(tmp, is_add);
         snprintf(buffer, BUFFER_SIZE, "obj_type=precise_data_time value=%s is_add=%s", time2str(tmp), STR_BOOL(is_add));
       }
       break;
     case ObVarcharType:
       {
         ObString tmp;
         obj.get_varchar(tmp);
         if (NULL != tmp.ptr()
             && 0 != tmp.length()
             && !str_isprint(tmp.ptr(), tmp.length()))
         {
           char hex_buffer[BUFFER_SIZE] = {'\0'};
           common::hex_to_str(tmp.ptr(), tmp.length(), hex_buffer, BUFFER_SIZE);
           snprintf(buffer, BUFFER_SIZE, "obj_type=var_char value=[0x %s] value_ptr=%p value_length=%d",
                   hex_buffer, tmp.ptr(), tmp.length());
         }
         else
         {
           snprintf(buffer, BUFFER_SIZE, "obj_type=var_char value=[%.*s] value_ptr=%p value_length=%d",
                   tmp.length(), tmp.ptr(), tmp.ptr(), tmp.length());
         }
       }
       break;
     case ObSeqType:
       snprintf(buffer, BUFFER_SIZE, "obj_type=seq");
       break;
     case ObCreateTimeType:
       {
         ObCreateTime tmp = 0;
         obj.get_createtime(tmp);
         snprintf(buffer, BUFFER_SIZE, "obj_type=create_time value=%s", time2str(tmp));
       }
       break;
     case ObModifyTimeType:
       {
         ObModifyTime tmp = 0;
         obj.get_modifytime(tmp);
         snprintf(buffer, BUFFER_SIZE, "obj_type=modify_time value=%s", time2str(tmp));
       }
       break;
     case ObExtendType:
       {
         int64_t tmp = 0;
         obj.get_ext(tmp);
         snprintf(buffer, BUFFER_SIZE, "obj_type=extend value=%ld", tmp);
       }
       break;
     default:
       break;
   }
   return buffer;
 }