Beispiel #1
0
int main(int argc, char *argv[])
{
    char *password = fsp_argv_password(&argc, argv);

    if (argc != 2) {
      fprintf(stderr, "%s revision %s\n", argv[0], FS_FRONTEND_VER);
      fprintf(stderr, "Usage: %s <kbname>\n", argv[0]);
      return 1;
    }

    fsp_syslog_enable();

    fsp_link *link = fsp_open_link(argv[1], password, FS_OPEN_HINT_RO);

    if (!link) {

      fs_error(LOG_ERR, "couldn't connect to “%s”", argv[1]);
      return 2;
    }

    if (fsp_no_op(link, 0)) {
      fs_error(LOG_ERR, "NO-OP failed\n");
      return 3;
    }

    fs_data_size total = {0, 0, 0, 0, 0, 0};
    fs_data_size sz;
    if (fsp_get_data_size(link, 0, &sz)) {
	fs_error(LOG_ERR, "cannot get size information");

	exit(2);
    }

    printf("%5s%12s%12s%12s%12s\n", "seg","quads (s)","quads (sr)",
           "models", "resources");

    const int segments = fsp_link_segments(link);
    for (fs_segment seg = 0; seg < segments; ++seg) {
        fs_data_size sz;
	int ret = fsp_get_data_size(link, seg, &sz);
	if (ret) {
           printf("%5d -- problem obtaining size information --\n", seg);
	} else {
           printf("%5d%12lld%+12lld%12lld%12lld\n", seg,
                  sz.quads_s, sz.quads_sr - sz.quads_s,
                  sz.models_s, sz.resources);
	   total.quads_s += sz.quads_s;
	   total.quads_sr += sz.quads_sr;
           if (sz.models_s > total.models_s) total.models_s = sz.models_s;
	   total.resources += sz.resources;
	}
   }
    printf("\n");
    printf("%5s%12lld%+12lld%12lld%12lld\n",
           "TOTAL", total.quads_s, (total.quads_sr - total.quads_s),
           total.models_s, total.resources);
    printf("\ncollision probability ≅ %.2Lf%%\n", 100.0 * (1.0 - expl(-(total.resources * (total.resources-1.0) / (2.0 * CONST_2to63)))));

    fsp_close_link(link);
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    char *password = fsp_argv_password(&argc, argv);

    if (argc != 3 || !strcmp(argv[2], "-h")) {
      fprintf(stderr, "Usage: %s kbname <begin|rollback|commit>\n", basename(argv[0]));

      return 1;
    }

    fsp_syslog_enable();
    fsp_link *link = fsp_open_link(argv[1], password, FS_OPEN_HINT_RW);

    if (!link) {
      fprintf(stderr, "couldn't connect to “%s”\n", argv[1]);

      return 2;
    }

    if (fsp_no_op(link, 0)) {
      fprintf(stderr, "NO-OP failed\n");

      return 1;
    }

    int ret = 0;

    if (!strcmp(argv[2], "begin")) {
	fsp_transaction_begin_all(link);
    } else if (!strcmp(argv[2], "rollback")) {
	fsp_transaction_rollback_all(link);
    } else if (!strcmp(argv[2], "precommit")) {
	/* this is an undocumented "feature", don't use it unless you know
	 * what it means, it's only really for benchmark timing */
	ret = fsp_lock(link);
	if (ret) {
	    fs_error(LOG_CRIT, "failed to get commit lock for '%s'", argv[1]);
	}
	if (!ret) ret = fsp_transaction_pre_commit_all(link);
    } else if (!strcmp(argv[2], "commit")) {
	ret = fsp_lock(link);
	if (ret) {
	    fs_error(LOG_CRIT, "failed to get commit lock for '%s'", argv[1]);
	}
	if (!ret) ret = fsp_transaction_pre_commit_all(link);
	if (!ret) ret = fsp_transaction_commit_all(link);
    } else {
	fprintf(stderr, "bad argument, expected “begin”, “rollback” or “commit”\n");

	return 3;
    }

    fsp_close_link(link);

    return ret;
}
Beispiel #3
0
static void daemonize(void)
{
    pid_t sid;
    int fd, rv;

    /* fork once from parent process */
    fork_from_parent();

    /* create new process group */
    sid = setsid();
    if (sid < 0) {
        fsa_error(LOG_ERR, "setsid() error starting daemon: %s",
                  strerror(errno));
        exit(EXIT_FAILURE);
    }

    /* fork again to separate from parent permanently */
    fork_from_parent();

    /* change working directory somewhere known */
    if (chdir("/") == -1) {
        fsa_error(LOG_ERR, "chdir failed: %s", strerror(errno));
    }

    /* close all file descriptors */
    for (fd = getdtablesize(); fd >= 0; fd--) {
        close(fd);
    }

    /* set file mode mask */
    umask(0);

    /* reopen standard fds */
    fd = open("/dev/null", O_RDWR); /* stdin */
    rv = dup(fd); /* stdout */
    rv = dup(fd); /* stderr */

    /* log to syslog instead of stderr */
    fsp_syslog_enable();
    fsa_log_to = ADM_LOG_TO_FS_ERROR;
    setlogmask(LOG_UPTO(fsa_log_level));
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    fs_gnu_options(argc, argv, "<kbname> <noop|freq>\n");

    char *password = fsp_argv_password(&argc, argv);

    if (argc != 3) {
        fprintf(stderr, "Usage: %s <kbname> <noop|freq>\n", basename(argv[0]));
        return 1;
    }

    fsp_syslog_enable();

    fsp_link *link = fsp_open_link(argv[1], password, FS_OPEN_HINT_RO);

    if (!link) {
        fs_error(LOG_ERR, "couldn't connect to “%s”", argv[1]);
        return 2;
    }

    double then = fs_time();
    if (fsp_no_op(link, 0)) {
      fs_error(LOG_ERR, "NO-OP failed\n");
      return 3;
    }
    double now = fs_time();

    if (!strcmp(argv[2], "noop")) {
        printf("NO-OP took %fs\n", now-then);

        return 0;
    } else if (!strcmp(argv[2], "freq")) {
        fs_query_state *qs = fs_query_init(link, NULL, NULL);
        fs_optimiser_freq_print(qs);
    }

    fsp_close_link(link);
}
Beispiel #5
0
int main(int argc, char *argv[])
{
    char *optstring = "nv";
    int help = 0;
    int c, opt_index = 0;
    kbconfig config = {
        .name = NULL,
        .password = NULL,
        .node = 0,
        .cluster = 1,
        .segments = 2,
        .mirror = 0,
        .model_files = 0,
    };

    static struct option long_options[] = {
        { "help", 0, 0, 'h' },
        { "version", 0, 0, 'V' },
        { "verbose", 0, 0, 'v' },
        { "mirror", 0, 0, 'm' },
        { "model-files", 0, 0, 'f' },
        { "print-only", 0, 0, 'n' },
        { "node", 1, 0, 'N' },
        { "cluster", 1, 0, 'C' },
        { "segments", 1, 0, 'S' },
        { "password", 1, 0, 'P' },
        { 0, 0, 0, 0 }
    };

    setlocale(LC_ALL, NULL);
    int help_return = 1;

    while ((c = getopt_long (argc, argv, optstring, long_options, &opt_index)) != -1) {
	if (c == 'v') {
	    verbosity++;
	} else if (c == 'm') {
	    config.mirror = 1;
	} else if (c == 'f') {
	    config.model_files = 1;
	} else if (c == 'n') {
	    dummy = 1;
	} else if (c == 'N') {
	    config.node = atoi(optarg);
	} else if (c == 'C') {
	    config.cluster = atoi(optarg);
	} else if (c == 'S') {
	    config.segments = atoi(optarg);
	} else if (c == 'P') {
	    config.password = optarg;
	} else if (c == 'h') {
	    help = 1;
	    help_return = 0;
	} else if (c == 'V') {
	    printf("%s, built for 4store %s\n", basename(argv[0]), GIT_REV);
	    exit(0);
	} else {
	    help++;
	}
    }

    if (optind == argc - 1) {
	config.name = argv[optind];
    }

    if (config.segments < 1 || config.node < 0 ||
        config.node >= config.cluster || config.name == NULL) {
        help = 1;
    }

    if (help) {
        fprintf(stdout, "%s, built for 4store %s\n", basename(argv[0]), GIT_REV);
        fprintf(stdout, "Usage: %s [-v] --node <id> --cluster <size>\n\t--segments <seg> [--password <pw>] <kbname>\n", basename(argv[0]));
        fprintf(stdout, "   --node <id>       node id 0 ... cluster-1\n");
        fprintf(stdout, "   --cluster <size>  number of nodes in cluster\n");
        fprintf(stdout, "   --segments <seg>  number of segments in cluster\n");
        fprintf(stdout, "   --password <pw>   password for authentication\n");
        fprintf(stdout, "   -m, --mirror      mirror segments\n");
        fprintf(stdout, "   --model-files     use a file per-model (for large models)\n");
        fprintf(stdout, "   -v, --verbose     increase verbosity\n");
        fprintf(stdout, "   -n, --print-only  dont execute commands, just show\n");
        fprintf(stdout, "This command creates KBs, if the KB already exists, its contents are lost.\n");
        return help_return;
    }

    /* check segments is a power of 2 */
    for (int s= config.segments; s > 0; s = s >> 1) {
      if ((s & 1) == 1 && s != 1) {
         fprintf(stderr, "Number of segments must be a power of 2\n");
         return 1;
      }
    }

    fsp_syslog_enable(); /* from now on errors are logged */

    for (int k= 0; k < strlen(config.name); ++k) {
      if (!index(FS_LEGAL_KB_CHARS, config.name[k])) {
        fs_error(LOG_ERR, "character '%c' not allowed in KB name %s", config.name[k], config.name);
        return 1;
      }
    }

    fs_backend *be = fs_backend_init(config.name, FS_BACKEND_NO_OPEN);
    create_dir(&config);

    erase_db(&config);
    fs_error(LOG_INFO, "erased files for KB %s", config.name);

    setup_metadata(&config);

    fs_backend_fini(be);

    return 0;
}

