예제 #1
0
static void
snapshot_create_delete(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 );

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

	t( sp_destroy(env) == 0 );
}
예제 #2
0
static void
shutdown_transaction1(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_open(env) == 0 );

	void *txn = sp_begin(env);
	t( txn != NULL );

	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 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(db) == 0 );

	sp_destroy(db); /* unref */
	sp_destroy(db); /* schedule shutdown, unlink */

	void *dbp = sp_getobject(env, "db.test");
	t( dbp == NULL );

	/* process shutdown, txn not binded */
	t( sp_setint(env, "scheduler.run", 0) == 1 );
	t( sp_destroy(txn) == 0 );

	t( sp_destroy(env) == 0 );
}
예제 #3
0
파일: github.test.c 프로젝트: leitao/sophia
static void
github_123(void)
{
	rmrf("./abc");
	rmrf("./abc_log");

	void *env = sp_env();
	t( env != NULL );

	char path[] = { '.', '/', 'a', 'b', 'c' };
	char path_log[] = { '.', '/', 'a', 'b', 'c', '_', 'l', 'o', 'g' };
	char name[] = { 't', 'e', 's', 't' };

	t( sp_setstring(env, "sophia.path", path, sizeof(path)) == 0 );
	t( sp_setstring(env, "db", name, sizeof(name)) == 0 );
	t( sp_setstring(env, "log.path", path_log, sizeof(path_log)) == 0 );
	t( sp_setstring(env, "view", name, sizeof(name)) == 0 );
	t( sp_open(env) == 0 );

	t( exists("./", "abc") == 1 );
	t( exists("./", "abc_log") == 1 );

	void *db = sp_getobject(env, "db.test");
	t( db != NULL );

	void *view = sp_getobject(env, "view.test");
	t( view != NULL );

	t( sp_destroy(env) == 0 );

	rmrf("./abc");
	rmrf("./abc_log");
}
예제 #4
0
static void
drop_test(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_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 );

	void *txn = sp_begin(env);
	t( txn != NULL );

	sp_destroy(db); /* unref */
	t( sp_drop(db) == 0); /* scheduler drop */

	void *dbp = sp_getobject(env, "db.test");
	t( dbp == NULL );

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

	t( exists(st_r.conf->db_dir, "") == 1 );
	t( sp_setint(env, "scheduler.run", 0) == 1 ); /* proceed drop */
	t( exists(st_r.conf->db_dir, "") == 0 );

	t( sp_destroy(env) == 0 );
}
예제 #5
0
static void
scheme_test0(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.compression_cold", "zstd", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "key_b", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key_b", "string,key(1)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 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 );
	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.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 );
	db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	char *v = sp_getstring(env, "db.test.compression_cold", 0);
	t( v != NULL );
	t( strcmp(v, "zstd") == 0 );
	free(v);

	v = sp_getstring(env, "db.test.scheme.key", 0);
	t( v != NULL );
	t( strcmp(v, "u32,key(0)") == 0 );
	free(v);

	v = sp_getstring(env, "db.test.scheme.key_b", 0);
	t( v != NULL );
	t( strcmp(v, "string,key(1)") == 0 );
	free(v);

	v = sp_getstring(env, "db.test.scheme.value", 0);
	t( v != NULL );
	t( strcmp(v, "string") == 0 );
	free(v);

	t( sp_destroy(env) == 0 );
}
예제 #6
0
static void
secondary_index_test0(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, "compaction.0.branch_wm", 1) == 0 );

	/* unique */
	t( sp_setstring(env, "db", "primary", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme", "a", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme.a", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme", "b", 0) == 0 );
	t( sp_setstring(env, "db.primary.scheme.b", "u32", 0) == 0 );
	t( sp_setint(env, "db.primary.sync", 0) == 0 );

	/* non-unique */
	t( sp_setstring(env, "db", "secondary", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme", "a", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme.a", "u32,key(1)", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme", "b", 0) == 0 );
	t( sp_setstring(env, "db.secondary.scheme.b", "u32,key(0)", 0) == 0 );
	t( sp_setint(env, "db.secondary.sync", 0) == 0 );

	void *primary = sp_getobject(env, "db.primary");
	void *secondary = sp_getobject(env, "db.secondary");

	t( primary != NULL );
	t( secondary != NULL );

	t( sp_open(env) == 0 );

	void *tx = sp_begin(env);
	uint32_t a = 0;
	uint32_t b = 0;
	void *po = sp_document(primary);
	sp_setstring(po, "a", &a, sizeof(a));
	sp_setstring(po, "b", &b, sizeof(b));
	t( sp_open(po) == 0 );
	t( sp_set(tx, po) == 0 );
	void *so = sp_document(secondary);
	t( sp_setobject(so, "reuse", po) == 0 );
	t( sp_set(tx, so) == 0 );
	t( sp_commit(tx) == 0 );
	sp_destroy(po);

	t( sp_getint(env, "performance.documents") == 1 );

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

	sp_destroy(env);
}
예제 #7
0
static void
ddl_open_online0(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_destroy(s0) == 0 );
	t( sp_destroy(s0) == 0 ); /* shutdown */

	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 );
	/* ban open existing databases */
	s0 = sp_getobject(env, "db.s0");
	t( s0 != NULL );
	t( sp_open(s0) == -1 );

	t( sp_destroy(env) == 0 );

	rmrf("./logdir");
	rmrf("./dir0");
	rmrf("./dir1");
}
예제 #8
0
static void
snapshot_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 );
	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;
	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 );
}
예제 #9
0
파일: npr.test.c 프로젝트: dongxu-pc/sophia
static void
npr_test0(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, "sophia.recover", 3) == 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, "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.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 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 );

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

	t( sp_open(env) == 0 ); /* 2nd state */
	/* recover */

	t( sp_setstring(env, "db", "test2", 0) == 0 );
	t( sp_setint(env, "db.test2.sync", 0) == 0 );
	db = sp_getobject(env, "db.test2");
	t( db != NULL );
	t( sp_open(db) == 0 );
	v = sp_getstring(env, "db.test2.status", NULL);
	t( strcmp(v, "online") == 0 );
	free(v);

	t( sp_open(env) == 0 ); /* 3nd state */
	/* online */
	t( sp_open(env) == 0 ); /* N states */
	/* recover */
	t( sp_open(env) == 0 ); /* ... */
	/* online */

	t( sp_destroy(db) == 0 );
	t( sp_destroy(env) == 0 );
}
예제 #10
0
static void
mt_single_stmt(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", 3) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_setint(env, "log.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 );

	ssthreadpool p;
	ss_threadpool_init(&p);
	t( ss_threadpool_new(&p, &st_r.a, 5, single_stmt_thread, db) == 0 );
	t( ss_threadpool_shutdown(&p, &st_r.a) == 0 );

	t (sp_getint(env, "db.test.index.count") == 100000 );

	t( sp_destroy(env) == 0 );
}
예제 #11
0
static void
mt_multi_stmt_conflict0(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", 3) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_setint(env, "log.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 );
	/* conflict source */
	t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 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 );

	ssthreadpool p;
	ss_threadpool_init(&p);
	void *ptr[2] = { env, db };
	t( ss_threadpool_new(&p, &st_r.a, 5, multi_stmt_conflict_thread0, ptr) == 0 );
	t( ss_threadpool_shutdown(&p, &st_r.a) == 0 );

	t( sp_destroy(env) == 0 );
}
예제 #12
0
static void
meta_db(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, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key_b", 0) == 0 );
	t( sp_setint(env, "db.test.id", 777) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(env) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	char *s = sp_getstring(db, "name",  NULL);
	t( strcmp(s, "test") == 0 );
	free(s);
	t( sp_getint(db, "id") == 777 );
	t( sp_getint(db, "key-count") == 2 );
	s = sp_getstring(env, "db.test.index.key", 0);
	t( s != NULL );
	t( strcmp(s, "string") == 0 );
	free(s);
	s = sp_getstring(env, "db.test.index.key_b", 0);
	t( s != NULL );
	t( strcmp(s, "string") == 0 );
	free(s);
	t( sp_destroy(env) == 0 );
}
예제 #13
0
static void
transaction_batch_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_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 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 );

	void *tx = sp_begin(env);
	t( tx != NULL );

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

	t( sp_setstring(tx, "isolation", "batch", 0) == -1 );
	t( sp_destroy(tx) == 0 );

	t( sp_destroy(env) == 0 );
}
예제 #14
0
파일: github.test.c 프로젝트: leitao/sophia
static void
github_118(void)
{
	void *env = sp_env();
	t( env != NULL );

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

	unsigned key = 123456;

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

	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);

	t( sp_getint(env, "db.test.index.count") == 1 );
	char *sz = sp_getstring(env, "db.test.index.temperature_histogram", NULL);
	t( strcmp(sz, "[0]:1-1 ") == 0 );
	free(sz);

	t( sp_destroy(db) == 0 );
	t( sp_destroy(env) == 0 );
}
예제 #15
0
static void
batch_set_commit(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 );

	void *batch = sp_batch(db);
	t( batch != NULL );

	int key = 123;
	void *o = sp_object(db);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &key, sizeof(key)) == 0 );
	t( sp_set(batch, o) == 0 );
	t( sp_commit(batch) == 0 );

	t( sp_destroy(env) == 0 );
}
예제 #16
0
static void
ddl_constraint(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_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.index", "key-2", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key-3", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key-4", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key-5", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key-6", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key-7", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key-8", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key-9", 0) == -1 );
	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_destroy(env) == 0 );
}
예제 #17
0
static void
mt_quota_checkpoint(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.limit", 524288) == 0 ); /* 512k */
	/* use default settings */
	t( sp_setint(env, "scheduler.threads", 5) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_setint(env, "log.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 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	char value[1000];
	memset(value, 0, sizeof(value));
	int i = 0;
	while (i < 20000) { /* ~ 20Mb */
		void *o = sp_object(db);
		assert(o != NULL);
		sp_setstring(o, "key", &i, sizeof(i));
		sp_setstring(o, "value", value, sizeof(value));
		int rc = sp_set(db, o);
		t( rc == 0 );
		i++;
	}
	t( sp_destroy(env) == 0 );
}
예제 #18
0
파일: leak.test.c 프로젝트: ifzz/sophia
static void
leak_set(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_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 = 123;
	void *o = sp_document(db);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_set(db, o) == 0 );

	key = 124;
	o = sp_document(db);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_set(db, o) == 0 );

	t( sp_getint(env, "performance.documents") == 2 );
	t( sp_setint(env, "db.test.branch", 0) == 0 );
	t( sp_getint(env, "performance.documents") == 0 );

	t( sp_destroy(env) == 0 );
}
예제 #19
0
static void
mt_multi_stmt(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", 3) == 0 );
	t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_setint(env, "log.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 );

	seworkerpool p;
	se_workerpool_init(&p);
	void *ptr[2] = { env, db };
	t( se_workerpool_new(&p, &st_r.r, 5, multi_stmt_thread, ptr) == 0 );
	t( se_workerpool_shutdown(&p, &st_r.r) == 0 );

	t (sp_getint(env, "db.test.index.count") == 100000 );

	t( sp_destroy(env) == 0 );
}
예제 #20
0
static void
meta_empty_key(void)
{
	void *env = sp_env();
	t( env != NULL );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setint(env, "log.enable", 0) == 0 );
	t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	void *o = sp_object(db);
	t( sp_setstring(o, "key", "", 0) == 0 );
	t( sp_set(db, o) == 0 );

	o = sp_object(db);
	t( sp_setstring(o, "key", "", 0) == 0 );
	o = sp_get(db, o);
	t( o != NULL );

	int key_size;
	void *key = sp_getstring(o, "key", &key_size);
	t( key_size == 0 );
	t( key != NULL );
	sp_destroy(o);

	t( sp_destroy(env) == 0 );
}
예제 #21
0
static void
object_readonly1(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_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 = 7;
	void *o = sp_object(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 );
	o = sp_object(db);
	t( o != NULL );
	t( sp_setstring(o, "order", ">", 0) == 0 );
	void *c = sp_cursor(db, o);
	o = sp_get(c, NULL);
	t( o != NULL );
	t( sp_setstring(o, "key", &key, sizeof(key)) == -1 );
	sp_destroy(o);
	sp_destroy(c);

	sp_destroy(env);
}
예제 #22
0
static void
meta_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, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.index", "key_b", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(env) == 0 );
	t( sp_setstring(env, "snapshot", "test_snapshot0", 0) == 0 );

	fprintf(st_r.output, "\n");

	void *cur = sp_getobject(env, NULL);
	t( cur != NULL );
	fprintf(st_r.output, "\n");
	void *o = NULL;
	while ((o = sp_get(cur, o))) {
		char *key = sp_getstring(o, "key", 0);
		char *value = sp_getstring(o, "value", 0);
		fprintf(st_r.output, "%s", key);
		if (value)
			fprintf(st_r.output, " = %s\n", value);
		else
			fprintf(st_r.output, " = \n");
	}
	fprintf(st_r.output, "\n");

	t( sp_destroy(cur) == 0 );
	t( sp_destroy(env) == 0 );
}
예제 #23
0
static void
object_set_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_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 = 7;
	void *o = sp_object(db);
	t(o != NULL);
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
	t( sp_setstring(o, "value", &key, sizeof(key)) == 0 );
	int size = 0;
	t( *(int*)sp_getstring(o, "key", &size) == key );
	t( size == sizeof(key) );
	t( *(int*)sp_getstring(o, "value", &size) == key );
	t( size == sizeof(key) );
	sp_destroy(o);

	sp_destroy(env);
}
예제 #24
0
파일: npr.test.c 프로젝트: dongxu-pc/sophia
static void
npr_test4(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, "sophia.recover", 3) == 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, "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.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 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_destroy(env) == 0 );
}
예제 #25
0
static void
compact_temperature(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.0.compact_mode", 1) == 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.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 );
	t( sp_setint(env, "db.test.temperature", 1) == 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;
	while (key < 20) {
		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_setint(env, "db.test.compact", 0) == 0 );

	t( sp_destroy(env) == 0 );
}
예제 #26
0
static void
compact_directio(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_setint(env, "db.test.compaction.branch_wm", 1) == 0 );
	t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_setint(env, "db.test.direct_io", 1) == 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 );

	char value[100];
	memset(value, 0, sizeof(value));

	int key = 0;
	while (key < 300000) {
		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 );
		if ((key % 10000) == 0 && key > 0) {
			if (sp_setint(env, "db.test.compaction.branch", 0) == -1) {
				char *e = sp_getstring(env, "sophia.error", NULL);
				printf("%s, %d\n", (e) ? e: "null", errno);
				t( 0 );
			}
			/*t( sp_setint(env, "db.test.compaction.branch", 0) == 0 );*/
		}
		key++;
	}

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

	key = 0;
	while (key < 1000) {
		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 );
		t( *(int*)sp_getstring(o, "key", NULL) == key );
		sp_destroy(o);
		key++;
	}

	t( sp_destroy(env) == 0 );
}
예제 #27
0
static void
shutdown_snapshot0(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_open(env) == 0 );

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

	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 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(db) == 0 );

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

	sp_destroy(db); /* unref */
	sp_destroy(db); /* schedule shutdown, unlink */

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

	void *dbp = sp_getobject(env, "db.test");
	t( dbp == NULL );

	t( sp_setint(env, "scheduler.run", 0) == 0 );
	t( sp_destroy(a) == 0 );
	t( sp_setint(env, "scheduler.run", 0) == 0 ); /* no unlink */
	t( sp_destroy(v) == 0 );
	t( sp_setint(env, "scheduler.run", 0) == 0 ); /* no unlink */
	t( sp_destroy(b) == 0 );
	t( sp_setint(env, "scheduler.run", 0) == 1 );

	t( sp_destroy(env) == 0 );
}
예제 #28
0
static void
mt_async_read(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_setint(env, "compaction.0.async", 1) == 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", "kv", 0) == 0 );
	t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	int i = 0;
	while (i < 100000) {
		void *o = sp_object(db);
		assert(o != NULL);
		sp_setstring(o, "key", &i, sizeof(i));
		int rc = sp_set(db, o);
		t( rc == 0 );
		print_current(i);
		i++;
	}
	fprintf(st_r.output, " (insert done..iterate) ");

	void *async = sp_asynchronous(db);
	t( async != NULL );

	/* trigger iteration */
	void *o = sp_object(async);
	sp_setstring(o, "order", ">=", 0);
	o = sp_get(db, o);
	t( o != NULL );
	sp_destroy(o);

	i = 0;
	while (i < 100000) {
		o = sp_poll(env);
		if (o == NULL)
			continue;
		t( strcmp(sp_getstring(o, "type", 0), "on_read") == 0 );
		t( sp_getint(o, "status") == 1 );
		t( *(int*)sp_getstring(o, "key", NULL) == i );
		o = sp_get(db, o);
		t( o != NULL );
		sp_destroy(o);
		print_current(i);
		i++;
	}
	t( i == 100000 );
	fprintf(st_r.output, "(complete)");
	t( sp_destroy(env) == 0 );
}
예제 #29
0
파일: view_db.test.c 프로젝트: ifzz/sophia
static void
view_db_test0(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.rotate_wm", 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 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == 0 );

	void *snapcur = sp_getobject(env, "db");
	t( snapcur != NULL );

	t( sp_drop(db) == 0 );
	t( sp_destroy(db) == 0 ); /* unref */
	t( sp_destroy(db) == 0 ); /* shutdown */

	t( sp_setstring(env, "db", "test2", 0) == 0 );
	void *db2 = sp_getobject(env, "db.test2");
	t( db2 != NULL );
	t( sp_open(db2) == 0 );

	void *o;
	while ((o = sp_get(snapcur, NULL))) {
		t( o == db );
	}
	sp_destroy(snapcur);

	snapcur = sp_getobject(env, "db");
	t( snapcur != NULL );
	while ((o = sp_get(snapcur, NULL))) {
		t( o == db2 );
	}
	sp_destroy(snapcur);

	t( sp_destroy(env) == 0 );
}
예제 #30
0
static void
snapshot_test2(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.sync", 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_setstring(env, "db", "t0", 0) == 0 );
	t( sp_setstring(env, "db", "t1", 0) == 0 );
	t( sp_setstring(env, "db.t0.index.key", "u32", 0) == 0 );
	t( sp_setstring(env, "db.t1.index.key", "u32", 0) == 0 );
	t( sp_setint(env, "db.t0.sync", 0) == 0 );
	t( sp_setint(env, "db.t1.sync", 0) == 0 );

	void *t0 = sp_getobject(env, "db.t0");
	t( t0 != NULL );
	void *t1 = sp_getobject(env, "db.t1");
	t( t1 != NULL );
	t( sp_open(env) == 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_setint(env, "scheduler.run", 0) == 0 );
	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 );

	t( sp_destroy(env) == 0 );
}