Пример #1
0
static void
compact_delete_node1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_setint(env, "compaction.node_size", 524288 /* 512K */) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	int key = 0;
	char value[100];
	memset(value, 0, sizeof(value));
	while (key < 13000) {
		void *o = sp_object(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
		t( sp_setstring(o, "value", value, sizeof(value)) == 0 );
		t( sp_set(db, o) == 0 );
		key++;
	}
	t( sp_setint(env, "db.test.branch", 0) == 0 );
	t( sp_setint(env, "db.test.compact", 0) == 0 );

	t( sp_getint(env, "db.test.index.node_count") == 2 );

	key = 0;
	while (key < 5511 ) {
		void *o = sp_object(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
		t( sp_delete(db, o) == 0 );
		key++;
	}

	t( sp_setint(env, "db.test.branch", 0) == 0 );
	t( sp_setint(env, "db.test.compact", 0) == 0 );

	t( sp_getint(env, "db.test.index.node_count") == 1 );

	void *o = sp_object(db);
	void *cur = sp_cursor(db, o);
	while ((o = sp_get(cur, NULL))) {
		t( sp_delete(db, o) == 0 );
		key++;
		sp_destroy(o);
	}
	sp_destroy(cur);
	t( key == 13000 );

	t( sp_setint(env, "db.test.branch", 0) == 0 );
	t( sp_setint(env, "db.test.compact", 0) == 0 );

	t( sp_getint(env, "db.test.index.node_count") == 1 );
	t( sp_destroy(env) == 0 );
}
Пример #2
0
sophiadb_t* db_init(void * conf) {
	
	conf_t * pconf = (conf_t *)conf;
	printf("size of datatype = %d\n",pconf->max_num);

	sophiadb_t* db = (sophiadb_t*) calloc(pconf->max_num, sizeof(sophiadb_t));	
	if (!db) {
		printf("error alloc size=%lu\n", sizeof(sophiadb_t));
		exit(1);
	}
	
	assert(db);	

	datatype_t * p = (datatype_t *)pconf->list_datatypes;	
	
	spcmpf fcmp ;

	while(p) {
		fcmp = cmp0;

		if (p->number <= 0) {
			printf("error config parametr: number=%d \n", p->number );
			free(db);
			return NULL;
		}

		db[p->number-1].type = p->type;
		db[p->number-1].datadir = p->datadir;

		switch (p->type) {
			case SPHDB_INT :
				db[p->number-1].datalen = sizeof(int32_t);
				fcmp = cmp32;
				break;
		
			case SPHDB_LONG : 
				db[p->number-1].datalen = sizeof(int64_t);
				fcmp = cmp64;
				break;

			case SPHDB_STRING :	
				db[p->number-1].datalen = SPHDB_STRLEN;
				break;

			default:
				printf("error: undefined config datatype\n");
				free(db);
				exit(1);
		}

	printf("fcmp: fcmp=%x\n", fcmp);

		db[p->number-1].env = sp_env();
		if (db[p->number-1].env == NULL) {
			/* memory allocation error */
			printf("env error\n");
			free(db);
			exit(1);
		}

		int rc = sp_ctl(db[p->number-1].env, SPDIR, SPO_CREAT|SPO_RDWR, p->datadir);
		if (rc == -1) {
			/* memory allocation error */
			printf("error: %s\n", sp_error(db[p->number-1].env));
			sp_destroy(db[p->number-1].env);
			free(db);
			exit(1);
		}

		if (fcmp != cmp0) {	
			printf("%s type=%d %x\n", p->datadir, p->type , fcmp);
			rc = sp_ctl(db[p->number-1].env, SPCMP, fcmp, NULL); 
			if (rc == -1) {
				/* memory allocation error */
				printf("error: %s\n", sp_error(db[p->number-1].env));
				sp_destroy(db[p->number-1].env);
				free(db);
				exit(1);
			}
		}

		db[p->number-1].db = sp_open(db[p->number-1].env);
		if (db[p->number-1].db == NULL) {
		    printf("sp_open: %s\n", sp_error(db[p->number-1].env));
		    sp_destroy(db[p->number-1].env);
		    exit(1);
		}

	 	p = p->next;
	}


	printf("db is open %s\n", pconf->datadir );


	return db;
}
Пример #3
0
static void
ddl_create_online2(void)
{
	rmrf("./logdir");
	rmrf("./dir0");
	rmrf("./dir1");

	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_open(env) == 0 );

	t( sp_setstring(env, "db", "s0", 0) == 0 );
	t( sp_setstring(env, "db.s0.path", "dir0", 0) == 0 );
	t( sp_setstring(env, "db.s0.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.s0.sync", 0) == 0 );
	void *s0 = sp_getobject(env, "db.s0");
	t( s0 != NULL );
	t( sp_open(s0) == 0 );

	int key = 7;
	void *o = sp_object(s0);
	sp_setstring(o, "key", &key, sizeof(key));
	t( sp_set(s0, o) == 0 );
	key = 8;
	o = sp_object(s0);
	sp_setstring(o, "key", &key, sizeof(key));
	t( sp_set(s0, o) == 0 );
	key = 9;
	o = sp_object(s0);
	sp_setstring(o, "key", &key, sizeof(key));
	t( sp_set(s0, o) == 0 );

	t( sp_setstring(env, "db", "s1", 0) == 0 );
	t( sp_setstring(env, "db.s1.path", "dir1", 0) == 0 );
	t( sp_setstring(env, "db.s1.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.s1.sync", 0) == 0 );
	void *s1 = sp_getobject(env, "db.s1");
	t( s1 != NULL );
	t( sp_open(s1) == 0 );

	key = 7;
	o = sp_object(s1);
	sp_setstring(o, "key", &key, sizeof(key));
	t( sp_set(s1, o) == 0 );
	key = 8;
	o = sp_object(s1);
	sp_setstring(o, "key", &key, sizeof(key));
	t( sp_set(s1, o) == 0 );
	key = 9;
	o = sp_object(s1);
	sp_setstring(o, "key", &key, sizeof(key));
	t( sp_set(s1, o) == 0 );

	t( sp_destroy(s1) == 0 );
	t( sp_destroy(s0) == 0 );
	t( sp_destroy(env) == 0 );

	rmrf("./logdir");
	rmrf("./dir0");
	rmrf("./dir1");
}
Пример #4
0
static void
snapshot_test1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.sync", 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );

	int key = 0;
	while (key < 10) {
		void *o = sp_document(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
		t( sp_setstring(o, "value", &key, sizeof(key)) == 0 );
		t( sp_set(db, o) == 0 );
		key++;
	}
	t( sp_setint(env, "db.test.branch", 0) == 0 );

	t( sp_getint(env, "scheduler.snapshot_active") == 0 );
	t( sp_getint(env, "scheduler.snapshot_ssn") == 0 );
	t( sp_getint(env, "scheduler.snapshot_ssn_last") == 0 );

	t( sp_setint(env, "scheduler.snapshot", 0) == 0 );

	t( sp_getint(env, "scheduler.snapshot_active") == 1 );
	t( sp_getint(env, "scheduler.snapshot_ssn") == 1 );
	t( sp_getint(env, "scheduler.snapshot_ssn_last") == 0 );

	t( sp_setint(env, "scheduler.run", 0) == 1 );
	t( sp_setint(env, "scheduler.run", 0) == 1 );
	t( sp_setint(env, "scheduler.run", 0) == 0 );

	t( sp_getint(env, "scheduler.snapshot_active") == 0 );
	t( sp_getint(env, "scheduler.snapshot_ssn") == 0 );
	t( sp_getint(env, "scheduler.snapshot_ssn_last") == 1 );

	while (key < 15) {
		void *o = sp_document(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
		t( sp_setstring(o, "value", &key, sizeof(key)) == 0 );
		t( sp_set(db, o) == 0 );
		key++;
	}
	t( sp_setint(env, "db.test.branch", 0) == 0 );

	t( sp_destroy(env) == 0 );

	env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.sync", 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	db = sp_getobject(env, "db.test");
	t( sp_open(env) == 0 );

	key = 0;
	while (key < 10) {
		void *o = sp_document(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
		o = sp_get(db, o);
		t( o != NULL );
		sp_destroy(o);
		key++;
	}
	t( sp_destroy(env) == 0 );
}
Пример #5
0
int main()
{
    srand(time(NULL));
    int i;
    UserData ud;
    ud.pdel = 0;
    sp_data *sp;
    sp_create(&sp);
    sp->len = 44100 * 40;
    char *notes[] = {
        "62 69 78",
        "55 62 69 71",
        "43 50"
    };


    for(i = 0; i < NUMLINE; i++) {
        sp_randi_create(&ud.line[i].randi);
        chord_cloud_create(&ud.line[i].cc);
        chord_cloud_init(sp, ud.line[i].cc, notes[i], 0.1);
        sp_randi_init(sp, ud.line[i].randi, rand());
        ud.line[i].randi->cps = 0.1 + randf(1.5);
    }
    sp_revsc_create(&ud.rev);
    sp_revsc_init(sp, ud.rev);
    ud.rev->feedback = 0.95;
    sp_metro_create(&ud.clk);
    sp_metro_init(sp, ud.clk);
    ud.clk->freq = 86.0 / 60.0;
    sp_count_create(&ud.meter);
    sp_count_init(sp, ud.meter);
    ud.meter->count = 5;
    sp_drip_create(&ud.drip);
    sp_drip_init(sp, ud.drip, 0.01);
    sp_vdelay_create(&ud.del);
    /* give some headroom for the delay */
    sp_vdelay_init(sp, ud.del, 0.4);
    ud.del->del = 0.3;

    sp_tenv_create(&ud.master);
    sp_tenv_init(sp, ud.master);
    ud.master->atk = 0;
    ud.master->hold = 30;
    ud.master->rel =  10;


    sp_progress_create(&ud.prog);
    sp_progress_init(sp, ud.prog);

    modal_create(&ud.mod);
    modal_init(sp, ud.mod);
    sp_ftbl_create(sp, &ud.notes, 1);
    sp_gen_vals(sp, ud.notes, "62 64 59 57");
    sp_tseq_create(&ud.seq);
    sp_tseq_init(sp, ud.seq, ud.notes);
    sp_maygate_create(&ud.mg);
    sp_maygate_init(sp, ud.mg);
    ud.mg->prob = 0.3;
    ud.mg->mode = 1;
    sp_process(sp, &ud, process);

    for(i = 0; i < NUMLINE; i++) {
        sp_randi_destroy(&ud.line[i].randi);
        chord_cloud_destroy(&ud.line[i].cc);
    }


    sp_drip_destroy(&ud.drip);
    sp_revsc_destroy(&ud.rev);
    sp_metro_destroy(&ud.clk);
    sp_count_destroy(&ud.meter);
    sp_vdelay_destroy(&ud.del);
    sp_tenv_destroy(&ud.master);
    modal_destroy(&ud.mod);
    sp_ftbl_destroy(&ud.notes);
    sp_tseq_destroy(&ud.seq);
    sp_maygate_destroy(&ud.mg);
    sp_progress_destroy(&ud.prog);

    sp_destroy(&sp);
    return 0;
}
Пример #6
0
static void
recover_loop(stc *cx)
{
	int seedprev = -1;
	int seed = 3424118;
	int seedorigin = seed;
	int run = 10;
	int count = 1040;

	while (run >= 0) {
		cx->env = sp_env();
		t( cx->env != NULL );
		void *c = sp_ctl(cx->env);
		t( c != NULL );
		t( sp_set(c, "sham.path", cx->suite->shamdir) == 0 );
		t( sp_set(c, "scheduler.threads", "0") == 0 );
		t( sp_set(c, "compaction.0.branch_wm", "1") == 0 );
		t( sp_set(c, "log.path", cx->suite->logdir) == 0 );
		t( sp_set(c, "log.sync", "0") == 0 );
		t( sp_set(c, "log.rotate_sync", "0") == 0 );
		t( sp_set(c, "db", "test") == 0 );
		t( sp_set(c, "db.test.path", cx->suite->dir) == 0 );
		t( sp_set(c, "db.test.sync", "0") == 0 );
		t( sp_set(c, "db.test.index.cmp", "u32", NULL) == 0 );
		cx->db = sp_get(c, "db.test");
		t( cx->db != NULL );
		t( sp_open(cx->env) == 0 );
	
		int i = 0;
		if (seedprev != -1) {
			srand(seedprev);
			while (i < count) {
				int k = rand();
				void *o = sp_object(cx->db);
				t( sp_set(o, "key", &k, sizeof(k)) == 0 );
				o = sp_get(cx->db, o);
				t( o != NULL );
				st_transaction(cx);
				t( *(int*)sp_get(o, "value", NULL) == k );
				sp_destroy(o);
				i++;
			}
			t( sp_set(c, "db.test.branch") == 0 );
		}

		srand(seed);
		i = 0;
		while (i < count) {
			int k = rand();
			void *o = sp_object(cx->db);
			t( o != NULL );
			t( sp_set(o, "key", &k, sizeof(k)) == 0 );
			t( sp_set(o, "value", &k, sizeof(k)) == 0 );
			t( sp_set(cx->db, o) == 0 );
			st_transaction(cx);
			i++;
		}
		t( sp_destroy(cx->env) == 0 );

		seedprev = seed;
		seed = time(NULL);
		run--;
	}

	cx->env = sp_env();
	t( cx->env != NULL );
	void *c = sp_ctl(cx->env);
	t( c != NULL );
	t( sp_set(c, "sham.path", cx->suite->shamdir) == 0 );
	t( sp_set(c, "scheduler.threads", "0") == 0 );
	t( sp_set(c, "compaction.0.branch_wm", "1") == 0 );
	t( sp_set(c, "log.path", cx->suite->logdir) == 0 );
	t( sp_set(c, "log.sync", "0") == 0 );
	t( sp_set(c, "log.rotate_sync", "0") == 0 );
	t( sp_set(c, "db", "test") == 0 );
	t( sp_set(c, "db.test.path", cx->suite->dir) == 0 );
	t( sp_set(c, "db.test.sync", "0") == 0 );
	t( sp_set(c, "db.test.index.cmp", "u32", NULL) == 0 );
	cx->db = sp_get(c, "db.test");
	t( cx->db != NULL );
	t( sp_open(cx->env) == 0 );

	srand(seedorigin);
	int i = 0;
	while (i < count) {
		int k = rand();
		void *o = sp_object(cx->db);
		t( sp_set(o, "key", &k, sizeof(k)) == 0 );
		o = sp_get(cx->db, o);
		t( o != NULL );
		t( *(int*)sp_get(o, "value", NULL) == k );
		sp_destroy(o);
		i++;
	}
	t( sp_destroy(cx->env) == 0 );
	cx->env = NULL;
	cx->db  = NULL;
}
 void destroy() {
     plumber_clean(&pd);
     sp_destroy(&sp);
 }
Пример #8
0
 void destroy() {
     sp_noise_destroy(&noise);
     sp_destroy(&sp);
 }
Пример #9
0
 void destroy() {
     sp_autowah_destroy(&autowah);
     sp_destroy(&sp);
 }
Пример #10
0
 void destroy() {
     sp_osc_destroy(&osc);
     sp_destroy(&sp);
 }
Пример #11
0
 void destroy() {
     sp_drip_destroy(&drip);
     sp_destroy(&sp);
 }
Пример #12
0
void
sphia_iterator_free (sphia_iterator_t *self) {
  if (self->cursor) sp_destroy(self->cursor);
  free(self);
}
Пример #13
0
void
sphia_iterator_end (sphia_iterator_t *self) {
  if (self->cursor) sp_destroy(self->cursor);
  self->cursor = NULL;
}
Пример #14
0
static void
tpr_test1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.enable", 0) == 0 );
	t( sp_setint(env, "log.two_phase_recover", 1) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );

	t( sp_open(env) == 0 );

	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );
	t( sp_open(env) == 0 );

	int key = 7;
	int value = 8;
	void *o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );
	t( sp_setint(env, "db.test.branch", 0) == 0 );
	key = 7;
	value = 9;
	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );
	t( sp_destroy(env) == 0 );

	env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.enable", 0) == 0 );
	t( sp_setint(env, "log.two_phase_recover", 1) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );

	char *v = sp_getstring(env, "db.test.status", NULL);
	t( strcmp(v, "recover") == 0 );
	free(v);

	void *tx = sp_begin(env);
	t( tx != NULL );
	key = 7;
	value = 8;
	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "lsn", 1) == 0 );
	t( sp_commit(tx) == 0 ); /* skip */

	tx = sp_begin(env);
	t( tx != NULL );
	key = 7;
	value = 9;
	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(tx, o) == 0 );
	t( sp_setint(tx, "lsn", 2) == 0 );
	t( sp_commit(tx) == 0 ); /* commit */

	t( sp_open(env) == 0 );

	v = sp_getstring(env, "db.test.status", NULL);
	t( strcmp(v, "online") == 0 );
	free(v);

	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	o = sp_get(db, o);
	t( o != NULL );
	t( *(int*)sp_getstring(o, "value", NULL) == 9 );
	t( sp_getint(o, "lsn") == 2ULL );
	t( sp_destroy(o) == 0 );

	t( sp_destroy(env) == 0 );
}
 void destroy() {
     sp_tbvcf_destroy(&tbvcf);
     sp_destroy(&sp);
 }
