コード例 #1
0
static ngx_int_t
ngx_http_groonga_context_init(grn_ctx *context,
                              ngx_http_groonga_loc_conf_t *location_conf,
                              ngx_pool_t *pool,
                              ngx_log_t *log)
{
  ngx_int_t status;

  grn_ctx_init(context, GRN_NO_FLAGS);

  status = ngx_http_groonga_context_init_logger(context,
                                                location_conf,
                                                pool,
                                                log);
  if (status == NGX_ERROR) {
    grn_ctx_fin(context);
    return status;
  }

  status = ngx_http_groonga_context_init_query_logger(context,
                                                      location_conf,
                                                      pool,
                                                      log);
  if (status == NGX_ERROR) {
    grn_ctx_fin(context);
    return status;
  }

  if (location_conf->cache) {
    grn_cache_current_set(context, location_conf->cache);
  }

  return status;
}
コード例 #2
0
static void
ngx_http_groonga_close_database_callback(ngx_http_groonga_loc_conf_t *location_conf,
                                         void *user_data)
{
  ngx_http_groonga_database_callback_data_t *data = user_data;
  grn_ctx *context;

  context = &(location_conf->context);
  ngx_http_groonga_context_init_logger(context,
                                       location_conf,
                                       data->pool,
                                       data->log);
  ngx_http_groonga_context_init_query_logger(context,
                                             location_conf,
                                             data->pool,
                                             data->log);
  grn_cache_current_set(context, location_conf->cache);

  grn_obj_close(context, grn_ctx_db(context));
  ngx_http_groonga_context_log_error(data->log, context);

  grn_cache_current_set(context, NULL);
  grn_cache_close(context, location_conf->cache);

  grn_ctx_fin(context);
}
コード例 #3
0
static ngx_int_t
ngx_http_groonga_context_init(ngx_http_groonga_loc_conf_t *location_conf,
                              ngx_pool_t *pool,
                              ngx_log_t *log)
{
  ngx_int_t status;

  if (location_conf == ngx_http_groonga_current_location_conf) {
    return NGX_OK;
  }

  status = ngx_http_groonga_context_init_logger(location_conf,
                                                pool,
                                                log);
  if (status == NGX_ERROR) {
    return status;
  }

  status = ngx_http_groonga_context_init_query_logger(location_conf,
                                                      pool,
                                                      log);
  if (status == NGX_ERROR) {
    return status;
  }

  grn_ctx_use(context, location_conf->database);
  grn_cache_current_set(context, location_conf->cache);

  /* TODO: It doesn't work yet. We need to implement request timeout
   * handler. */
  if (location_conf->default_request_timeout_msec == NGX_CONF_UNSET_MSEC) {
    grn_set_default_request_timeout(0.0);
  } else {
    double timeout;
    timeout = location_conf->default_request_timeout_msec / 1000.0;
    grn_set_default_request_timeout(timeout);
  }

  ngx_http_groonga_current_location_conf = location_conf;

  return status;
}
コード例 #4
0
static void
ngx_http_groonga_open_database_callback(ngx_http_groonga_loc_conf_t *location_conf,
                                        void *user_data)
{
  ngx_http_groonga_database_callback_data_t *data = user_data;

  data->rc = ngx_http_groonga_context_init_logger(location_conf,
                                                  data->pool,
                                                  data->log);
  if (data->rc != NGX_OK) {
    return;
  }
  data->rc = ngx_http_groonga_context_init_query_logger(location_conf,
                                                        data->pool,
                                                        data->log);
  if (data->rc != NGX_OK) {
    return;
  }

  if (!location_conf->database_path.data) {
    ngx_log_error(NGX_LOG_EMERG, data->log, 0,
                  "%s: \"groonga_database\" must be specified in block at %s:%d",
                  location_conf->name,
                  location_conf->config_file,
                  location_conf->config_line);
    data->rc = NGX_ERROR;
    return;
  }

  if (!location_conf->database_path_cstr) {
    location_conf->database_path_cstr =
      ngx_str_null_terminate(data->pool, &(location_conf->database_path));
  }

  location_conf->database =
    grn_db_open(context, location_conf->database_path_cstr);
  if (context->rc != GRN_SUCCESS) {
    if (location_conf->database_auto_create) {
      ngx_http_groonga_create_database(location_conf, data);
    } else {
      ngx_log_error(NGX_LOG_EMERG, data->log, 0,
                    "failed to open Groonga database: %s",
                    context->errbuf);
      data->rc = NGX_ERROR;
    }
    if (data->rc != NGX_OK) {
      return;
    }
  }

  location_conf->cache = grn_cache_open(context);
  if (!location_conf->cache) {
    ngx_log_error(NGX_LOG_EMERG, data->log, 0,
                  "failed to open Groonga cache: %s",
                  context->errbuf);
    data->rc = NGX_ERROR;
    return;
  }

  if (location_conf->cache_limit != NGX_CONF_UNSET_SIZE) {
    grn_cache_set_max_n_entries(context,
                                location_conf->cache,
                                location_conf->cache_limit);
  }
}