static void mt_multi_stmt_conflict(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.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 ); seworkerpool p; se_workerpool_init(&p); void *ptr[2] = { env, db }; t( se_workerpool_new(&p, &st_r.r, 5, multi_stmt_conflict_thread, ptr) == 0 ); t( se_workerpool_shutdown(&p, &st_r.r) == 0 ); t( sp_destroy(env) == 0 ); }
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"); }
void st_scene_open(stscene *g, stc *cx) { printf(".open"); fflush(NULL); t( sp_open(cx->env) == 0 ); }
static void meta_scheduler(void) { void *env = sp_env(); t( env != NULL ); t( sp_setint(env, "scheduler.threads", 2) == 0 ); t( sp_setint(env, "log.enable", 0) == 0 ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_getstring(env, "scheduler.0.trace", NULL) == NULL ); t( sp_open(env) == 0 ); char *v = sp_getstring(env, "scheduler.0.trace", NULL); t( v != NULL ); t( strcmp(v, "malfunction") != 0 ); free(v); v = sp_getstring(env, "scheduler.1.trace", NULL); t( v != NULL ); t( strcmp(v, "malfunction") != 0 ); free(v); v = sp_getstring(env, "scheduler.2.trace", NULL); t( v == NULL ); t( sp_destroy(env) == 0 ); }
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 ); }
static void meta_db(void) { void *env = sp_env(); t( env != NULL ); void *c = sp_ctl(env); t( c != NULL ); t( sp_set(c, "sophia.path", cx->suite->sophiadir) == 0 ); t( sp_set(c, "scheduler.threads", "0") == 0 ); t( sp_set(c, "db", "test") == 0 ); t( sp_set(c, "db.test.sync", "0") == 0 ); t( sp_open(env) == 0 ); void *db = sp_get(c, "db.test"); t( db != NULL ); void *dbctl = sp_ctl(db); t( dbctl != NULL ); void *o = sp_get(dbctl, "name"); t( o != NULL ); t( strcmp(sp_get(o, "value", NULL), "test") == 0 ); sp_destroy(o); o = sp_get(dbctl, "id"); t( o != NULL ); t( strcmp(sp_get(o, "value", NULL), "1") == 0 ); sp_destroy(o); t( sp_destroy(env) == 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 ); printf("\n"); void *o; void *cur = sp_cursor(env, NULL); t( cur != NULL ); printf("\n"); while ((o = sp_get(cur, NULL))) { char *key = sp_getstring(o, "key", 0); char *value = sp_getstring(o, "value", 0); printf("%s", key); if (value) printf(" = %s\n", value); else printf(" = \n"); sp_destroy(o); } t( sp_destroy(cur) == 0 ); t( sp_destroy(env) == 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_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_setint(env, "db.test.compaction.compact_mode", 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.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.compaction.branch", 0) == 0 ); t( sp_setint(env, "db.test.compaction.compact", 0) == 0 ); t( sp_destroy(env) == 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 ); }
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 ); }
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_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.scheme", "key-1", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key-2", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key-3", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key-4", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key-5", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key-6", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key-7", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key-8", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key-9", 0) == -1 ); t( sp_setstring(env, "db.test.scheme.key-1", "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 ); t( sp_destroy(env) == 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 ); }
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 ); seworkerpool p; se_workerpool_init(&p); t( se_workerpool_new(&p, &st_r.r, 5, single_stmt_thread, db) == 0 ); t( se_workerpool_shutdown(&p, &st_r.r) == 0 ); t (sp_getint(env, "db.test.index.count") == 100000 ); t( sp_destroy(env) == 0 ); }
static void multi_process_2(void) { void *env = sp_env(); t( env != NULL ); t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0 ); t( sp_ctl(env, SPCMP, cmp, NULL) == 0 ); void *db = sp_open(env); t( db != NULL ); void *env2 = sp_env(); t( env != NULL ); t( sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep2) == 0 ); t( sp_ctl(env2, SPCMP, cmp, NULL) == 0 ); uint32_t k = 1; size_t vsize = 0; void *vp = NULL; int pid = fork(); t( pid != -1 ); if (pid == 0) { void *db2 = sp_open(env2); t( db2 != NULL ); t( sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0 ); t( sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1 ); t( vsize == sizeof(k) ); t( *(uint32_t*)vp == k ); free(vp); t( sp_destroy(db2) == 0 ); t( sp_destroy(env2) == 0 ); t( rmrf(dbrep2) == 0 ); /* valgrind: parent db and env are unfreed here, and that * is correct otherwise destroy would * corrupt the database. */ exit(0); } k = 3; t( sp_set(db, &k, sizeof(k), &k, sizeof(k)) == 0 ); t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 ); t( vsize == sizeof(k) ); t( *(uint32_t*)vp == k ); free(vp); t( sp_destroy(db) == 0 ); t( sp_destroy(env) == 0 ); t( rmrf(dbrep1) == 0 ); int status = 0; t( waitpid(pid, &status, 0) == pid ); t( status == 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 ); }
static void single_process(void) { void *env = sp_env(); t( env != NULL ); t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0 ); void *db = sp_open(env); t( db != NULL ); void *env2 = sp_env(); t( env2 != NULL ); t( sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0 ); void *db2 = sp_open(env2); t( db2 == NULL ); t( sp_destroy(env2) == 0 ); t( sp_destroy(db) == 0 ); t( sp_destroy(env) == 0 ); rmrf(dbrep1); }
static void meta_validation(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_open(env) == 0 ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == -1 ); t( sp_setint(env, "memory.limit", 0) == -1 ); t( sp_setint(env, "compaction.page_size", 0) == -1 ); t( sp_setint(env, "compaction.node_size", 0) == -1 ); t( sp_setint(env, "scheduler.threads", 0) == -1 ); t( sp_setint(env, "log.enable", 0) == -1 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == -1 ); t( sp_setint(env, "log.sync", 0) == -1 ); t( sp_setint(env, "log.rotate_wm", 0) == -1 ); t( sp_setint(env, "log.rotate_sync", 0) == -1 ); t( sp_setint(env, "log.two_phase_commit", 0) == -1 ); t( sp_setint(env, "log.commit_lsn", 0) == -1 ); 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_open(db) == 0 ); t( sp_setstring(env, "db.test.path", "path", 0) == -1 ); t( sp_setstring(env, "db.test.index.key", NULL, 0) == -1 ); void *o = sp_object(db); t( o != NULL ); char key[65000]; memset(key, 0, sizeof(key)); t( sp_setstring(o, "key", key, sizeof(key)) == -1 ); t( sp_setstring(o, "key", key, (1 << 15)) == 0 ); t( sp_setstring(o, "value", key, (1 << 21) + 1 ) == -1 ); t( sp_setstring(o, "value", key, (1 << 21)) == 0 ); t( sp_destroy(env) == 0 ); }
static void repository_empty(void) { void *env = sp_env(); t( env != NULL ); t( sp_open(env) == -1 ); t( sp_destroy(env) == 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 ); }
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 ); }
static void leak_tx_tx_tx_set_get_commit1(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 ); void *a = sp_begin(env); t( a != NULL ); void *b = sp_begin(env); t( b != NULL ); void *c = sp_begin(env); t( c != NULL ); int key = 123; void *o = sp_document(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(c, o) == 0 ); t( sp_getint(env, "performance.documents") == 1 ); t( sp_commit(c) == 0 ); t( sp_getint(env, "performance.documents") == 1 ); key = 124; o = sp_document(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(b, o) == 0 ); t( sp_getint(env, "performance.documents") == 2 ); t( sp_commit(b) == 0 ); t( sp_getint(env, "performance.documents") == 2 ); key = 125; o = sp_document(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(a, o) == 0 ); t( sp_getint(env, "performance.documents") == 3 ); t( sp_commit(a) == 0 ); t( sp_getint(env, "performance.documents") == 3 ); t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_getint(env, "performance.documents") == 0 ); t( sp_destroy(env) == 0 ); }
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 ); }
static void ddl_create_online0(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 ); t( sp_destroy(env) == 0 ); }
static void compact_delete1(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.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 ); 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 ); key = 0; while (key < 20) { void *o = sp_document(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 ); void *o = sp_document(db); t( o != NULL ); void *cur = sp_cursor(env); t( o != NULL ); int i = 0; while ((o = sp_get(cur, o))) { t( *(int*)sp_getstring(o, "key", NULL) == i ); i++; } t( i == 0 ); t( sp_destroy(env) == 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); }
static void amqf_test3(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", 1) == 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 < 100) { 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 = 300; while (i < 500) { 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 ); t( sp_setint(env, "db.test.compact", 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") == 232 ); t( sp_destroy(env) == 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); }
static void checkpoint_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.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.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(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, "log.rotate", 0) == 0 ); t( sp_getint(env, "log.files") == 2 ); key = 40; while (key < 80) { 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, "log.rotate", 0) == 0 ); t( sp_getint(env, "log.files") == 3 ); t( sp_setint(env, "db.test.compaction.checkpoint", 0) == 0 ); t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_getint(env, "log.files") == 1 ); t( sp_destroy(env) == 0 ); }
static void mt_set_get_kv_multipart(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.compression_key", 1) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "string", 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 ); uint32_t n = 500000; uint32_t i; char key_a[] = "very_long_long_key_part"; srand(82351); for (i = 0; i < n; i++) { uint32_t key_b = rand(); uint32_t value = key_b; void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", key_a, sizeof(key_a)) == 0 ); t( sp_setstring(o, "key_b", &key_b, sizeof(key_b)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); print_current(i); } srand(82351); for (i = 0; i < n; i++) { uint32_t key_b = rand(); uint32_t value = key_b; void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", key_a, sizeof(key_a)) == 0 ); t( sp_setstring(o, "key_b", &key_b, sizeof(key_b)) == 0 ); o = sp_get(db, o); t( o != NULL ); int size = 0; t( memcmp(sp_getstring(o, "key", &size), key_a, sizeof(key_a)) == 0 ); t( *(uint32_t*)sp_getstring(o, "key_b", &size) == key_b ); t( *(uint32_t*)sp_getstring(o, "value", &size) == value ); sp_destroy(o); print_current(i); } t( sp_destroy(env) == 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; }