示例#1
0
void
cut_setup(void)
{
  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);
  database = NULL;

  context2 = g_new0(grn_ctx, 1);
  grn_ctx_init(context2, 0);
  database2 = NULL;
}
void
test_read_write(gconstpointer *data)
{
  gint i;
  const gchar *key;
  grn_ctx *context;
  grn_pat *trie;
  const gchar *path;
  const gchar *value_string;
  gint process_number = 0;
  const gchar *process_number_string;
  void *value;
  int added;
  grn_id id = GRN_ID_NIL;
  grn_rc rc;

  i = GPOINTER_TO_INT(data);
  process_number_string = g_getenv(GRN_TEST_ENV_PROCESS_NUMBER);
  if (process_number_string)
    process_number = atoi(process_number_string);

  key = cut_take_printf("key: %d (%d:%d)", i, process_number, N_THREADS);

  rc = grn_ctx_init(contexts[i], GRN_CTX_USE_QL);
  cut_set_message("context: %d (%d)", i, process_number);
  grn_test_assert(rc);
  context = contexts[i];

  path = g_getenv(GRN_TEST_ENV_PATRICIA_TRIE_PATH);
  cut_assert_not_null(path);
  tries[i] = grn_pat_open(context, path);
  cut_assert_not_null(tries[i], "patricia trie: %d (%d)", i, process_number);
  trie = tries[i];

  cut_set_message("lookup - fail: %s (%d:%d)", key, i, process_number);
  grn_test_assert_nil(grn_pat_get(context, trie, key, strlen(key), &value));

  value_string = cut_take_printf("value: [%s] (%d:%d)", key, i, process_number);
  rc = grn_io_lock(context, trie->io, -1);
  if (rc != GRN_SUCCESS)
    grn_test_assert(rc);
  added = 0;
  id = grn_pat_add(context, trie, key, strlen(key), &value, &added);
  grn_io_unlock(trie->io);
  grn_test_assert_not_nil(id);
  cut_assert_equal_uint(1, added);
  strcpy(value, value_string);

  value = NULL;
  id = grn_pat_get(context, trie, key, strlen(key), &value);
  cut_set_message("lookup - success: %s (%d:%d)", key, i, process_number);
  grn_test_assert_not_nil(id);
  cut_assert_equal_string(value_string, value);

  tries[i] = NULL;
  grn_test_assert(grn_pat_close(context, trie));

  contexts[i] = NULL;
  grn_test_assert(grn_ctx_fin(context));
}
示例#3
0
void
cut_setup(void)
{
  const gchar *database_path;

  cut_set_fixture_data_dir(grn_test_get_base_dir(),
                           "fixtures",
                           "story",
                           "taiyaki",
                           NULL);

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);

  assert_send_commands(cut_get_fixture_data_string("ddl.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("areas.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("categories.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("shops.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("synonyms.grn", NULL));
}
示例#4
0
文件: index.c 项目: ikdttr/groonga
int
main(int argc, char **argv)
{
  int r = 0;
  grn_ctx ctx;
  grn_index *index;
  if (argc < 2) {
    fprintf(stderr, "usage: %s db_pathname [target_dir]\n", argv[0]);
    return -1;
  }
  if (grn_init()) {
    fprintf(stderr, "grn_init() failed\n");
    return -1;
  }
  if (grn_ctx_init(&ctx, 0)) {
    fprintf(stderr, "grn_ctx_init() failed\n");
    return -1;
  }
  if (argc > 2) {
    index = grn_index_create(&ctx, argv[1]);
    do_index(&ctx, index, argv[2]);
  } else {
    index = grn_index_open(&ctx, argv[1]);
    do_search(&ctx, index);
  }
  if (index) { grn_index_close(&ctx, index); }
  grn_ctx_fin(&ctx);
  grn_fin();
  return r;
}
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;
}
void
cut_setup(void)
{
  const gchar *database_path;

  cut_set_fixture_data_dir(grn_test_get_base_dir(),
                           "fixtures",
                           "geo",
                           NULL);

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);

  load_data();

  points = get("Points");
  short_degree_column = get("Points.short_degree");
  location_index_column = get("Locations.point");

  result = grn_table_create(context,
                            NULL, 0,
                            NULL,
                            GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
                            points, NULL);
}
示例#7
0
void
cut_setup(void)
{
  const gchar *database_path;

  cut_set_fixture_data_dir(grn_test_get_base_dir(),
                           "fixtures",
                           "story",
                           "taiyaki",
                           NULL);

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);

  setup_values();
  load_data();

  shops = get("Shops");
  location_index = get("Locations.shop");

  result = grn_table_create(context,
                            NULL, 0,
                            NULL,
                            GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
                            shops, NULL);
}
示例#8
0
static gboolean
run_test(const gchar **test_case_names, const grn_test_data *data)
{
  const gchar *type_name, *table_name;
  gchar *path;

  grn_test_assert(grn_ctx_init(context, GRN_CTX_USE_QL));

  GRN_CTX_SET_ENCODING(context, GRN_ENC_UTF8);

  type_name = "name";
  type = grn_type_create(context, type_name, strlen(type_name),
                         GRN_OBJ_KEY_UINT, sizeof(grn_id));

  path = g_build_filename(base_dir, "table", NULL);
  g_setenv(GRN_TEST_ENV_TABLE_PATH, path, TRUE);

  table_name = cut_take_printf("%s: performance-read-write", data->type_name);
  g_setenv(GRN_TEST_ENV_TABLE_TYPE, data->type_name, TRUE);
  table = grn_table_create(context,
                           table_name, strlen(table_name),
                           path, GRN_OBJ_PERSISTENT | data->flags,
                           type, NULL);
  g_free(path);
  cut_assert_not_null(table);

  return run(test_case_names, data);
}
示例#9
0
void
test_read_write(gconstpointer *data)
{
  gint i, key;
  int added;
  grn_ctx *context;
  grn_hash *hash;
  const gchar *path;
  const gchar *value_string;
  gint process_number = 0;
  const gchar *process_number_string;
  void *value;
  grn_id id = GRN_ID_NIL;
  grn_rc rc;

  i = GPOINTER_TO_INT(data);
  process_number_string = g_getenv(GRN_TEST_ENV_PROCESS_NUMBER);
  if (process_number_string)
    process_number = atoi(process_number_string);

  key = i + process_number * N_THREADS;

  rc = grn_ctx_init(contexts[i], GRN_CTX_USE_QL);
  grn_test_assert(rc, cut_message("context: %d (%d)", i, process_number));
  context = contexts[i];

  path = g_getenv(GRN_TEST_ENV_HASH_PATH);
  cut_assert_not_null(path);
  hashes[i] = grn_hash_open(context, path);
  cut_assert_not_null(hashes[i],
                      cut_message("hash: %d (%d)", i, process_number));
  hash = hashes[i];

  grn_test_assert_nil(
    grn_hash_get(context, hash, &key, sizeof(key), &value),
    cut_message("lookup - fail: %d (%d:%d)", key, i, process_number));

  value_string = cut_take_printf("value: %d (%d:%d)", key, i, process_number);
  rc = grn_io_lock(context, hash->io, -1);
  if (rc != GRN_SUCCESS)
    grn_test_assert(rc);
  id = grn_hash_add(context, hash, &key, sizeof(key), &value, &added);
  grn_io_unlock(hash->io);
  grn_test_assert_not_nil(id);
  cut_assert_equal_int(1, added);
  strcpy(value, value_string);

  value = NULL;
  id = grn_hash_get(context, hash, &key, sizeof(key), &value);
  grn_test_assert_not_nil(
    id,
    cut_message("lookup - success: %d (%d:%d)", key, i, process_number));
  cut_assert_equal_string(value_string, value);

  hashes[i] = NULL;
  grn_test_assert(grn_hash_close(context, hash));

  contexts[i] = NULL;
  grn_test_assert(grn_ctx_fin(context));
}
示例#10
0
void
cut_setup(void)
{
  logger = setup_grn_logger();
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, NULL, NULL);
}
示例#11
0
int
main(int argc, char **argv)
{
  int exit_code = EXIT_SUCCESS;

  if (argc != 3) {
    fprintf(stderr, "Usage: %s DB_PATH RUBY_SCRIPT_PATH\n", argv[0]);
    return EXIT_FAILURE;
  }

  if (grn_init() != GRN_SUCCESS) {
    return EXIT_FAILURE;
  }

  {
    grn_ctx ctx;
    grn_ctx_init(&ctx, 0);
    exit_code = run(&ctx, argv[1], argv[2]);
    grn_ctx_fin(&ctx);
  }

  grn_fin();

  return exit_code;
}
示例#12
0
void
setup (void)
{
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, NULL, NULL);
  GRN_VOID_INIT(&buffer);
}
示例#13
0
void
test_read_write(gconstpointer *data)
{
  gint i;
  int added;
  grn_ctx *context;
  grn_obj *table;
  const gchar *path;
  const gchar *value_string;
  gint process_number = 0;
  const gchar *process_number_string;
  const gchar table_name[] = "performance-read-write";
  grn_obj value;
  grn_obj *retrieved_value;
  grn_id id;
  grn_rc rc;

  i = GPOINTER_TO_INT(data);
  process_number_string = g_getenv(GRN_TEST_ENV_PROCESS_NUMBER);
  if (process_number_string)
    process_number = atoi(process_number_string);

  rc = grn_ctx_init(&contexts[i], GRN_CTX_USE_QL);
  grn_test_assert(rc, cut_set_message("context: %d (%d)", i, process_number));
  context = &contexts[i];

  path = g_getenv(GRN_TEST_ENV_TABLE_PATH);
  cut_assert_not_null(path);
  tables[i] = grn_table_open(context, table_name, strlen(table_name),
                             path);
  cut_assert_not_null(tables[i],
                      cut_message("table: %d (%d)", i, process_number));
  table = tables[i];

  grn_test_assert_nil(grn_table_get(context, table, &i, sizeof(grn_id)),
                      cut_message("lookup - fail: (%d:%d)", i, process_number));

  value_string = cut_take_printf("value: (%d:%d)", i, process_number);
  id = grn_table_add(context, table, &i, sizeof(grn_id), &added);
  grn_test_assert_not_nil(id);
  cut_assert_equal_int(1, added);

  GRN_TEXT_INIT(&value, GRN_OBJ_DO_SHALLOW_COPY);
  GRN_TEXT_SET_REF(&value, value_string, strlen(value_string));
  grn_obj_set_value(context, table, id, &value, GRN_OBJ_SET);

  retrieved_value = grn_obj_get_value(context, table, id, NULL);
  grn_test_assert_not_nil(
    id,
    cut_message("lookup - success: (%d:%d)", i, process_number));
  GRN_TEXT_PUTC(context, retrieved_value, '\0');
  cut_assert_equal_string(value_string, GRN_BULK_HEAD(retrieved_value));

  tables[i] = NULL;
  grn_test_assert(grn_obj_close(context, table));

  //  contexts[i] = NULL;
  grn_test_assert(grn_ctx_fin(context));
}
示例#14
0
 void cut_startup()
 {
   ctx = (grn_ctx *)malloc(sizeof(grn_ctx));
   grn_init();
   grn_ctx_init(ctx, 0);
   db = grn_db_create(ctx, NULL, NULL);
   grn_ctx_use(ctx, db);
 }