Пример #16
0
static void
snapshot_recover_get(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_setint(env, "log.sync", 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	int i = 0;
	while ( i < 100 ) {
		void *o = sp_object(db);
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		t( sp_setstring(o, "value", &i, sizeof(i)) == 0 );
		t( sp_set(db, o) == 0 );
		i++;
	}

	t( sp_setstring(env, "snapshot", "test_snapshot", 0) == 0 );
	void *snapshot = sp_getobject(env, "snapshot.test_snapshot");
	t( snapshot != NULL );

	i = 0;
	while ( i < 100 ) {
		void *o = sp_object(db);
		int value = i + 1;
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
		t( sp_set(db, o) == 0 );
		i++;
	}

	int64_t lsn = sp_getint(env, "snapshot.test_snapshot.lsn");

	t( sp_destroy(env) == 0 );

	env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_setint(env, "log.sync", 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );

	/* recover snapshot */
	t( sp_setstring(env, "snapshot", "test_snapshot", 0) == 0 );
	snapshot = sp_getobject(env, "snapshot.test_snapshot");
	t( snapshot != NULL );
	t( sp_setint(env, "snapshot.test_snapshot.lsn", lsn) == 0 );

	t( sp_open(env) == 0 );
	db = sp_getobject(env, "db.test");
	t( db != NULL );

	i = 0;
	while ( i < 100 ) {
		void *o = sp_object(db);
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		o = sp_get(db, o);
		t( *(int*)sp_getstring(o, "value", NULL) == i + 1 );
		t( sp_destroy(o) == 0 );
		i++;
	}

	i = 0;
	while ( i < 100 ) {
		void *o = sp_object(db);
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		o = sp_get(snapshot, o);
		t( *(int*)sp_getstring(o, "value", NULL) == i );
		t( sp_destroy(o) == 0 );
		i++;
	}

	t( sp_destroy(env) == 0 );
}
Пример #17
0
static void
anticache_promote0(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "memory.anticache", 100 * 1024 * 1024) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.sync", 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setstring(env, "db.test.storage", "anti-cache", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_setint(env, "db.test.temperature", 1) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(db) == 0 );

	int key = 0;
	while (key < 10) {
		void *o = sp_document(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
		t( sp_setstring(o, "value", &key, sizeof(key)) == 0 );
		t( sp_set(db, o) == 0 );
		key++;
	}
	t( sp_setint(env, "db.test.branch", 0) == 0 );

	t( sp_getint(env, "scheduler.anticache_active") == 0 );
	t( sp_getint(env, "scheduler.anticache_asn") == 0 );
	t( sp_getint(env, "scheduler.anticache_asn_last") == 0 );

	t( sp_setint(env, "scheduler.anticache", 0) == 0 );

	t( sp_getint(env, "scheduler.anticache_active") == 1 );
	t( sp_getint(env, "scheduler.anticache_asn") == 1 );
	t( sp_getint(env, "scheduler.anticache_asn_last") == 0 );

	int rc;
	while ( (rc = sp_setint(env, "scheduler.run", 0)) > 0 );
	t( rc == 0 );

	t( sp_getint(env, "scheduler.anticache_active") == 0 );
	t( sp_getint(env, "scheduler.anticache_asn") == 0 );
	t( sp_getint(env, "scheduler.anticache_asn_last") == 1 );

	key = 0;
	while (key < 10) {
		void *o = sp_document(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
		o = sp_get(db, o);
		t( o != NULL );
		sp_destroy(o);
		key++;
	}

	t( sp_destroy(env) == 0 );
}
Пример #18
0
static void
snapshot_cursor(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	int i = 0;
	while ( i < 100 ) {
		void *o = sp_object(db);
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		t( sp_setstring(o, "value", &i, sizeof(i)) == 0 );
		t( sp_set(db, o) == 0 );
		i++;
	}

	t( sp_setstring(env, "snapshot", "test_snapshot", 0) == 0 );
	void *snapshot = sp_getobject(env, "snapshot.test_snapshot");
	t( snapshot != NULL );

	i = 0;
	while ( i < 100 ) {
		void *o = sp_object(db);
		int value = i + 1;
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
		t( sp_set(db, o) == 0 );
		i++;
	}

	i = 0;
	void *o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "order", ">=", 0) == 0 );
	void *cur = sp_cursor(env);
	while ((o = sp_get(cur, o))) {
		t( *(int*)sp_getstring(o, "key", NULL) == i );
		t( *(int*)sp_getstring(o, "value", NULL) == i + 1);
		i++;
	}
	sp_destroy(cur);

	i = 0;
	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "order", ">=", 0) == 0 );
	cur = sp_cursor(snapshot);
	while ((o = sp_get(cur, o))) {
		t( *(int*)sp_getstring(o, "key", NULL) == i );
		t( *(int*)sp_getstring(o, "value", NULL) == i );
		i++;
	}
	sp_destroy(cur);

	t( sp_destroy(env) == 0 );
}
Пример #19
0
 void destroy() {
     sp_panst_destroy(&panst);
     sp_destroy(&sp);
 }
 void destroy() {
     sp_blsaw_destroy(&blsaw);
     sp_destroy(&sp);
 }
