/* perform optimize command */ static int procoptimize(const char *name, const char *params){ TCADB *adb = tcadbnew(); ADBSKEL skel; if(*name == '@'){ setskeltran(&skel); if(!tcadbsetskel(adb, &skel)){ printerr(adb); skel.del(skel.opq); tcadbdel(adb); return 1; } name++; } else if(*name == '%'){ if(!tcadbsetskelmulti(adb, 8)){ printerr(adb); tcadbdel(adb); return 1; } name++; } if(!tcadbopen(adb, name)){ printerr(adb); tcadbdel(adb); return 1; } bool err = false; if(!tcadboptimize(adb, params)){ printerr(adb); err = true; } if(!tcadbclose(adb)){ if(!err) printerr(adb); err = true; } tcadbdel(adb); return err ? 1 : 0; }
gearman_return_t gearman_queue_libtokyocabinet_init(gearman_server_st *server, gearman_conf_st *conf) { gearman_queue_libtokyocabinet_st *queue; gearman_conf_module_st *module; const char *name; const char *value; const char *opt_file= NULL; const char *opt_optimize= NULL; gearman_log_info(server->gearman, "Initializing libtokyocabinet module"); queue= calloc(1, sizeof(gearman_queue_libtokyocabinet_st)); if (queue == NULL) { gearman_log_error(server->gearman, "gearman_queue_libtokyocabinet_init", "malloc"); return GEARMAN_MEMORY_ALLOCATION_FAILURE; } if ((queue->db= tcadbnew()) == NULL) { free(queue); gearman_log_error(server->gearman, "gearman_queue_libtokyocabinet_init", "tcadbnew"); return GEARMAN_QUEUE_ERROR; } /* Get module and parse the option values that were given. */ module= gearman_conf_module_find(conf, "libtokyocabinet"); if (module == NULL) { gearman_log_error(server->gearman, "gearman_queue_libtokyocabinet_init", "modconf_module_find:NULL"); return GEARMAN_QUEUE_ERROR; } while (gearman_conf_module_value(module, &name, &value)) { if (!strcmp(name, "file")) opt_file= value; else if (!strcmp(name, "optimize")) opt_optimize= value; else { tcadbdel(queue->db); free(queue); gearman_log_error(server->gearman, "gearman_queue_libtokyocabinet_init", "Unknown argument: %s", name); return GEARMAN_QUEUE_ERROR; } } if (opt_file == NULL) { gearman_log_error(server->gearman, "gearman_queue_libtokyocabinet_init", "No --file given"); return GEARMAN_QUEUE_ERROR; } if (!tcadbopen(queue->db, opt_file)) { tcadbdel(queue->db); free(queue); gearman_log_error(server->gearman, "gearman_queue_libtokyocabinet_init", "tcadbopen(%s): %s", opt_file, _libtokyocabinet_tcaerrmsg(queue->db)); return GEARMAN_QUEUE_ERROR; } if (opt_optimize == NULL || !strcasecmp(opt_optimize, "yes")) { gearman_log_info(server->gearman, "libtokyocabinet optimizing database file"); if (!tcadboptimize(queue->db, NULL)) { tcadbdel(queue->db); free(queue); gearman_log_error(server->gearman, "gearman_queue_libtokyocabinet_init", "tcadboptimize"); return GEARMAN_QUEUE_ERROR; } } gearman_server_set_queue_context(server, queue); gearman_server_set_queue_add_fn(server, _libtokyocabinet_add); gearman_server_set_queue_flush_fn(server, _libtokyocabinet_flush); gearman_server_set_queue_done_fn(server, _libtokyocabinet_done); gearman_server_set_queue_replay_fn(server, _libtokyocabinet_replay); return GEARMAN_SUCCESS; }