示例#15
0
void
cut_setup(void)
{
  logger = setup_grn_logger();
  grn_ctx_init(&context, 0);
  GRN_VOID_INIT(&src);
  GRN_VOID_INIT(&dest);
}
示例#16
0
void
cut_setup(void)
{
  cut_remove_path(tmp_directory, NULL);
  g_mkdir_with_parents(tmp_directory, 0700);
  path = g_build_filename(tmp_directory, "text-expr", NULL);
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, path, NULL);
}
示例#17
0
static void
bench_setup_common(gpointer user_data)
{
  BenchmarkData *data = user_data;

  grn_ctx_init(data->context, GRN_CTX_USE_QL);
  data->database = grn_db_create(data->context, NULL, NULL);
  data->expression = grn_expr_create(data->context, NULL, 0);
}
示例#18
0
static void
bench_startup(BenchmarkData *data)
{
  if (data->use_mruby) {
    g_setenv("GRN_MRUBY_ENABLED", "yes", TRUE);
  } else {
    g_setenv("GRN_MRUBY_ENABLED", "no", TRUE);
  }
  grn_ctx_init(&(data->context), 0);
  setup_database(data);
}
示例#19
0
void
cut_setup(void)
{
  logger = setup_grn_logger();
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, NULL, NULL);

  create_bookmarks_table();
  add_count_column_to_bookmarks_table();
  add_groonga_bookmark();
}
示例#20
0
void
cut_setup(void)
{
  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);
  ja = grn_ja_create(context, NULL, 65536, 0);
  vector = grn_obj_open(context, GRN_BULK, GRN_OBJ_VECTOR, GRN_DB_VOID);
}
void
cut_setup(void)
{
  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);
}
示例#22
0
void
cut_setup(void)
{
  context = NULL;

  logger = setup_grn_logger();

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database = grn_db_create(context, NULL, NULL);
}
示例#23
0
void
cut_setup(void)
{
    gchar *table_path, *vgram_path;
    const gchar *type_name, *table_name;

    cut_set_fixture_data_dir(grn_test_get_base_dir(),
                             "fixtures",
                             "inverted-index",
                             NULL);

    logger = setup_grn_logger();

    expected_messages = NULL;
    record_ids = NULL;

    remove_tmp_directory();
    g_mkdir_with_parents(tmp_directory, 0700);
    path = g_build_filename(tmp_directory, "inverted-index", NULL);

    context = g_new0(grn_ctx, 1);
    grn_test_assert(grn_ctx_init(context, GRN_CTX_USE_QL));
    GRN_CTX_SET_ENCODING(context, GRN_ENC_UTF8);

    db = grn_db_create(context, NULL, NULL);
    grn_ctx_use(context, db);

    type_name = "name";
    type = grn_type_create(context, type_name, strlen(type_name),
                           GRN_OBJ_KEY_VAR_SIZE, TYPE_SIZE);

    table_name = "lexicon";
    table_path = g_build_filename(tmp_directory, "lexicon-table", NULL);
    lexicon = grn_table_create(context,
                               table_name, strlen(table_name),
                               table_path,
                               GRN_OBJ_PERSISTENT | GRN_OBJ_TABLE_PAT_KEY,
                               type, NULL);

    grn_obj_set_info(context, lexicon, GRN_INFO_DEFAULT_TOKENIZER,
                     grn_ctx_at(context, GRN_DB_BIGRAM));

    g_free(table_path);

    vgram_path = g_build_filename(tmp_directory, "vgram", NULL);
    /*
      vgram = grn_vgram_create(vgram_path);
    */
    g_free(vgram_path);

    inverted_index = NULL;
}
示例#24
0
grn_ctx *
grn_ctx_open(int flags)
{
  grn_ctx *ctx = GRN_GMALLOCN(grn_ctx, 1);
  if (ctx) {
    grn_ctx_init(ctx, flags|GRN_CTX_ALLOCATED);
    if (ERRP(ctx, GRN_ERROR)) {
      GRN_GFREE(ctx);
      ctx = NULL;
    }
  }
  return ctx;
}
示例#25
0
MRN_API my_bool mroonga_escape_init(UDF_INIT *initid, UDF_ARGS *args,
                                    char *message)
{
  EscapeInfo *info = NULL;

  initid->ptr = NULL;
  if (!(1 <= args->arg_count && args->arg_count <= 2)) {
    sprintf(message,
            "mroonga_escape(): Incorrect number of arguments: %u for 1..2",
            args->arg_count);
    goto error;
  }
  if (args->arg_type[0] != STRING_RESULT) {
    strcpy(message,
           "mroonga_escape(): The 1st argument must be query as string");
    goto error;
  }
  if (args->arg_count == 2) {
    if (args->arg_type[1] != STRING_RESULT) {
      strcpy(message,
             "mroonga_escape(): "
             "The 2st argument must be escape target characters as string");
      goto error;
    }
  }

  initid->maybe_null = 1;
  initid->const_item = 0;

  info = (EscapeInfo *)mrn_my_malloc(sizeof(EscapeInfo),
                                     MYF(MY_WME | MY_ZEROFILL));
  if (!info) {
    strcpy(message, "mroonga_escape(): out of memory");
    goto error;
  }

  grn_ctx_init(&(info->ctx), 0);
  GRN_TEXT_INIT(&(info->target_characters), 0);
  GRN_TEXT_INIT(&(info->escaped_query), 0);

  initid->ptr = (char *)info;

  return FALSE;

error:
  if (info) {
    grn_ctx_fin(&(info->ctx));
    my_free(info);
  }
  return TRUE;
}
示例#26
0
文件: server.c 项目: kou/hog
void* server(void *arg)
{
    int loop = 1;
    char num_handlers = sizeof(cmd_handlers)/sizeof(cmd_handlers[0]);
    server_t *s = (server_t*)arg;
    fprintf(stdout, "connection opening: %d\n", s->socket);
    hog_t *hog = s->hog;
    grn_ctx ctx;
    grn_ctx_init(&ctx, 0);
    // open db
    grn_obj *db = grn_db_open(&ctx, hog->db_path);
    // setup socket
    struct timeval to;
    to.tv_sec = 10;
    to.tv_usec = 0;
    //setsockopt(s->socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&to, sizeof(to));
    setsockopt(s->socket, SOL_SOCKET, SO_SNDTIMEO, (char*)&to, sizeof(to));
    // send the command list
    if(submit(s->socket, &num_handlers, 1) != 0){
        fprintf(stderr, "Failed to send num handlers\n");
    }
    for(char i = 0; i < num_handlers; ++i){
        const char *name = cmd_handlers[i].name;
        if(submit_chunk(s->socket, name) != 0){
            fprintf(stderr, "Failed to send cmd (%d) %s\n", i, name);
        }
    }
    while(loop){
        unsigned char cmd;
        if(receive(s->socket, &cmd, 1) != 0){
            switch(errno){
            case 0: case EBADF: case ENOENT: case EAGAIN: break;
            case ETIMEDOUT: continue;
            default:
                fprintf(stderr, "Failed to recv cmd: %s\n", strerror(errno));
                break;
            }
            loop = 0;
            break;
        }
        if(cmd < num_handlers) (cmd_handlers[cmd].handler)(s, &ctx);
        else fprintf(stderr, "Invalid cmd: %d\n", cmd);
    }
cleanup:
    fprintf(stdout, "connection closing: %d\n", s->socket);
    GRN_OBJ_FIN(&ctx, db);
    grn_ctx_fin(&ctx);
    close(s->socket);
    free(s);
    return NULL;
}
示例#27
0
grn_rc
grn_plugins_init(void)
{
  CRITICAL_SECTION_INIT(grn_plugins_lock);
  grn_ctx_init(&grn_plugins_ctx, 0);
  grn_plugins = grn_hash_create(&grn_plugins_ctx, NULL,
                                PATH_MAX, sizeof(grn_plugin *),
                                GRN_OBJ_KEY_VAR_SIZE);
  if (!grn_plugins) {
    grn_ctx_fin(&grn_plugins_ctx);
    return GRN_NO_MEMORY_AVAILABLE;
  }
  return GRN_SUCCESS;
}
示例#28
0
void
cut_setup(void)
{
    cut_remove_path(tmp_directory, NULL);
    g_mkdir_with_parents(tmp_directory, 0700);
    path = g_build_filename(tmp_directory, "text-expr", NULL);
    context = g_new0(grn_ctx, 1);
    grn_ctx_init(context, 0);
    database = grn_db_create(context, path, NULL);

    expr = NULL;

    GRN_TEXT_INIT(&textbuf, 0);
    GRN_UINT32_INIT(&intbuf, 0);
}
示例#29
0
void
cut_startup(void)
{
  int i;
  grn_init();
  for (i = 0; i < N_THREADS; i++) {
    grn_ctx *context;

    context = &contexts[i];
    grn_ctx_init(context, 0);
    // contexts[i] = NULL;
    // grn_ctx_fin(context);
    tables[i] = NULL;
  }
}
示例#30
0
void
cut_setup(void)
{
  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = NULL;
  logger = setup_grn_logger();

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database = grn_db_create(context,
                           cut_build_path(tmp_directory, "table.db", NULL),
                           NULL);
}