Пример #21
0
int main(int argc, char *argv[])
{
	(void)argc;
	(void)argv;

	/*
	 * Do set, get, delete operations. (see transaction.c)
	*/

	/* open or create environment and database */
	void *env = sp_env();
	sp_setstring(env, "sophia.path", "_test", 0);
	sp_setstring(env, "db", "test", 0);
	void *db = sp_getobject(env, "db.test");
	int rc = sp_open(env);
	if (rc == -1)
		goto error;

	/* set */
	uint32_t key = 1;
	void *o = sp_object(db);
	sp_setstring(o, "key", &key, sizeof(key));
	sp_setstring(o, "value", &key, sizeof(key));
	rc = sp_set(db, o);
	if (rc == -1)
		goto error;

	/* get */
	o = sp_object(db);
	sp_setstring(o, "key", &key, sizeof(key));
	o = sp_get(db, o);
	if (o) {
		/* ensure key and value are correct */
		int size;
		char *ptr = sp_getstring(o, "key", &size);
		assert(size == sizeof(uint32_t));
		assert(*(uint32_t*)ptr == key);

		ptr = sp_getstring(o, "value", &size);
		assert(size == sizeof(uint32_t));
		assert(*(uint32_t*)ptr == key);

		sp_destroy(o);
	}

	/* delete */
	o = sp_object(db);
	sp_setstring(o, "key", &key, sizeof(key));
	rc = sp_delete(db, o);
	if (rc == -1)
		goto error;

	/* finish work */
	sp_destroy(env);
	return 0;

error:;
	int size;
	char *error = sp_getstring(env, "sophia.error", &size);
	printf("error: %s\n", error);
	free(error);
	sp_destroy(env);
	return 1;
}
Пример #22
0
static void
mt_set_get_document_multipart_cursor(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 5) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_setstring(env, "db.test.format", "document", 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key_b", 0) == 0 );
	t( sp_setstring(env, "db.test.index.key_b", "u32", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	struct document {
		uint32_t value;
		char used0[89];
		uint32_t key_a;
		char used1[15];
		uint32_t key_b;
		char used2[10];
	} sspacked;
	struct document doc;
	memset(&doc, 'x', sizeof(doc));

	uint32_t n = 500000;
	uint32_t i;

	for (i = 0; i < n; i++) {
		doc.key_a = i;
		doc.key_b = i;
		doc.value = doc.key_a ^ doc.key_b;
		void *o = sp_object(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &doc.key_a, sizeof(doc.key_a)) == 0 );
		t( sp_setstring(o, "key_b", &doc.key_b, sizeof(doc.key_b)) == 0 );
		t( sp_setstring(o, "value", &doc, sizeof(doc)) == 0 );
		t( sp_set(db, o) == 0 );
		print_current(i);
	}

	i = 0;
	void *o = sp_object(db);
	t( o != NULL );
	void *cursor = sp_cursor(env);
	t( cursor != NULL );
	while ((o = sp_get(cursor, o))) {
		int valuesize = 0;
		struct document *ret =
			(struct document*)sp_getstring(o, "value", &valuesize);
		t( valuesize == sizeof(doc) );
		t( ret->key_a == i );
		t( ret->key_b == i );
		print_current(i);
		i++;
	}
	sp_destroy(cursor);
	t( i == n );

	t( sp_destroy(env) == 0 );
}
 void destroy() {
     sp_eqfil_destroy(&eqfil);
     sp_destroy(&sp);
 }
Пример #24
0
static void
mt_set_checkpoint_get(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 1) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.sync", 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	char value[100];
	memset(value, 0, sizeof(value));
	uint32_t n = 300000;
	uint32_t i, k;
	srand(82351);
	for (i = 0; i < n; i++) {
		k = rand();
		*(uint32_t*)value = k;
		void *o = sp_object(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &k, sizeof(k)) == 0 );
		t( sp_setstring(o, "value", value, sizeof(value)) == 0 );
		t( sp_set(db, o) == 0 );
		print_current(i);
	}
	t( sp_setint(env, "log.rotate", 0) == 0 );
	t( sp_setint(env, "scheduler.checkpoint", 0) == 0 );
	fprintf(st_r.output, " (checkpoint..");
	for (;;) {
		int active = sp_getint(env, "scheduler.checkpoint_active");
		if (!active)
			break;
	}
	fprintf(st_r.output, "done)");

	/* This works only with thread = 1.
	 *
	 * Real data flush can happed before index got
	 * collected and any other worker trigger
	 * checkpoint complete.
	*/
	t( sp_setint(env, "log.gc", 0) == 0 );
	t( sp_getint(env, "log.files") == 1 );

	srand(82351);
	for (i = 0; i < n; i++) {
		k = rand();
		void *o = sp_object(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &k, sizeof(k)) == 0 );
		o = sp_get(db, o);
		t( o != NULL );
		t( *(uint32_t*)sp_getstring(o, "value", NULL) == k );
		sp_destroy(o);
		print_current(i);
	}

	t( sp_destroy(env) == 0 );
}
Пример #25
0
static void
basic_test()
{
	int ret;
	struct sorted_points *sp1;
	struct sorted_points *sp2;
	struct point p1;

	srand(0);
	sp1 = sp_init();
	sp2 = sp_init();

	// empty list checks
	ret = sp_remove_by_index(sp1, 1, &p1);
	assert(!ret);
	ret = sp_remove_by_index(sp1, 0, &p1);
	assert(!ret);
	ret = sp_remove_by_index(sp1, -1, &p1);
	assert(!ret);
	ret = sp_remove_first(sp1, &p1);
	assert(!ret);
	ret = sp_remove_last(sp1, &p1);
	assert(!ret);

	ret = sp_add_point(sp1, 1.0, 1.0);
	assert(ret);
	ret = sp_add_point(sp1, 1.0, 1.0);
	assert(ret);
	ret = sp_add_point(sp1, 1.0, 1.0);
	assert(ret);

	ret = sp_add_point(sp2, 3.0, 1.0);
	assert(ret);
	ret = sp_add_point(sp2, 2.0, 1.0);
	assert(ret);
	ret = sp_add_point(sp2, 1.0, 1.0);
	assert(ret);

	ret = sp_add_point(sp1, 2.0, 2.0);
	assert(ret);
	ret = sp_add_point(sp1, 2.0, 2.0);
	assert(ret);
	ret = sp_add_point(sp1, 4.0, 3.0);
	assert(ret);
	ret = sp_add_point(sp1, 2.0, 2.0);
	assert(ret);

	ret = sp_remove_last(sp1, &p1);
	assert(ret);
	assert(point_X(&p1) == 4.0);
	assert(point_Y(&p1) == 3.0);

	ret = sp_remove_first(sp1, &p1);
	assert(ret);
	assert(point_X(&p1) == 1.0);
	assert(point_Y(&p1) == 1.0);

	ret = sp_remove_by_index(sp1, 2, &p1);
	assert(ret);
	assert(point_X(&p1) == 2.0);
	assert(point_Y(&p1) == 2.0);

	ret = sp_add_point(sp1, 2.0, 2.0);
	assert(ret);
	ret = sp_add_point(sp1, 2.0, 2.0);
	assert(ret);
	ret = sp_add_point(sp1, 2.0, 2.0);
	assert(ret);

	ret = sp_remove_first(sp1, &p1);
	assert(ret);
	assert(point_X(&p1) == 1.0);
	assert(point_Y(&p1) == 1.0);

	ret = sp_delete_duplicates(sp1);
	assert(ret == 4);

	ret = sp_remove_first(sp1, &p1);
	assert(ret);
	assert(point_X(&p1) == 1.0);
	assert(point_Y(&p1) == 1.0);

	ret = sp_remove_first(sp1, &p1);
	assert(ret);
	assert(point_X(&p1) == 2.0);
	assert(point_Y(&p1) == 2.0);

	ret = sp_remove_first(sp1, &p1);
	assert(!ret);

	ret = sp_delete_duplicates(sp2);
	assert(ret == 0);

	ret = sp_add_point(sp2, 5.0, 2.0);
	assert(ret);
	ret = sp_add_point(sp2, 6.0, 3.0);
	assert(ret);
	ret = sp_add_point(sp2, 7.0, 4.0);
	assert(ret);
	ret = sp_add_point(sp2, 0.0, 1.0);
	assert(ret);

	ret = sp_remove_by_index(sp2, 5, &p1);
	assert(ret);
	assert(point_X(&p1) == 6.0);
	assert(point_Y(&p1) == 3.0);

	ret = sp_remove_by_index(sp2, 5, &p1);
	assert(ret);
	assert(point_X(&p1) == 7.0);
	assert(point_Y(&p1) == 4.0);

	ret = sp_remove_by_index(sp2, 5, &p1);
	assert(!ret);

	ret = sp_remove_by_index(sp2, 0, &p1);
	assert(ret);
	assert(point_X(&p1) == 0.0);
	assert(point_Y(&p1) == 1.0);

	sp_destroy(sp1);
	sp_destroy(sp2);
}
Пример #26
0
static void
get_oldest_test1(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(env) == 0 );
	void *db = sp_getobject(env, "db.test");

	uint32_t key = 7;
	uint32_t value = 1;
	void *o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );

	key = 8;
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );

	t( sp_setint(env, "db.test.branch", 0) == 0 );
	t( sp_setint(env, "db.test.compact", 0) == 0 );

	value = 2;
	key = 7;
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );

	key = 8;
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
	t( sp_set(db, o) == 0 );

	t( sp_setint(env, "db.test.branch", 0) == 0 );

	/* default */
	o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	o = sp_get(db, o);
	t( o != NULL );
	t( *(int*)sp_getstring(o, "value", NULL) == 2 );
	sp_destroy(o);

	/* oldest only */
	o = sp_document(db);
	t( o != NULL );
	t( sp_setint(o, "oldest_only", 1) == 0 );
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	o = sp_get(db, o);
	t( o != NULL );
	t( *(int*)sp_getstring(o, "value", NULL) == 1 );
	sp_destroy(o);

	t( sp_destroy(env) == 0 );
}
 void destroy() {
     sp_adsr_destroy(&adsr);
     sp_destroy(&sp);
 }
 void destroy() {
     sp_butbr_destroy(&butbr);
     sp_destroy(&sp);
 }
Пример #29
0
 void destroy() {
     sp_clip_destroy(&clip);
     sp_destroy(&sp);
 }
 void destroy() {
     sp_butbp_destroy(&butbp);
     sp_destroy(&sp);
 }