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; }
void cut_shutdown() { grn_obj_unlink(ctx, db); grn_ctx_fin(ctx); grn_fin(); free(ctx); }
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; }
static void finish_groonga (VALUE data) { debug("finish\n"); grn_fin(); rb_grn_exited = GRN_TRUE; debug("finish: done\n"); }
void plugin_unload(void) { #define SYLPF_FUNC_NAME "plugin_unload" SYLPF_START_FUNC; grn_fin(); SYLPF_END_FUNC; #undef SYLPF_FUNC_NAME }
int main(int argc, gchar **argv) { grn_rc rc; BenchmarkData data; BenchReporter *reporter; gint n = 100; rc = grn_init(); if (rc != GRN_SUCCESS) { g_print("failed to initialize Groonga: <%d>: %s\n", rc, grn_get_global_error_message()); return EXIT_FAILURE; } bench_init(&argc, &argv); data.context = g_new(grn_ctx, 1); data.base_dir = g_build_filename(g_get_tmp_dir(), "groonga-bench", NULL); data.name = "table"; data.name_size = strlen(data.name); data.path = g_build_filename(data.base_dir, "table", NULL); data.flags = DEFAULT_FLAGS; data.key_type = NULL; data.value_size = DEFAULT_VALUE_SIZE; data.encoding = GRN_ENC_DEFAULT; reporter = bench_reporter_new(); bench_reporter_register(reporter, "normal (persistent)", n, bench_setup, bench_normal, bench_teardown, &data); bench_reporter_register(reporter, "factory (persistent)", n, bench_setup, bench_factory, bench_teardown, &data); bench_reporter_register(reporter, "normal (temporary)", n, bench_setup, bench_normal_temporary, bench_teardown, &data); bench_reporter_register(reporter, "factory (temporary)", n, bench_setup, bench_factory_temporary, bench_teardown, &data); bench_reporter_run(reporter); g_object_unref(reporter); bench_utils_remove_path_recursive_force(data.base_dir); g_free(data.path); g_free(data.base_dir); g_free(data.context); bench_quit(); grn_fin(); return EXIT_SUCCESS; }
int main(int argc, gchar **argv) { BenchmarkData data; BenchReporter *reporter; gint n = 1000; grn_init(); bench_init(&argc, &argv); data.report_result = g_getenv("GROONGA_BENCH_REPORT_RESULT") != NULL; data.context = g_new(grn_ctx, 1); { const gchar *groonga_bench_n; groonga_bench_n = g_getenv("GROONGA_BENCH_N"); if (groonga_bench_n) { n = atoi(groonga_bench_n); } } reporter = bench_reporter_new(); #define REGISTER(label, setup) \ bench_reporter_register(reporter, label, n, \ bench_setup_ ## setup, \ bench_geo_distance, \ bench_teardown, \ &data) REGISTER("rectangular (WGS84)", rectangular_wgs84); REGISTER("rectangular (TOKYO)", rectangular_tgs); REGISTER("spherical (WGS84)", spherical_wgs84); REGISTER("spherical (TOKYO)", spherical_tgs); REGISTER("hubeny (WGS84)", hubeny_wgs84); REGISTER("hubeny (TOKYO)", hubeny_tgs); #undef REGISTER bench_reporter_run(reporter); g_object_unref(reporter); g_free(data.context); bench_quit(); grn_fin(); return 0; }
static void ngx_http_groonga_exit_process(ngx_cycle_t *cycle) { ngx_http_conf_ctx_t *http_conf; ngx_http_groonga_database_callback_data_t data; http_conf = (ngx_http_conf_ctx_t *)ngx_get_conf(cycle->conf_ctx, ngx_http_module); data.log = cycle->log; data.pool = cycle->pool; ngx_http_groonga_each_loc_conf(http_conf, ngx_http_groonga_close_database_callback, &data); grn_fin(); return; }
void cut_shutdown(void) { int i; for (i = 0; i < N_THREADS; i++) { grn_ctx *context; context = &contexts[i]; if (context) { grn_obj *table; table = tables[i]; #if 0 if (table) grn_table_close(context, table); #endif grn_ctx_fin(context); } } grn_fin(); }
int main(int argc, char **argv) { int port_no = DEFAULT_PORT, daemon = 0; const char *max_threads_string = NULL, *port_string = NULL; const char *address; const char *send_endpoint = NULL, *recv_endpoint = NULL, *log_base_path = NULL; int n_processed_args, flags = RUN_MODE_ENABLE_MAX_FD_CHECK; run_mode mode = run_mode_none; if (!(default_max_threads = get_core_number())) { default_max_threads = DEFAULT_MAX_THREADS; } /* parse options */ { static grn_str_getopt_opt opts[] = { {'c', NULL, NULL, 0, getopt_op_none}, /* deprecated */ {'t', "n-threads", NULL, 0, getopt_op_none}, {'h', "help", NULL, run_mode_usage, getopt_op_update}, {'p', "port", NULL, 0, getopt_op_none}, {'\0', "bind-address", NULL, 0, getopt_op_none}, /* not supported yet */ {'s', "send-endpoint", NULL, 0, getopt_op_none}, {'r', "receive-endpoint", NULL, 0, getopt_op_none}, {'l', "log-base-path", NULL, 0, getopt_op_none}, {'d', "daemon", NULL, run_mode_daemon, getopt_op_update}, {'\0', "disable-max-fd-check", NULL, RUN_MODE_ENABLE_MAX_FD_CHECK, getopt_op_off}, {'\0', NULL, NULL, 0, 0} }; opts[0].arg = &max_threads_string; opts[1].arg = &max_threads_string; opts[3].arg = &port_string; opts[4].arg = &address; opts[5].arg = &send_endpoint; opts[6].arg = &recv_endpoint; opts[7].arg = &log_base_path; n_processed_args = grn_str_getopt(argc, argv, opts, &flags); } /* main */ mode = (flags & RUN_MODE_MASK); if (n_processed_args < 0 || (argc - n_processed_args) != 1 || mode == run_mode_error) { usage(stderr); return EXIT_FAILURE; } else if (mode == run_mode_usage) { usage(stdout); return EXIT_SUCCESS; } else { grn_ctx ctx; void *zmq_ctx; int max_threads; if (max_threads_string) { max_threads = atoi(max_threads_string); if (max_threads > MAX_THREADS) { print_error("too many threads. limit to %d.", MAX_THREADS); max_threads = MAX_THREADS; } } else { max_threads = default_max_threads; } if (port_string) { port_no = atoi(port_string); } if (flags & RUN_MODE_ENABLE_MAX_FD_CHECK) { /* check environment */ struct rlimit rlim; if (!getrlimit(RLIMIT_NOFILE, &rlim)) { if (rlim.rlim_max < MIN_MAX_FDS) { print_error("too small max fds. %d required.", MIN_MAX_FDS); return -1; } rlim.rlim_cur = rlim.rlim_cur; setrlimit(RLIMIT_NOFILE, &rlim); } } if (mode == run_mode_daemon) { daemonize(); } grn_init(); grn_ctx_init(&ctx, 0); if ((db = grn_db_open(&ctx, argv[n_processed_args]))) { if ((zmq_ctx = zmq_init(1))) { signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); signal(SIGQUIT, signal_handler); serve_threads(max_threads, port_no, argv[n_processed_args], zmq_ctx, send_endpoint, recv_endpoint, log_base_path); zmq_term(zmq_ctx); } else { print_error("cannot create zmq context."); } grn_obj_close(&ctx, db); } else { print_error("cannot open db."); } grn_ctx_fin(&ctx); grn_fin(); } return 0; }
int main(int argc, char **argv) { int r, op = 'p', method = 'c'; const char *path; if (argc < 2) { fprintf(stderr, "usage: kv dbpath [put|get] [col|table|hash|pat|ql] [value_size]\n"); return -1; } path = *argv[1] ? argv[1] : NULL; if (argc > 2) { op = *argv[2]; } if (argc > 3) { method = *argv[3]; } if (argc > 4) { value_size = atoi(argv[4]); } if (argc > 5) { nloops = atoi(argv[5]); } if (grn_init()) { fprintf(stderr, "grn_init() failed\n"); return -1; } if (grn_ctx_init(&ctx, (method == 'q' ? GRN_CTX_USE_QL|GRN_CTX_BATCH_MODE : 0))) { fprintf(stderr, "grn_ctx_init() failed\n"); return -1; } srand(0); if (method == 'h' || method == 'p') { switch (method) { case 'h' : r = (op == 'p') ? hash_put(path) : hash_get(path); break; case 'p' : r = (op == 'p') ? pat_put(path) : pat_get(path); break; default : r = -1; fprintf(stderr, "invalid method\n"); break; } } else { if (path) { db = grn_db_open(&ctx, path); } if (!db) { db = grn_db_create(&ctx, path, NULL); } if (!db) { fprintf(stderr, "db initialize failed\n"); return -1; } value_type = grn_type_create(&ctx, "<value_type>", 12, 0, value_size); switch (method) { case 'q' : r = (op == 'p') ? ql_put() : ql_get(); break; case 'c' : r = (op == 'p') ? column_put() : column_get(); break; case 't' : r = (op == 'p') ? table_put() : table_get(); //r = (op == 'p') ? table_put_allocate() : table_get(); //r = (op == 'p') ? table_put2() : table_get(); break; default : r = -1; fprintf(stderr, "invalid method\n"); break; } if (grn_obj_close(&ctx, db)) { fprintf(stderr, "grn_obj_close() failed\n"); return -1; } } if (grn_ctx_fin(&ctx)) { fprintf(stderr, "grn_ctx_fin() failed\n"); return -1; } if (grn_fin()) { fprintf(stderr, "grn_fin() failed\n"); return -1; } return r; }
void groonga_test_cooldown(void) { grn_fin(); }
int main(int argc, char **argv) { const char *db_path; const char *dataset_name; grn_ctx ctx_, *ctx; grn_obj *db; grn_bool success = GRN_TRUE; int parsed_argc, rest_argc; int flags = MODE_NONE; const char *default_tokenizer = NULL; static grn_str_getopt_opt opts[] = { {'\0', "default-tokenizer", NULL, 0, GETOPT_OP_NONE}, {'h', "help", NULL, MODE_USAGE, GETOPT_OP_UPDATE} }; opts[0].arg = &default_tokenizer; parsed_argc = grn_str_getopt(argc, argv, opts, &flags); if (parsed_argc < 0) { usage(stderr, argc, argv); return EXIT_FAILURE; } if (flags & MODE_USAGE) { usage(stdout, argc, argv); return EXIT_SUCCESS; } rest_argc = argc - parsed_argc; if (rest_argc != 2) { usage(stderr, argc, argv); return EXIT_FAILURE; } db_path = argv[parsed_argc]; dataset_name = argv[parsed_argc + 1]; grn_init(); ctx = &ctx_; grn_ctx_init(ctx, 0); db = grn_db_open(ctx, db_path); if (!db) { if (ctx->rc == GRN_NO_SUCH_FILE_OR_DIRECTORY) { db = grn_db_create(ctx, db_path, NULL); if (!db) { fprintf(stderr, "DB create failed (%s): %s\n", db_path, ctx->errbuf); } } else { fprintf(stderr, "DB open failed (%s): %s\n", db_path, ctx->errbuf); } } if (db) { grn_obj text; GRN_TEXT_INIT(&text, 0); #define SEND(string) send_command(ctx, &text, string, dataset_name) SEND("register suggest/suggest"); SEND("table_create event_type TABLE_HASH_KEY ShortText"); { grn_obj query; GRN_TEXT_INIT(&query, 0); GRN_TEXT_PUTS(ctx, &query, "table_create bigram TABLE_PAT_KEY ShortText " "--default_tokenizer "); if (default_tokenizer) { GRN_TEXT_PUTS(ctx, &query, default_tokenizer); } else { GRN_TEXT_PUTS(ctx, &query, DEFAULT_DEFAULT_TOKENIZER); } GRN_TEXT_PUTS(ctx, &query, " --normalizer NormalizerAuto"); GRN_TEXT_PUTC(ctx, &query, '\0'); SEND(GRN_TEXT_VALUE(&query)); GRN_OBJ_FIN(ctx, &query); } SEND("table_create kana TABLE_PAT_KEY ShortText " "--normalizer NormalizerAuto"); SEND("table_create item_${DATASET} TABLE_PAT_KEY " "ShortText --default_tokenizer TokenDelimit " "--normalizer NormalizerAuto"); SEND("column_create bigram item_${DATASET}_key " "COLUMN_INDEX|WITH_POSITION item_${DATASET} _key"); SEND("column_create item_${DATASET} kana COLUMN_VECTOR kana"); SEND("column_create kana item_${DATASET}_kana COLUMN_INDEX " "item_${DATASET} kana"); SEND("column_create item_${DATASET} freq COLUMN_SCALAR Int32"); SEND("column_create item_${DATASET} last COLUMN_SCALAR Time"); SEND("column_create item_${DATASET} boost COLUMN_SCALAR Int32"); SEND("column_create item_${DATASET} freq2 COLUMN_SCALAR Int32"); SEND("column_create item_${DATASET} buzz COLUMN_SCALAR Int32"); SEND("table_create pair_${DATASET} TABLE_HASH_KEY UInt64"); SEND("column_create pair_${DATASET} pre COLUMN_SCALAR item_${DATASET}"); SEND("column_create pair_${DATASET} post COLUMN_SCALAR item_${DATASET}"); SEND("column_create pair_${DATASET} freq0 COLUMN_SCALAR Int32"); SEND("column_create pair_${DATASET} freq1 COLUMN_SCALAR Int32"); SEND("column_create pair_${DATASET} freq2 COLUMN_SCALAR Int32"); SEND("column_create item_${DATASET} co COLUMN_INDEX pair_${DATASET} pre"); SEND("table_create sequence_${DATASET} TABLE_HASH_KEY ShortText"); SEND("table_create event_${DATASET} TABLE_NO_KEY"); SEND("column_create sequence_${DATASET} events " "COLUMN_VECTOR|RING_BUFFER event_${DATASET}"); SEND("column_create event_${DATASET} type COLUMN_SCALAR event_type"); SEND("column_create event_${DATASET} time COLUMN_SCALAR Time"); SEND("column_create event_${DATASET} item COLUMN_SCALAR item_${DATASET}"); SEND("column_create event_${DATASET} sequence COLUMN_SCALAR " "sequence_${DATASET}"); SEND("table_create configuration TABLE_HASH_KEY ShortText"); SEND("column_create configuration weight COLUMN_SCALAR UInt32"); SEND("load --table configuration"); SEND("["); SEND("{\"_key\": \"${DATASET}\", \"weight\": 1}"); SEND("]"); #undef SEND success = ctx->rc == GRN_SUCCESS; GRN_OBJ_FIN(ctx, &text); GRN_OBJ_FIN(ctx, db); } else { success = GRN_FALSE; } grn_ctx_fin(ctx); grn_fin(); return success ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, gchar **argv) { grn_rc rc; BenchReporter *reporter; gint n = 10; rc = grn_init(); if (rc != GRN_SUCCESS) { g_print("failed to initialize Groonga: <%d>: %s\n", rc, grn_get_global_error_message()); return EXIT_FAILURE; } g_print("Process %d times in each pattern\n", n); bench_init(&argc, &argv); reporter = bench_reporter_new(); { BenchmarkData data_small_with_mruby; BenchmarkData data_small_without_mruby; BenchmarkData data_medium_with_mruby; BenchmarkData data_medium_without_mruby; BenchmarkData data_large_with_mruby; BenchmarkData data_large_without_mruby; BenchmarkData data_very_large_with_mruby; BenchmarkData data_very_large_without_mruby; #define REGISTER(data, n_records_, min, max, use_mruby_) \ do { \ gchar *label; \ label = g_strdup_printf("(%6d, %6d] (%7d): %7s mruby", \ min, max, n_records_, \ use_mruby_ ? "with" : "without"); \ data.use_mruby = use_mruby_; \ data.n_records = n_records_; \ data.command = \ "select Entries --cache no " \ "--filter 'rank > " #min " && rank <= " #max "'"; \ bench_startup(&data); \ bench_reporter_register(reporter, label, \ n, \ NULL, \ bench, \ NULL, \ &data); \ g_free(label); \ } while(FALSE) REGISTER(data_small_with_mruby, 1000, 500, 600, GRN_TRUE); REGISTER(data_small_without_mruby, 1000, 500, 600, GRN_FALSE); REGISTER(data_medium_with_mruby, 10000, 5000, 5100, GRN_TRUE); REGISTER(data_medium_without_mruby, 10000, 5000, 5100, GRN_FALSE); REGISTER(data_large_with_mruby, 100000, 50000, 50100, GRN_TRUE); REGISTER(data_large_without_mruby, 100000, 50000, 50100, GRN_FALSE); REGISTER(data_very_large_with_mruby, 1000000, 500000, 500100, GRN_TRUE); REGISTER(data_very_large_without_mruby, 1000000, 500000, 500100, GRN_FALSE); #undef REGISTER bench_reporter_run(reporter); bench_shutdown(&data_small_with_mruby); bench_shutdown(&data_small_without_mruby); bench_shutdown(&data_medium_with_mruby); bench_shutdown(&data_medium_without_mruby); bench_shutdown(&data_large_with_mruby); bench_shutdown(&data_large_without_mruby); bench_shutdown(&data_very_large_with_mruby); bench_shutdown(&data_very_large_without_mruby); } g_object_unref(reporter); grn_fin(); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int port_no = DEFAULT_PORT, daemon = 0; const char *send_endpoint = NULL, *recv_endpoint = NULL, *log_path = NULL; /* check environment */ { struct rlimit rlim; if (!getrlimit(RLIMIT_NOFILE, &rlim)) { if (rlim.rlim_max < MIN_MAX_FDS) { print_error("too small max fds. %d required.", MIN_MAX_FDS); return -1; } rlim.rlim_cur = rlim.rlim_cur; setrlimit(RLIMIT_NOFILE, &rlim); } } if (!(default_max_threads = get_core_number())) { default_max_threads = DEFAULT_MAX_THREADS; } /* parse options */ { int ch; while ((ch = getopt(argc, argv, "c:p:s:r:l:d")) != -1) { switch(ch) { case 'c': default_max_threads = atoi(optarg); if (default_max_threads > MAX_THREADS) { print_error("too many threads. limit to %d.", MAX_THREADS); default_max_threads = MAX_THREADS; } break; case 'p': port_no = atoi(optarg); break; case 's': send_endpoint = optarg; break; case 'r': recv_endpoint = optarg; break; case 'l': log_path = optarg; break; case 'd': daemon = 1; break; } } argc -= optind; argv += optind; } /* main */ if (argc != 1) { usage(stderr); } else { grn_ctx ctx; void *zmq_ctx; if (daemon) { daemonize(); } grn_init(); grn_ctx_init(&ctx, 0); if ((db = grn_db_open(&ctx, argv[0]))) { if ((zmq_ctx = zmq_init(1))) { signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); signal(SIGQUIT, signal_handler); serve_threads(default_max_threads, port_no, argv[0], zmq_ctx, send_endpoint, recv_endpoint, log_path); zmq_term(zmq_ctx); } else { print_error("cannot create zmq context."); } grn_obj_close(&ctx, db); } else { print_error("cannot open db."); } grn_ctx_fin(&ctx); grn_fin(); } return 0; }
int main(int argc, char **argv) { const char *db_path; const char *dataset_name; grn_ctx ctx_, *ctx; grn_obj *db; grn_bool success = GRN_TRUE; if (argc != 3) { usage(stderr, argc, argv); return(EXIT_FAILURE); } db_path = argv[1]; dataset_name = argv[2]; grn_init(); ctx = &ctx_; grn_ctx_init(ctx, 0); if (access(db_path, F_OK) == 0) { db = grn_db_open(ctx, db_path); if (!db) { fprintf(stderr, "DB open failed (%s): %s\n", db_path, ctx->errbuf); } } else { db = grn_db_create(ctx, db_path, NULL); if (!db) { fprintf(stderr, "DB create failed (%s): %s\n", db_path, ctx->errbuf); } } if (db) { grn_obj text; GRN_TEXT_INIT(&text, 0); #define SEND(string) send_command(ctx, &text, string, dataset_name) SEND("register suggest/suggest"); SEND("table_create event_type TABLE_HASH_KEY ShortText"); SEND("table_create bigram TABLE_PAT_KEY|KEY_NORMALIZE ShortText " "--default_tokenizer TokenBigram"); SEND("table_create kana TABLE_PAT_KEY|KEY_NORMALIZE ShortText"); SEND("table_create item_${DATASET} TABLE_PAT_KEY|KEY_NORMALIZE " "ShortText --default_tokenizer TokenDelimit"); SEND("column_create bigram item_${DATASET}_key " "COLUMN_INDEX|WITH_POSITION item_${DATASET} _key"); SEND("column_create item_${DATASET} kana COLUMN_VECTOR kana"); SEND("column_create kana item_${DATASET}_kana COLUMN_INDEX " "item_${DATASET} kana"); SEND("column_create item_${DATASET} freq COLUMN_SCALAR Int32"); SEND("column_create item_${DATASET} last COLUMN_SCALAR Time"); SEND("column_create item_${DATASET} boost COLUMN_SCALAR Int32"); SEND("column_create item_${DATASET} freq2 COLUMN_SCALAR Int32"); SEND("column_create item_${DATASET} buzz COLUMN_SCALAR Int32"); SEND("table_create pair_${DATASET} TABLE_HASH_KEY UInt64"); SEND("column_create pair_${DATASET} pre COLUMN_SCALAR item_${DATASET}"); SEND("column_create pair_${DATASET} post COLUMN_SCALAR item_${DATASET}"); SEND("column_create pair_${DATASET} freq0 COLUMN_SCALAR Int32"); SEND("column_create pair_${DATASET} freq1 COLUMN_SCALAR Int32"); SEND("column_create pair_${DATASET} freq2 COLUMN_SCALAR Int32"); SEND("column_create item_${DATASET} co COLUMN_INDEX pair_${DATASET} pre"); SEND("table_create sequence_${DATASET} TABLE_HASH_KEY ShortText"); SEND("table_create event_${DATASET} TABLE_NO_KEY"); SEND("column_create sequence_${DATASET} events " "COLUMN_VECTOR|RING_BUFFER event_${DATASET}"); SEND("column_create event_${DATASET} type COLUMN_SCALAR event_type"); SEND("column_create event_${DATASET} time COLUMN_SCALAR Time"); SEND("column_create event_${DATASET} item COLUMN_SCALAR item_${DATASET}"); SEND("column_create event_${DATASET} sequence COLUMN_SCALAR " "sequence_${DATASET}"); #undef SEND success = ctx->rc == GRN_SUCCESS; GRN_OBJ_FIN(ctx, &text); GRN_OBJ_FIN(ctx, db); } else { success = GRN_FALSE; } grn_ctx_fin(ctx); grn_fin(); return success ? EXIT_SUCCESS : EXIT_FAILURE; }