void create_dir(kbconfig *config)
{
    char *tmp;

    LOG(1, "Creating data directory");
    tmp = g_strdup_printf("%s/%s", FS_STORE_ROOT, config->name);
    if (mkdir(tmp, 0755)) {
	if (errno != EEXIST) {
	    fprintf(stderr, "Failed to create store directory '%s': %s\n", 
		tmp, strerror(errno));
	    exit(1);
	}
    }
    g_free(tmp);

    LOG(1, "Create segment directories");
    for (int i=0; i<config->segments; i++) {
	if (!uses_segment(config, i)) continue;
	tmp = g_strdup_printf("%s/%s/%04x", FS_STORE_ROOT, config->name, i);
	if (mkdir(tmp, 0755)) {
	    if (errno != EEXIST) {
		fprintf(stderr, "Failed to create store directory '%s': %s\n", 
		    tmp, strerror(errno));
		exit(1);
	    }
	}
	g_free(tmp);
	fs_backend *be = fs_backend_init(config->name, FS_BACKEND_NO_OPEN);
	if (!be) {
	    fprintf(stderr, "Failed to open backed\n");
	    exit(1);
	}
	fs_backend_open_files(be, i, O_CREAT | O_RDWR | O_TRUNC, FS_OPEN_ALL);
	fs_backend_cleanup_files(be);
	fs_backend_close_files(be, i);
	/* create directories for model indexes */
	tmp = g_strdup_printf("%s/%s/%04x/m", FS_STORE_ROOT,
			      config->name, i);
	mkdir(tmp, 0755);
	g_free(tmp);
	fs_backend_fini(be);
    }
}
Beispiel #6
0
int main(int argc, char *argv[])
{
    int verbosity = 0;
    int dryrun = 0;
    char *password = NULL;
    char *format = "auto";
    FILE *msg = stderr;
    char *optstring = "am:M:vnf:";
    int c, opt_index = 0, help = 0;
    int files = 0, adding = 0;
    char *kb_name = NULL;
    char *model[argc], *uri[argc];
    char *model_default = NULL;

    password = fsp_argv_password(&argc, argv);

    static struct option long_options[] = {
        { "add", 0, 0, 'a' },
        { "model", 1, 0, 'm' },
        { "model-default", 1, 0, 'M' },
        { "verbose", 0, 0, 'v' },
        { "dryrun", 0, 0, 'n' },
        { "no-resources", 0, 0, 'R' },
        { "no-quads", 0, 0, 'Q' },
        { "format", 1, 0, 'f' },
        { "help", 0, 0, 'h' },
        { "version", 0, 0, 'V' },
        { 0, 0, 0, 0 }
    };

    for (int i= 0; i < argc; ++i) {
      model[i] = NULL;
    }

    int help_return = 1;

    while ((c = getopt_long (argc, argv, optstring, long_options, &opt_index)) != -1) {
        if (c == 'm') {
	    model[files++] = optarg;
        } else if (c == 'M') {
            model_default = optarg;
        } else if (c == 'v') {
	    verbosity++;
        } else if (c == 'a') {
	    adding = 1;
        } else if (c == 'n') {
	    dryrun |= FS_DRYRUN_DELETE | FS_DRYRUN_RESOURCES | FS_DRYRUN_QUADS;
	} else if (c == 'R') {
	    dryrun |= FS_DRYRUN_RESOURCES;
	} else if (c == 'Q') {
	    dryrun |= FS_DRYRUN_QUADS;
        } else if (c == 'f') {
            format = optarg;
        } else if (c == 'h') {
	    help = 1;
            help_return = 0;
        } else if (c == 'V') {
            printf("%s, built for 4store %s\n", argv[0], GIT_REV);
            exit(0);
        } else {
	    help = 1;
        }
    }

    if (verbosity > 0) {
	if (dryrun & FS_DRYRUN_DELETE) {
	    printf("warning: not deleting old model\n");
	}
	if (dryrun & FS_DRYRUN_RESOURCES) {
	    printf("warning: not importing resource nodes\n");
	}
	if (dryrun & FS_DRYRUN_QUADS) {
	    printf("warning: not importing quad graph\n");
	}
    }

    files = 0;
    for (int k = optind; k < argc; ++k) {
        if (!kb_name) {
            kb_name = argv[k];
        } else {
	    if (strchr(argv[k], ':')) {
		uri[files] = g_strdup(argv[k]);
	    } else {
		uri[files] = (char *)raptor_uri_filename_to_uri_string(argv[k]);
	    }
            if (!model[files]) {
                if (!model_default) {
                    model[files] = uri[files];
                } else {
                    model[files] = model_default;
                }
            }
            files++;
        }
    }

    raptor_world *rw = raptor_new_world();
    if (help || !kb_name || files == 0) {
        fprintf(stdout, "%s revision %s\n", argv[0], FS_FRONTEND_VER);
        fprintf(stdout, "Usage: %s <kbname> <rdf file/URI> ...\n", argv[0]);
        fprintf(stdout, " -v --verbose   increase verbosity (can repeat)\n");
        fprintf(stdout, " -a --add       add data to models instead of replacing\n");
        fprintf(stdout, " -m --model     specify a model URI for the next RDF file\n");
        fprintf(stdout, " -M --model-default specify a model URI for all RDF files\n");
        fprintf(stdout, " -f --format    specify an RDF syntax for the import\n");
        fprintf(stdout, "\n   available formats are:\n");

        for (unsigned int i=0; 1; i++) {
            const raptor_syntax_description *desc =
                    raptor_world_get_parser_description(rw, i);
            if (!desc) {
                break;
            }
            fprintf(stdout, "    %12s - %s\n", desc->names[0], desc->label);
        }
        exit(help_return);
    }

    fsp_syslog_enable();

    fsplink = fsp_open_link(kb_name, password, FS_OPEN_HINT_RW);

    if (!fsplink) {
      fs_error (LOG_ERR, "couldn't connect to “%s”", kb_name);
      exit(2);
    }

    const char *features = fsp_link_features(fsplink);
    int has_o_index = !(strstr(features, "no-o-index")); /* tweak */

    fs_hash_init(fsp_hash_type(fsplink));
    const int segments = fsp_link_segments(fsplink);
    int total_triples = 0;

    fs_import_timing timing[segments];

    for (int seg = 0; seg < segments; seg++) {
        fsp_get_import_times(fsplink, seg, &timing[seg]);
    }

    gettimeofday(&then, 0);

    if (fsp_start_import_all(fsplink)) {
	fs_error(LOG_ERR, "aborting import");

	exit(3);
    }

#if 0
printf("press enter\n");
char foo;
read(0, &foo, 1);
#endif

    fs_rid_vector *mvec = fs_rid_vector_new(0);

    for (int f= 0; f < files; ++f) {
        fs_rid muri = fs_hash_uri(model[f]);
        fs_rid_vector_append(mvec, muri);
    }
    if (!adding) {
        if (verbosity) {
	    printf("removing old data\n");
	    fflush(stdout);
        }
        if (!(dryrun & FS_DRYRUN_DELETE)) {
	    if (fsp_delete_model_all(fsplink, mvec)) {
	        fs_error(LOG_ERR, "model delete failed");
	        return 1;
	    }
	    for (int i=0; i<mvec->length; i++) {
		if (mvec->data[i] == fs_c.system_config) {
		    fs_import_reread_config();
		}
	    }
        }
        fsp_new_model_all(fsplink, mvec);
    }

    fs_rid_vector_free(mvec);

    gettimeofday(&then_last, 0);
    for (int f = 0; f < files; ++f) {
	if (verbosity) {
            printf("Reading <%s>\n", uri[f]);
            if (strcmp(uri[f], model[f])) {
                printf("   into <%s>\n", model[f]);
            }
	    fflush(stdout);
        }

        fs_import(fsplink, model[f], uri[f], format, verbosity, dryrun, has_o_index, msg, &total_triples);
	if (verbosity) {
	    fflush(stdout);
        }
    }
    double sthen = fs_time();
    int ret = fs_import_commit(fsplink, verbosity, dryrun, has_o_index, msg, &total_triples);

    if (verbosity > 0) {
	printf("Updating index\n");
        fflush(stdout);
    }
    fsp_stop_import_all(fsplink);
    if (verbosity > 0) {
        printf("Index update took %f seconds\n", fs_time()-sthen);
    }

    if (!ret) {
        gettimeofday(&now, 0);
        double diff = (now.tv_sec - then.tv_sec) +
                        (now.tv_usec - then.tv_usec) * 0.000001;
        if (verbosity && total_triples > 0) {
	    printf("Imported %d triples, average %d triples/s\n", total_triples,
		     (int)((double)total_triples/diff));
            fflush(stdout);
        }
    }

    if (verbosity > 1) {
        printf("seg add_q\tadd_r\t\tcommit_q\tcommit_r\tremove\t\trebuild\t\twrite\n");
        long long *tics = fsp_profile_write(fsplink);

        for (int seg = 0; seg < segments; seg++) {
            fs_import_timing newtimes;
            fsp_get_import_times(fsplink, seg, &newtimes);

	    printf("%2d: %f\t%f\t%f\t%f\t%f\t%f\t%f\n", seg,
                   newtimes.add_s - timing[seg].add_s,
	           newtimes.add_r - timing[seg].add_r,
	           newtimes.commit_q - timing[seg].commit_q,
                   newtimes.commit_r - timing[seg].commit_r,
                   newtimes.remove - timing[seg].remove,
		   newtimes.rebuild - timing[seg].rebuild,
		   tics[seg] * 0.001);
	}
    }

    fsp_close_link(fsplink);
    raptor_free_world(rw);

    return 0;
}
Beispiel #7
0
int main(int argc, char *argv[])
{
    char *password = fsp_argv_password(&argc, argv);

    static char *optstring = "hevf:PO:Ib:rs:d";
    char *format = getenv("FORMAT");
    char *kb_name = NULL, *query = NULL;
    int programatic = 0, help = 0;
    int c, opt_index = 0;
    int verbosity = 0;
    int opt_level = 3;
    int insert_mode = 0;
    int restricted = 0;
    int soft_limit = 0;
    int explain = 0;
    int default_graph = 0;
    char *base_uri = "local:";
    raptor_world *rw = NULL;

    static struct option long_options[] = {
        { "help", 0, 0, 'h' },
        { "version", 0, 0, 'V' },
        { "verbose", 0, 0, 'v' },
        { "explain", 0, 0, 'e' },
        { "format", 1, 0, 'f' },
        { "programatic", 0, 0, 'P' },
        { "opt-level", 1, 0, 'O' },
        { "insert", 0, 0, 'I' },
        { "restricted", 0, 0, 'r' },
        { "soft-limit", 1, 0, 's' },
        { "default-graph", 0, 0, 'd' },
        { "base", 1, 0, 'b' },
        { 0, 0, 0, 0 }
    };

    int help_return = 1;

    while ((c = getopt_long (argc, argv, optstring, long_options, &opt_index)) != -1) {
        if (c == 'f') {
            format = optarg;
        } else if (c == 'P') {
            programatic = TRUE;
        } else if (c == 'v') {
            verbosity++;
        } else if (c == 'O') {
            opt_level = atoi(optarg);
        } else if (c == 'I') {
            insert_mode = 1;
        } else if (c == 'r') {
            restricted = 1;
        } else if (c == 's') {
            soft_limit = atoi(optarg);
        } else if (c == 'd') {
            default_graph = 1;
        } else if (c == 'b') {
            base_uri = optarg;
        } else if (c == 'h') {
            help = 1;
            help_return = 0;
        } else if (c == 'e') {
            explain = 1;
        } else if (c == 'V') {
            printf("%s, built for 4store %s\n", argv[0], GIT_REV);
            exit(0); 
        } else {
            help = 1;
        }
    }

    for (int k = optind; k < argc; ++k) {
        if (!kb_name) {
            kb_name = argv[k];
        } else if (!query && !programatic) {
            query = argv[k];
        } else {
            help = 1;
        }
    }

    if (help || !kb_name) {
      char *langs = "";
      if (fs_query_have_laqrs()) {
        langs = "/LAQRS";
      }
      fprintf(stdout, "%s revision %s\n", basename(argv[0]), GIT_REV);
      fprintf(stdout, "Usage: %s <kbname> [-f format] [-O opt-level] [-I] [-b uri] [query]\n", argv[0]);
      fprintf(stdout, "   or: %s <kbname> -P\n", basename(argv[0]));
      fprintf(stdout, " query is a SPARQL%s query, remember to use"
                      " shell quoting if necessary\n", langs);
      fprintf(stdout, " -f              Output format one of, sparql, text, json, or testcase\n");
      fprintf(stdout, " -O, --opt-level Set optimisation level, range 0-3\n");
      fprintf(stdout, " -I, --insert    Interpret CONSTRUCT statements as inserts\n");
      fprintf(stdout, " -r, --restricted  Enable query complexity restriction\n");
      fprintf(stdout, " -s, --soft-limit  Override default soft limit on search breadth\n");
      fprintf(stdout, " -d, --default-graph  Enable SPARQL default graph support\n");
      fprintf(stdout, " -b, --base      Set base URI for query\n");
      fprintf(stdout, " -e, --explain   Show explain results for execution plan\n");

      exit(help_return);
    }

    if (programatic || query) {
        /* don't syslog interactive errors */
        fsp_syslog_enable();
    }

    double then = ftime();
    /* if query does UPDATE or DELETE operations this needs a re-think */
    fsp_link *link = fsp_open_link(kb_name, password, FS_OPEN_HINT_RO);

    double now = ftime();
    show_timing = (getenv("SHOW_TIMING") != NULL) | (verbosity > 1);

    if (show_timing) {
        printf("Link open time: %f\n", now-then);
    }

    if (!link) {
      fs_error(LOG_ERR, "couldn't connect to “%s”", kb_name);
      return 2;
    }

    const int segments = fsp_link_segments(link);

    fs_query_timing timing[segments];
    memset(timing, 0, sizeof(fs_query_timing) * segments);
    if (show_timing) {
	for (int seg = 0; seg < segments; seg++) {
	    fsp_get_query_times(link, seg, timing+seg);
	}
    }

    if (fsp_no_op(link, 0)) {
      fs_error(LOG_ERR, "NO-OP failed for “%s”", kb_name);
      return 2;
    }

    rw = raptor_new_world();
    fs_hash_init(fsp_hash_type(link));

    raptor_uri *bu = raptor_new_uri(rw, (unsigned char *)base_uri);

    unsigned int flags = FS_QUERY_CONSOLE_OUTPUT; /* signal that we're using the */
                             /* console, allows better explain functionality */
    flags |= insert_mode ? FS_RESULT_FLAG_CONSTRUCT_AS_INSERT : 0;
    flags |= restricted ? FS_QUERY_RESTRICTED : 0;
    flags |= default_graph ? FS_QUERY_DEFAULT_GRAPH : 0;

    if (programatic) {
	programatic_io(link, bu, "sparql", format, timing, verbosity, opt_level,
            FS_RESULT_FLAG_HEADERS | flags, soft_limit, rw);
    } else if (!query) {
        if (!format) format = "text";
        interactive(link, bu, format, verbosity, opt_level,
            insert_mode ? FS_RESULT_FLAG_CONSTRUCT_AS_INSERT : flags,
            soft_limit, rw);
    }

    int ret = 0;

    fs_query_state *qs = fs_query_init(link, NULL, NULL);
    qs->verbosity = verbosity;
    fs_query *qr = fs_query_execute(qs, link, bu, query, flags, opt_level, soft_limit, explain);
    if (fs_query_errors(qr)) {
        ret = 1;
    }
    fs_query_results_output(qr, format, 0, stdout);
    fs_query_free(qr);

    if (show_timing) {
	printf("seg bind\t(secs)\t\tprice\t(secs)\t\tresolve\t(secs)\t\twait (secs)\n");
	long long *tics = fsp_profile_write(link);

	for (int seg = 0; seg < segments; seg++) {
	    fs_query_timing newtimes;
	    fsp_get_query_times(link, seg, &newtimes);

	    printf("%2d: %4d\t%f\t%4d\t%f\t%4d\t%f\t%f\n", seg,
		   newtimes.bind_count - timing[seg].bind_count,
		   newtimes.bind - timing[seg].bind,
		   newtimes.price_count - timing[seg].price_count,
		   newtimes.price - timing[seg].price,
		   newtimes.resolve_count - timing[seg].resolve_count,
		   newtimes.resolve - timing[seg].resolve,
		   tics[seg] * 0.001);
	}
    }

    raptor_free_uri(bu);
    raptor_free_world(rw);

    fs_query_cache_flush(qs, verbosity);
    fs_query_fini(qs);

    fsp_close_link(link);

    return ret;
}
Beispiel #8
0
int main(int argc, char *argv[])
{
    char *optstring = "n";
    int help = 0;
    int c, opt_index = 0;
    char *name = NULL;

    static struct option long_options[] = {
        { "version", 0, 0, 'V' },
        { "help", 0, 0, 'h' },
        { "print-only", 0, 0, 'n' },
        { 0, 0, 0, 0 }
    };

    setlocale(LC_ALL, NULL);
    int help_return = 1;

    while ((c = getopt_long (argc, argv, optstring, long_options, &opt_index)) != -1) {
	if (c == 'n') {
	    dummy = 1;
	} else if (c == 'V') {
            printf("%s, built for 4store %s\n", basename(argv[0]), GIT_REV);
	    exit(0);
	} else if (c == 'h') {
            help = 1;
	    help_return = 0;
	} else {
	    help++;
	}
    }

    if (optind == argc - 1) {
	name = argv[optind];
    }

    if (name == NULL) {
        help = 1;
    }

    if (help) {
	printf("%s, built for 4store %s\n", basename(argv[0]), GIT_REV);
        fprintf(stdout, "Usage: %s [-n] <kbname>\n", basename(argv[0]));
        fprintf(stdout, "   -n, --print-only  don't execute just show what would be done\n");
        fprintf(stdout, "This command destroys the KB and all its data.\n");
        return help_return;
    }

    fsp_syslog_enable();

    const int len = strlen(name);
    for (int k= 0; k < len; ++k) {
      if (!index(FS_LEGAL_KB_CHARS, name[k])) {
        fs_error(LOG_ERR, "character '%c' forbidden in a KB name", name[k]);
        return 2;
      }
    }

    char lexf[PATH_MAX + 1];
    lexf[PATH_MAX] = '\0';
    int unlinked = 0, errs = 0;
    gchar *rm_seg_dir_format = g_strconcat("rm -rf ",
					   fs_get_seg_dir_format(),
					   "*",
					   NULL);
    for (fs_segment segment = 0; segment < FS_MAX_SEGMENTS; ++segment)  {
        snprintf(lexf, PATH_MAX, rm_seg_dir_format, name, segment);
        system(lexf);
        snprintf(lexf, PATH_MAX, fs_get_seg_dir_format(), name, segment);
        unlinked += delete_it(lexf, &errs);
    }
    g_free(rm_seg_dir_format);

    gchar *metadata_nt_format = g_strconcat(fs_get_kb_dir_format(), "metadata.nt", NULL);
    snprintf(lexf, PATH_MAX, metadata_nt_format, name);
    unlinked += delete_it(lexf, &errs);
    g_free(metadata_nt_format);
    gchar *runtime_info_format = g_strconcat(fs_get_kb_dir_format(), "runtime.info", NULL);
    snprintf(lexf, PATH_MAX, runtime_info_format, name);
    unlinked += delete_it(lexf, &errs);
    g_free(runtime_info_format);
    gchar *backup_format = g_strconcat(fs_get_kb_dir_format(), "backup", NULL);
    snprintf(lexf, PATH_MAX, backup_format, name);
    unlinked += delete_it(lexf, &errs);
    g_free(backup_format);
    snprintf(lexf, PATH_MAX, fs_get_kb_dir_format(), name);
    unlinked += delete_it(lexf, &errs);

    if (unlinked > 0 && !errs) fs_error(LOG_INFO, "deleted data files for KB %s", name);

    if (errs) {
        return 1;
    }
    return 0;
}
Beispiel #9
0
int main (int argc, char *argv[])
{
  char *kb_name;
  int daemon = 1;
  int help = 0;
  float disk_limit = 1.0;

  fsp_syslog_enable();

  int c, opt_index=0;
  static const char *optstr = "Dl:";
  static struct option longopt[] = {
    { "daemon", 0, 0, 'D' },
    { "limit", 1, 0, 'l' },
    { "help", 0, 0, 'h' },
    { "version", 0, 0, 'v' },
    { 0, 0, 0, 0 }
  };

  if (getenv("FS_DISK_LIMIT")) {
    disk_limit = atof(getenv("FS_DISK_LIMIT"));
  } else if (getenv("DISK_LIMIT")) {
    disk_limit = atof(getenv("DISK_LIMIT"));
  }

  int help_return = 1;

  while (( c = getopt_long(argc, argv, optstr, longopt, &opt_index)) != -1) {
    switch (c) {
    case 'D':
      daemon = 0;
      break;
    case 'l':
      disk_limit = atof(optarg);
      break;
    case 'h':
      help_return = 0;
      help = 1;
      break;
    case 'v':
      printf("4s-backend, built for 4store %s\n", GIT_REV);
      exit(0);
      break;
    default:
      help = 1;
      break;
    }
  }

  if (optind != argc - 1) {
    help = 1;
  }

  if (help) {
    fprintf(stdout, "%s revision %s\n", argv[0], FS_BACKEND_VER);
    fprintf(stdout, "Usage: %s [-D,--deamon] [-l,--limit min-free-space] <kbname>\n", argv[0]);
    fprintf(stdout, "       env. var. FS_DISK_LIMIT also controls min free disk\n");
    return help_return;
  }

  kb_name = argv[argc - 1];

  if (fs_lock_kb(kb_name)) {
    return 1;
  }

  fsp_serve(kb_name, &native_backend, daemon, disk_limit);

  return 2; /* fsp_serve returns only if there is an error */
}