/* write back contents of scheduler queue to database (internal function) */
static int ta_flush(ta_t *ta, bool wr)
{
    int ret = TA_OK;
    ta_iter_t *tmp, *iter = ta->head;
    
    while (iter) {
        if (wr) {
            switch (iter->kind) {
            case TA_DELETE:
                ret |= ds_delete(iter->vhandle, iter->word);
                break;
            case TA_WRITE:
		set_date(iter->dsvval->date); /* wrong date otherwise! */
                ret |= ds_write(iter->vhandle, iter->word, iter->dsvval);
                break;
            }
        }
	word_free(iter->word);
	xfree(iter->dsvval);
        tmp = iter;
        iter = iter->next;
        xfree(tmp);
    }
    xfree(ta);

    return ret;
}
Example #2
0
main()
{
int count;
int fd;
int measurements = 10000;
char buffer[SECTOR];

FILE *fout = fopen("ploppy.txt", "w");

float time1;
float time2;
float outtime;
struct timeval tv;

for (count = 0; count < SECTOR; count++)
{
   buffer[count] = 'X';
}

fd = ds_open("/dev/disksim", O_WRONLY);

for (count = 0; count < measurements; count++)
{
   ds_lseek(fd, 0, SEEK_CUR);
   ds_write(fd, buffer, SECTOR);

   ds_gettimeofday(&tv);
   time1 = (float) tv.tv_sec*1000 + (float) tv.tv_usec/1000;

   ds_lseek(fd, SECTOR, SEEK_CUR);
   ds_write(fd, buffer, SECTOR);

   ds_gettimeofday(&tv);
   time2 = (float) tv.tv_sec*1000 + (float) tv.tv_usec/1000;

   outtime = time2 - time1;

   fprintf(fout, "%d ", count);
   fprintf(fout, "%f\n", outtime);
}
ds_close(fd);
fclose(fout);
}
Example #3
0
static ex_t get_robx(bfpath *bfp)
{
    double rx;
    int ret = 0;

    init_wordlist("word", bfp->filepath, 0, WL_REGULAR);
    rx = compute_robinson_x();
    if (rx < 0)
	return EX_ERROR;

    if (onlyprint)
	printf("%f\n", rx);
    else {
	dsv_t val;
	word_t *word_robx = word_news(ROBX_W);

	/* since compute_robinson_x() closes the wordlists, 
	   init_wordlist() must be called again */
	init_wordlist("word", bfp->filepath, 0, WL_REGULAR);

	open_wordlists(DS_WRITE);

	val.goodcount = 0;
	val.spamcount = (uint32_t) (rx * 1000000);
	do {
	    ret = ds_write(word_lists->dsh, word_robx, &val);
	    if (ret == DS_ABORT_RETRY) {
		rand_sleep(1000, 1000000);
		begin_wordlist(word_lists);
	    }
	} while (ret == DS_ABORT_RETRY);

	close_wordlists(true);
	free_wordlists();

	word_free(word_robx);
    }

    return ret ? EX_ERROR : EX_OK;
}
Example #4
0
static int load_wordlist(bfpath *bfp)
{
    void *dsh;
    byte buf[BUFSIZE];
    byte *p;
    int rv = 0;
    size_t len;
    int load_count = 0;
    unsigned long line = 0;
    unsigned long count[IX_SIZE], date;
    YYYYMMDD today_save = today;

    void *dbe = ds_init(bfp);

    dsh = ds_open(dbe, bfp, (dbmode_t)(DS_WRITE | DS_LOAD));
    if (dsh == NULL)
	/* print error, cleanup, and exit */
	ds_open_failure(bfp, dbe);

    memset(buf, '\0', BUFSIZE);

    if (DST_OK != ds_txn_begin(dsh))
	exit(EX_ERROR);

    for (;;) {
	dsv_t data;
	word_t *token;
	if (fgets((char *)buf, BUFSIZE, fpin) == NULL) {
	    if (ferror(fpin)) {
		perror(progname);
		rv = 2;
	    }
	    break;
	}

	line++;

	len = strlen((char *)buf);

	/* too short. */
	if (len < 4)
	    continue;

	p = spanword(buf);
	len = strlen((const char *)buf);

	if (max_token_len != 0 &&
	    len > max_token_len)
	    continue;		/* too long - discard */

	spamcount = (uint) atoi((const char *)p);
	if ((int) spamcount < 0)
	    spamcount = 0;
	p = spanword(p);

	goodcount = (uint) atoi((const char *)p);
	if ((int) goodcount < 0)
	    goodcount = 0;
	p = spanword(p);

	date = (uint) atoi((const char *)p);
	p = spanword(p);

	if (*p != '\0') {
	    fprintf(stderr,
		    "%s: Unexpected input [%s] on line %lu. "
		    "Expecting whitespace before count.\n",
		    progname, buf, line);
	    rv = 1;
	    break;
	}

	if (date == 0)				/* date as YYYYMMDD */
	    date = today_save;

	if (replace_nonascii_characters)
	    do_replace_nonascii_characters(buf, len);
 
 	token = word_new(buf, len);
	data.goodcount = goodcount;
	data.spamcount = spamcount;
	data.date = date;

	if (is_count((const char *)buf)
		&& !(maintain && discard_token(token, &data))) {
	    load_count += 1;
	    /* Slower, but allows multiple lists to be concatenated */
	    set_date(date);
	    switch (ds_read(dsh, token, &data)) {
		case 0:
		case 1:
		    break;
		default:
		    rv = 1;
	    }
	    data.spamcount += spamcount;
	    data.goodcount += goodcount;
	    if (ds_write(dsh, token, &data)) rv = 1;
	}
	word_free(token);
    }

    if (rv) {
	fprintf(stderr, "read or write error, aborting.\n");
	ds_txn_abort(dsh);
    } else {
	switch (ds_txn_commit(dsh)) {
	    case DST_FAILURE:
	    case DST_TEMPFAIL:
		fprintf(stderr, "commit failed\n");
		exit(EX_ERROR);
	    case DST_OK:
		break;
	}
    }

    ds_close(dsh);

    ds_cleanup(dbe);

    if (verbose)
	fprintf(dbgout, "%d tokens loaded\n", load_count);

    return rv;
}