Ejemplo n.º 1
0
    int load_string(tbsys::CConfig& config, char* dest, const int32_t size,
        const char* section, const char* name, bool not_null)
    {
      int ret = OB_SUCCESS;
      if (NULL == dest || 0 >= size || NULL == section || NULL == name)
      {
        ret = OB_ERROR;
      }

      const char* value = NULL;
      if (OB_SUCCESS == ret)
      {
        value = config.getString(section, name);
        if (not_null && (NULL == value || 0 >= strlen(value)))
        {
          TBSYS_LOG(ERROR, "%s.%s has not been set.", section, name);
          ret = OB_ERROR;
        }
      }

      if (OB_SUCCESS == ret && NULL != value)
      {
        if ((int32_t)strlen(value) >= size)
        {
          TBSYS_LOG(ERROR, "%s.%s too long, length (%d) > %d",
              section, name, (int32_t)strlen(value), size);
          ret = OB_SIZE_OVERFLOW;
        }
        else
        {
          memset(dest, 0, size);
          strncpy(dest, value, strlen(value));
        }
      }

      return ret;
    }
Ejemplo n.º 2
0
    int ObMergeServerParams::load_string(tbsys::CConfig & conf, char* dest, const int32_t size,
      const char* section, const char* name, bool require)
    {
      int ret = OB_SUCCESS;
      if (NULL == dest || 0 >= size || NULL == section || NULL == name)
      {
        ret = OB_ERROR;
      }

      const char* value = NULL;
      if (OB_SUCCESS == ret)
      {
        value = conf.getString(section, name);
        if (require && (NULL == value || 0 >= strlen(value)))
        {
          TBSYS_LOG(ERROR, "%s.%s has not been set.", section, name);
          ret = OB_ERROR;
        }
      }

      if (OB_SUCCESS == ret && NULL != value)
      {
        if ((int32_t)strlen(value) >= size)
        {
          TBSYS_LOG(ERROR, "%s.%s too long, length (%ld) > %d",
            section, name, strlen(value), size);
          ret = OB_SIZE_OVERFLOW;
        }
        else
        {
          strncpy(dest, value, strlen(value));
        }
      }

      return ret;
    }
