Exemplo n.º 1
0
static void
conf_validation_upsert(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_setint(env, "log.sync", 0) == 0 );
	t( sp_setint(env, "log.rotate_sync", 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_setstring(env, "db.test.index.upsert", conf_validation_upsert_op, 0) == 0 );
	t( sp_setstring(env, "db.test.format", "document", 0) == 0 );
	t( sp_open(env) == -1 );
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 2
0
static void
repository_test3(void)
{
	rmrf("./sophia");
	rmrf("./logdir");
	rmrf("./dir");
	void *env = sp_env();
	t( env != NULL );
	t( sp_setstring(env, "sophia.path", "sophia", 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.path", "dir", 0) == 0 );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(env) == 0 );
	t( exists("sophia", "log") == 1 );
	t( exists("sophia", "test") == 0 );
	t( exists("dir", "") == 1 );
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 3
0
static void
conf_validation1(void)
{
	void *env = sp_env();
	t( env != NULL );

	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setstring(env, "scheduler.threads", NULL, 0) == -1 );
	t( sp_getobject(env, "scheduler.threads") == NULL );

	t( sp_setint(env, "log.enable", 0) == 0 );
	t( sp_setstring(env, "log.enable", NULL, 0) == -1 );
	t( sp_getobject(env, "log.enable") == NULL );

	t( sp_setstring(env, "scheduler.run", NULL, 0) == 0 );
	t( sp_getobject(env, "scheduler.run") == NULL );

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 4
0
static void
anticache_promote1(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 );
	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 );
	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.anticache_active") == 0 );
	t( sp_getint(env, "scheduler.anticache_asn") == 0 );
	t( sp_getint(env, "scheduler.anticache_asn_last") == 1 );

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

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 5
0
static void
shutdown_transaction3(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 *a = sp_begin(env);
	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 );

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

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

	void *v = sp_begin(env);
	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 );
}
Exemplo n.º 6
0
static inline void *single_stmt_thread(void *arg) 
{
	ssthread *self = arg;
	void *db = self->arg;
	int i = 0;
	while (i < 20000) {
		char key[100];
		int keylen = snprintf(key, sizeof(key), "key_%" PRIiPTR "_%d",
		                      (uintptr_t)self, i);
		void *o = sp_document(db);
		assert(o != NULL);
		sp_setstring(o, "key", key, keylen + 1);
		sp_setstring(o, "value", &i, sizeof(i));
		int rc = sp_set(db, o);
		assert(rc != -1);
		i++;
	}
	return NULL;
}
Exemplo n.º 7
0
static void
cache_test0(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_setint(env, "db.test.sync", 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_open(env) == 0 );

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

	int i = 0;
	while (i < 185) {
		void *o = sp_object(db);
		t( o != NULL );
		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_setint(env, "db.test.branch", 0) == 0 );

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

	t( sp_getint(env, "db.test.index.read_disk") == 1 );
	t( sp_getint(env, "db.test.index.read_cache") == 184 );

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 8
0
static void
repository_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_open(env) == 0 );
	t( exists(st_r.conf->sophia_dir, "log") == 1 );
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 9
0
static void
multipart_cmp_eq_key(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 );

	char *v = sp_getstring(env, "db.test.index.key", 0);
	t( strcmp(v, "u32") == 0 );
	free(v);

	t( sp_open(env) == 0 );
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 10
0
static inline int
spr_cmd_start(void)
{
	/* create env */
	spr_env = sp_env();
	sp_setstring(spr_env, "sophia.path", "_test_sophia", 0);
	sp_setstring(spr_env, "backup.path", "_test_backup", 0);
	sp_setstring(spr_env, "db", "test", 0);
	spr_db = sp_getobject(spr_env, "db.test");
	int rc;
	rc = sp_open(spr_env);
	if (rc == -1) {
		sp_destroy(spr_env);
		return -1;
	}
	/* start thread */
	spr_start = 1;
	pthread_create(&spr_thread, NULL, spr_worker, NULL);
	return 0;
}
Exemplo n.º 11
0
static void
drop_test_fail_on_drop1(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_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 );

	sp_destroy(db); /* unref */
	t( sp_drop(db) == 0); /* scheduler drop */
	t( exists(st_r.conf->db_dir, "") == 1 );
	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 );
	t( sp_setint(env, "db.test.path_fail_on_drop", 1) == 0 );
	db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_open(env) == -1 ); /* fail on database dropped */
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 12
0
static inline void*
workflow_open(void *env)
{
	int rc;
	rc = sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0);
	if (rc == -1)
		return NULL;
	rc = sp_setint(env, "scheduler.threads", 0);
	if (rc == -1)
		return NULL;
	rc = sp_setint(env, "compaction.0.branch_wm", 1);
	if (rc == -1)
		return NULL;
	rc = sp_setstring(env, "log.path", st_r.conf->log_dir, 0);
	if (rc == -1)
		return NULL;
	rc = sp_setint(env, "log.sync", 0);
	if (rc == -1)
		return NULL;
	rc = sp_setstring(env, "db", "test", 0);
	if (rc == -1)
		return NULL;
	rc = sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0);
	if (rc == -1)
		return NULL;
	rc = sp_setstring(env, "db.test.compression", "lz4", 0);
	if (rc == -1)
		return NULL;
	rc = sp_setint(env, "db.test.compression_key", 1);
	if (rc == -1)
		return NULL;
	rc = sp_setstring(env, "db.test.storage", "in-memory", 0);
	if (rc == -1)
		return NULL;
	rc = sp_setstring(env, "db.test.index.key", "u32", 0);
	if (rc == -1)
		return NULL;
	rc = sp_setstring(env, "db.test.index.upsert", workflow_upsert_operator, 0);
	if (rc == -1)
		return NULL;
	rc = sp_setint(env, "db.test.sync", 0);
	if (rc == -1)
		return NULL;
	void *db = sp_getobject(env, "db.test");
	if (db == NULL)
		return NULL;
	rc = sp_open(env);
	if (rc == -1)
		return NULL;
	return db;
}
Exemplo n.º 13
0
static void
batch_db_destroy(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 );

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 14
0
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 );
}
Exemplo n.º 15
0
static void
batch_update_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_update(batch, o) == 0 );
	t( sp_commit(batch) == 0 );

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 16
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 );
}
Exemplo n.º 17
0
static void
scheme_timestamp2(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.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "ts0", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.ts0", "u32,timestamp,expire", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "ts1", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.ts1", "u32,timestamp,expire", 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) == -1 );
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 18
0
static void
scheme_timestamp0(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.scheme", "key", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme", "ts", 0) == 0 );
	t( sp_setstring(env, "db.test.scheme.ts", "u32,timestamp", 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 );

	uint32_t key = 0;
	while (key < 10) {
		void *o = sp_document(db);
		t( sp_setstring(o, "key", &key, sizeof(key)) == 0 );
		t( sp_set(db, o) == 0 );
		key++;
	}

	key = 0;
	void *o = sp_document(db);
	sp_setstring(o, "order", ">=", 0);
	void *c = sp_cursor(env);
	while ((o = sp_get(c, o))) {
		t( *(uint32_t*)sp_getstring(o, "key", NULL) == key );
		t( *(uint32_t*)sp_getstring(o, "ts", NULL) > 0 );
		key++;
	}

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 19
0
static void
shutdown_transaction2(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 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );
	t( sp_setint(env, "db.test.sync", 0) == 0 );
	t( sp_open(db) == 0 );

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

	/* shutdown properly closes used index */
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 20
0
static void
github_117(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 );
	int i = 0;
	int max = 30;
	while (i < max) {
		char name[30];
		snprintf(name, sizeof(name), "db.t_%d", i);
		t( sp_setstring(env, "db", name + 3, 0) == 0 );
		void *db = sp_getobject(env, name);
		t( db != NULL );
		i++;
	}
	t( sp_open(env) == 0 );
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 21
0
static void
mt_quota_age(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 */
	/* 100Mb branch_wm to avoid branching */
	t( sp_setint(env, "compaction.80.mode", 3) == 0 );
	t( sp_setint(env, "compaction.80.branch_wm", 104857600) == 0 );
	t( sp_setint(env, "compaction.80.branch_age_period", 1) == 0 );
	t( sp_setint(env, "compaction.80.branch_age", 1) == 0 );
	t( sp_setint(env, "compaction.80.branch_prio", 1) == 0 );
	t( sp_setint(env, "compaction.80.branch_age_wm", 500000) == 0 );
	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.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 );

	char value[1000];
	memset(value, 0, sizeof(value));
	int i = 0;
	while (i < 1000) { /* ~ 1Mb ~ 2-4 seconds */
		void *o = sp_document(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 );
}
Exemplo n.º 22
0
static void
mt_upsert0(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_open(env) == 0 );
	t( sp_setstring(env, "db", "test", 0) == 0 );
	t( sp_setstring(env, "db.test.index.upsert", upsert_op, 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 );
	uint32_t n = 400000;
	uint32_t i, k = 1234;
	uint32_t value = 1;
	for (i = 0; i < n; i++) {
		void *o = sp_document(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &k, sizeof(k)) == 0 );
		t( sp_setstring(o, "value", &value, sizeof(value)) == 0 );
		t( sp_upsert(db, o) == 0 );
		print_current(i);
	}

	void *o = sp_document(db);
	t( o != NULL );
	t( sp_setstring(o, "key", &k, sizeof(k)) == 0 );
	void *c = sp_cursor(env);
	t( c != NULL );
	o = sp_get(c, o);
	t( o != NULL );
	t( *(uint32_t*)sp_getstring(o, "value", NULL) == n);
	sp_destroy(o);
	sp_destroy(c);

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 23
0
static void
tpr_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.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 );

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

	t( sp_open(env) == 0 ); /* complete */

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

	t( sp_open(db) == -1 );

	t( sp_destroy(db) == 0 );
	t( sp_destroy(env) == 0 );
}
Exemplo n.º 24
0
static inline void *multi_stmt_conflict_thread1(void *arg)
{
	ssthread *self = arg;
	void *env = ((void**)self->arg)[0];
	void *db  = ((void**)self->arg)[1];
	int id = 1;
	int rc;
	int i = 0;
	while (i < 100) {
		rc = 0;
		do {
			void *tx = sp_begin(env);
			void *o = sp_document(db);
			sp_setstring(o, "key", &id, sizeof(id));
			o = sp_get(tx, o);
			int v = 0;
			if (o) {
				v = *(int*)sp_getstring(o, "value", NULL);
				sp_destroy(o);
			}
			v++;

			o = sp_document(db);
			sp_setstring(o, "key", &id, sizeof(id));
			sp_setstring(o, "value", &v, sizeof(v));
			rc = sp_set(tx, o);
			assert(rc == 0);

			rc = sp_commit(tx);
			if (2 == rc) sp_destroy(tx);
			assert(rc != -1);
		} while (rc != 0);
		i++;
	}
	return NULL;
}
Exemplo n.º 25
0
static void
github_120(void)
{
	/* open or create environment and database */
	void *env = sp_env();
	sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 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 */
	void *o = sp_document(db);
	sp_setstring(o, "key", "hello", 0);
	sp_setstring(o, "value", "world", 0);
	rc = sp_set(db, o);
	if (rc == -1)
		goto error;

	/* get */
	o = sp_document(db);
	sp_setstring(o, "key", "hello", 0);
	o = sp_get(db, o);
	if (o) {
		/* ensure key and value are correct */
		int size;
		char *ptr = sp_getstring(o, "key", &size);
		t( size == 5 );
		t( strncmp(ptr, "hello", 5) == 0 );

		ptr = sp_getstring(o, "value", &size);
		t( size == 5 );
		t( strncmp(ptr, "world", 5) == 0 );

		sp_destroy(o);
	}

	/* delete */
	o = sp_document(db);
	sp_setstring(o, "key", "hello", 0);
	rc = sp_delete(db, o);
	if (rc == -1)
		goto error;

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

error:;
	int size;
	char *error = sp_getstring(env, "sophia.error", &size);
	printf("error: %s\n", error);
	free(error);
	sp_destroy(env);
}
Exemplo n.º 26
0
static void
profiler_count(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_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 );
	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 );

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

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

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

	t( sp_getint(env, "db.test.index.count") == 100 );
	t( sp_getint(env, "db.test.index.branch_count") == 2 );

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

	t( sp_getint(env, "db.test.index.count") == 110 );
	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.count") == 100 );

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 27
0
static void
amqf_test0(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.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 );
	t( sp_setint(env, "db.test.amqf", 0) == 0 );
	t( sp_setint(env, "scheduler.threads", 0) == 0 );
	t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 );
	t( sp_open(env) == 0 );

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

	int i = 0;
	while (i < 200) {
		void *o = sp_document(db);
		t( o != NULL );
		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_setint(env, "db.test.branch", 0) == 0 );

	i = 0;
	while (i < 400) {
		void *o = sp_document(db);
		t( o != NULL );
		t( sp_setstring(o, "key", &i, sizeof(i)) == 0 );
		o = sp_get(db, o);
		if (o) {
			sp_destroy(o);
		}
		i++;
	}
	t( sp_getint(env, "db.test.index.read_disk") == 200 );

	t( sp_destroy(env) == 0 );
}
Exemplo n.º 28
0
int sn_storageopen(snstorage *s, snconfig *c, snlog *l)
{
	int rc;
	rc = sn_storagescheme(s, c, l);
	if (snunlikely(rc == -1))
		return -1;
	sn_storagescheme_print(s, l);
	s->env = sp_env();
	if (s->env == NULL)
		return -1;
	sp_setstring(s->env, "sophia.path", c->dir, 0);
	sp_setint(s->env, "memory.limit", c->maxmemory);
	sp_setstring(s->env, "scheduler.on_recover",
	             (void*)(uintptr_t)sn_storagerecover_cb, 0);
	sp_setstring(s->env, "scheduler.on_recover_arg", l, 0);
	int i = 0;
	while (i < s->count) {
		sndb *db = &s->storage[i];
		sp_setstring(s->env, "db", db->name, 0);
		char path[128];
		snprintf(path, sizeof(path), "db.%s.mmap", db->name);
		sp_setint(s->env, path, 1);
		if (db->path) {
			snprintf(path, sizeof(path), "db.%s.path", db->name);
			sp_setstring(s->env, path, db->path, 0);
		}
		if (db->key) {
			snprintf(path, sizeof(path), "db.%s.index.key", db->name);
			sp_setstring(s->env, path, db->key, 0);
		}
		i++;
	}
	rc = sp_open(s->env);
	if (snunlikely(rc == -1)) {
		char *error = sn_storageerror(s);
		if (error) {
			sn_log(l, "storage error: %s", error);
			free(error);
		}
		return -1;
	}
	i = 0;
	while (i < s->count) {
		sndb *db = &s->storage[i];
		char path[128];
		snprintf(path, sizeof(path), "db.%s", db->name);
		db->db = sp_getobject(s->env, path);
		if (snunlikely(db->db == NULL)) {
			sn_log(l, "failed to setupt '%s' database", db->name);
			return -1;
		}
		i++;
	}
	return 0;
}
Exemplo n.º 29
0
static void
object_lsn0(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_getint(o, "lsn") == -1 );
	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 );
	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) );
	t( sp_getint(o, "lsn") > 0 );
	t( sp_destroy(o) == 0 );
	o = sp_get(c, NULL);
	t( o == NULL );

	sp_destroy(c);
	sp_destroy(env);
}
Exemplo n.º 30
0
static void
github_97(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 );
	t( sp_open(env) == 0 );
	void *db = sp_getobject(env, "db.test");
	t( db != NULL );

	/* we must pass sizeof(uint32_t) in sp_setstring() */
	uint32_t i = 0;
	while ( i < 100 ) {
		void *o = sp_document(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++;
	}

	void *cur = sp_cursor(env);
	t( cur != NULL );

	void *o = sp_document(db);
	t( o != NULL );
	uint32_t key = 99;
	t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); /* <  */

	i = 0;
	while ((o = sp_get(cur, o)))
		i++;
	t( i == 1 );
	sp_destroy(cur);

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