Ejemplo n.º 3
0
    int ObMergeServerParams::load_from_config(tbsys::CConfig & conf)
    {
      int ret = OB_SUCCESS;

      ret = load_string(conf, root_server_ip_, OB_MAX_IP_SIZE, OBMS_RS_SECTION, OBMS_VIP);
      if (ret == OB_SUCCESS)
      {
        ret = load_string(conf, dev_name_, OB_MAX_IP_SIZE, OBMS_MS_SECTION, OBMS_DEVNAME);
      }

      if (ret == OB_SUCCESS)
      {
        server_listen_port_ = conf.getInt(OBMS_MS_SECTION, OBMS_PORT, 0);
        if (server_listen_port_ <= 0)
        {
          TBSYS_LOG(ERROR, "mergeserver listen port must > 0, got (%d)", server_listen_port_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        root_server_port_ = conf.getInt(OBMS_RS_SECTION, OBMS_PORT, 0);
        if (root_server_port_ <= 0)
        {
          TBSYS_LOG(ERROR, "root server's port must > 0, got (%d)", root_server_port_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        task_queue_size_ = conf.getInt(OBMS_MS_SECTION, OBMS_TASK_QUEUE_SIZE, 1000);
        if (task_queue_size_ <= 0)
        {
          TBSYS_LOG(ERROR, "task queue size must > 0, got (%d)", task_queue_size_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        task_thread_count_ = conf.getInt(OBMS_MS_SECTION, OBMS_TASK_THREAD_COUNT, 20);
        if (task_thread_count_ <= 0)
        {
          TBSYS_LOG(ERROR, "task thread count must > 0, got (%d)", task_thread_count_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        task_left_time_ = conf.getInt(OBMS_MS_SECTION, OBMS_TASK_LEFT_TIME, 100 * 1000);
        if (task_left_time_ < 0)
        {
          TBSYS_LOG(ERROR, "task left time must >= 0, got (%ld)", task_left_time_);
          ret = OB_INVALID_ARGUMENT;
        }
        // log interval count
        log_interval_count_ = conf.getInt(OBMS_MS_SECTION, OBMS_LOG_INTERVAL_COUNT, 100);
      }

      if (ret == OB_SUCCESS)
      {
        network_time_out_ = conf.getInt(OBMS_MS_SECTION, OBMS_NETWORK_TIMEOUT, 2000000);
        if (network_time_out_ <= 0)
        {
          TBSYS_LOG(ERROR, "network timeout must > 0, got (%ld)", network_time_out_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        ups_blacklist_timeout_ = conf.getInt(OBMS_MS_SECTION, OBMS_BLACKLIST_TIMEOUT, 60 * 1000 * 1000L);
        if (ups_blacklist_timeout_ <= 0)
        {
          TBSYS_LOG(ERROR, "ups in blacklist timeout must > 0, got (%ld)", ups_blacklist_timeout_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        ups_fail_count_ = conf.getInt(OBMS_MS_SECTION, OBMS_BLACKLIST_FAIL_COUNT, 100);
        if (ups_fail_count_ <= 0)
        {
          TBSYS_LOG(ERROR, "ups fail count into blacklist must > 0, got (%ld)", ups_fail_count_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        fetch_ups_interval_ = conf.getInt(OBMS_MS_SECTION, OBMS_UPSLIST_INTERVAL, 60 * 1000 * 1000L);
        if (fetch_ups_interval_<= 0)
        {
          TBSYS_LOG(ERROR, "fetch ups list interval time must > 0, got (%ld)", fetch_ups_interval_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        frozen_version_timeout_ = conf.getInt(OBMS_MS_SECTION, OBMS_UPSVERION_TIMEOT, 600 * 1000 * 1000L);
        if (frozen_version_timeout_ <= 0)
        {
          TBSYS_LOG(ERROR, "ups frozen version cache tiemout must > 0, got (%ld)", frozen_version_timeout_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        check_lease_interval_ = conf.getInt(OBMS_MS_SECTION, OBMS_LEASE_INTERVAL, 6 * 1000 * 1000L);
        if (check_lease_interval_ <= 0)
        {
          TBSYS_LOG(ERROR, "check lease interval time must > 0, got (%ld)", check_lease_interval_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        monitor_interval_ = conf.getInt(OBMS_MS_SECTION, OBMS_MONITOR_INTERVAL, 600 * 1000 * 1000L);
        if (monitor_interval_ <= 0)
        {
          TBSYS_LOG(ERROR, "monitor interval time must > 0, got (%ld)", monitor_interval_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        retry_times_ = conf.getInt(OBMS_MS_SECTION, OBMS_RETRY_TIMES, 3);
        if (retry_times_ < 0)
        {
          TBSYS_LOG(ERROR, "retry_times must >= 0, got (%d)", retry_times_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (OB_SUCCESS == ret)
      {
        location_cache_timeout_ = conf.getInt(OBMS_MS_SECTION, OBMS_LOCATION_CACHE_TIMEOUT, 1000 * 1000 * 600L);
        if (location_cache_timeout_ <= 0)
        {
          TBSYS_LOG(ERROR, "tablet location cache timeout must > 0, got (%ld)", location_cache_timeout_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (OB_SUCCESS == ret)
      {
        location_cache_size_ = conf.getInt(OBMS_MS_SECTION, OBMS_LOCATION_CACHE_SIZE);
        if (location_cache_size_ <= 0)
        {
          TBSYS_LOG(ERROR, "tablet location cache size should great than 0 got (%d)",
            location_cache_size_);
          ret = OB_INVALID_ARGUMENT;
        }
        else
        {
          location_cache_size_ *= 1024*1024;
        }
      }

      if (ret == OB_SUCCESS)
      {
        intermediate_buffer_size_ = conf.getInt(OBMS_MS_SECTION, OBMS_INTERMEDIATE_BUFFER_SIZE, 24);
        if (intermediate_buffer_size_ <= 0)
        {
          TBSYS_LOG(ERROR, "intermediate_buffer_size_ must > 0, got (%ld)", intermediate_buffer_size_);
          ret = OB_INVALID_ARGUMENT;
        }
        else
        {
          intermediate_buffer_size_ *= 1024*1024;
        }
      }

      if (OB_SUCCESS == ret)
      {
        max_parellel_count_ = conf.getInt(OBMS_MS_SECTION, OBMS_MAX_PARELLEL_COUNT, 16);
        if (max_parellel_count_ <= 0)
        {
          TBSYS_LOG(ERROR, "max_parellel_count_ must > 0, got (%ld)", max_parellel_count_);
          ret = OB_INVALID_ARGUMENT;
        }
      }
      if (OB_SUCCESS == ret)
      {
        max_get_rows_per_subreq_ = conf.getInt(OBMS_MS_SECTION, OBMS_MAX_GET_ROWS_PER_SUBREQ, 20);
        if (max_get_rows_per_subreq_ < 0)
        {
          TBSYS_LOG(ERROR, "max_get_rows_per_subreq_ must > 0, got (%ld)", max_get_rows_per_subreq_);
          ret = OB_INVALID_ARGUMENT;
        }
      }
      if (OB_SUCCESS == ret)
      {
        slow_query_threshold_= conf.getInt(OBMS_MS_SECTION, OBMS_SLOW_QUERY_THRESHOLD, 100000);
        if (slow_query_threshold_ <= 0)
        {
          TBSYS_LOG(ERROR, "slow_query_threshold must > 0, got (%ld)", slow_query_threshold_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (OB_SUCCESS == ret)
      {
        max_req_process_time_ = conf.getInt(OBMS_MS_SECTION, OBMS_MAX_REQ_PROCESS_TIME, 1500000);
        if (max_req_process_time_ <= 0)
        {
          TBSYS_LOG(ERROR, "max_req_process_time_ must > 0, got (%ld)", max_req_process_time_);
          ret = OB_INVALID_ARGUMENT;
        }
      }
      if (OB_SUCCESS == ret)
      {
        int64_t percent =  conf.getInt(OBMS_MS_SECTION, OBMS_MAX_CS_TIMEOUT_PERCENT, 70);
        if (percent <= 0 || percent > 100)
        {
          TBSYS_LOG(ERROR, "max_cs_time_percent must be in  (0, 100], but here , it is %ld", percent);
          ret = OB_INVALID_ARGUMENT;
        }
        else
        {
          max_cs_timeout_percent_ = (static_cast<double>(percent) / 100.0);
        }
      }

      if (ret == OB_SUCCESS)
      {
        support_session_next_ = conf.getInt(OBMS_MS_SECTION, OBMS_SUPPORT_SESSION_NEXT, 0);
        if ((support_session_next_!= 0) && (support_session_next_ != 1))
        {
          TBSYS_LOG(ERROR, "supoort session next must 0 or 1 it's [%d]", support_session_next_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        allow_return_uncomplete_result_ = conf.getInt(OBMS_MS_SECTION, OBMS_ALLOW_RETURN_UNCOMPLETE_RESULT, 0);
        if ((allow_return_uncomplete_result_ != 0) && (allow_return_uncomplete_result_ != 1))
        {
          TBSYS_LOG(ERROR, "allow_return_uncomplete_result must 0 or 1 it's [%d]", allow_return_uncomplete_result_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        memory_size_limit_ = conf.getInt(OBMS_MS_SECTION, OBMS_MEMORY_SIZE_LIMIT_PERCENT, 15);
        if (memory_size_limit_ < OB_MS_MIN_MEMORY_SIZE_LIMIT
          || OB_MS_MAX_MEMORY_SIZE_LIMIT < memory_size_limit_)
        {
          TBSYS_LOG(ERROR, "memory_size_limit_percent between [%ld,%ld], got (%ld)", OB_MS_MIN_MEMORY_SIZE_LIMIT,
            OB_MS_MAX_MEMORY_SIZE_LIMIT, memory_size_limit_);
          ret = OB_INVALID_ARGUMENT;
        }
        else
        {
          memory_size_limit_ = memory_size_limit_*sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGE_SIZE)/100;
          ob_set_memory_size_limit(memory_size_limit_);
          TBSYS_LOG(DEBUG, "set memory size limit [limit:%ld]", memory_size_limit_);
        }
      }

      if (ret == OB_SUCCESS)
      {
        query_cache_size_ = conf.getInt(OBMS_MS_SECTION, OBMS_QUERY_CACHE_SIZE, 0);
        if (query_cache_size_ < 0)
        {
          TBSYS_LOG(ERROR, "query_cache_size_ must >= 0, got (%ld)", query_cache_size_);
          ret = OB_INVALID_ARGUMENT;
        }
        else
        {
          query_cache_size_ *= 1024*1024;
        }
      }

      if (ret == OB_SUCCESS)
      {
        min_drop_error_count_ = conf.getInt(OBMS_MS_SECTION, OBMS_MIN_DROP_ERROR_COUNT, 1);
        if (min_drop_error_count_ <= 0)
        {
          TBSYS_LOG(ERROR, "min drop packet count for error log must > 0, got (%ld)", min_drop_error_count_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        max_access_lock_count_ = conf.getInt(OBMS_MS_SECTION, OBMS_MAX_ACCESS_LOCK_COUNT, 10);
        if (max_access_lock_count_ <= 0)
        {
          TBSYS_LOG(ERROR, "max access root server lock count must > 0, got (%d)", max_access_lock_count_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        reserve_get_param_count_ = conf.getInt(OBMS_MS_SECTION, OBMS_RESERVE_GET_PARAM_COUNT, 5);
        if (reserve_get_param_count_ < 0)
        {
          TBSYS_LOG(ERROR, "reserve get param count must >= 0, got (%d)", reserve_get_param_count_);
          ret = OB_INVALID_ARGUMENT;
        }
      }

      if (ret == OB_SUCCESS)
      {
        // default not open
        get_request_factor_ = conf.getInt(OBMS_MS_SECTION, OBMS_GET_REQUEST_FACTOR, 1);
        scan_request_factor_ = conf.getInt(OBMS_MS_SECTION, OBMS_SCAN_REQUEST_FACTOR, 2);
      }
      return ret;
    }