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 ); }
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 ); }
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 ); t( sp_setint(env, "db.test.temperature", 1) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); int key = 0; while (key < 10) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_getint(env, "scheduler.anticache_active") == 0 ); t( sp_getint(env, "scheduler.anticache_asn") == 0 ); t( sp_getint(env, "scheduler.anticache_asn_last") == 0 ); t( sp_setint(env, "scheduler.anticache", 0) == 0 ); t( sp_getint(env, "scheduler.anticache_active") == 1 ); t( sp_getint(env, "scheduler.anticache_asn") == 1 ); t( sp_getint(env, "scheduler.anticache_asn_last") == 0 ); int rc; while ( (rc = sp_setint(env, "scheduler.run", 0)) > 0 ); t( rc == 0 ); t( sp_getint(env, "scheduler.anticache_active") == 0 ); t( sp_getint(env, "scheduler.anticache_asn") == 0 ); t( sp_getint(env, "scheduler.anticache_asn_last") == 1 ); 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 ); }
static void meta_error_injection(void) { void *env = sp_env(); t( env != NULL ); t( sp_getint(env, "debug.error_injection.si_branch_0") == 0 ); t( sp_setint(env, "debug.error_injection.si_branch_0", 1) == 0 ); t( sp_getint(env, "debug.error_injection.si_branch_0") == 1 ); t( sp_destroy(env) == 0 ); }
static void checkpoint_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", "test", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_open(env) == 0 ); t( sp_getint(env, "db.test.scheduler.checkpoint") == 0 ); t( sp_getint(env, "db.test.scheduler.checkpoint_lsn") == 0 ); t( sp_getint(env, "db.test.scheduler.checkpoint_lsn_last") == 0 ); t( sp_setint(env, "db.test.compaction.checkpoint", 0) == 0 ); t( sp_getint(env, "db.test.scheduler.checkpoint") == 1 ); t( sp_getint(env, "db.test.scheduler.checkpoint_lsn") == 0 ); t( sp_getint(env, "db.test.scheduler.checkpoint_lsn_last") == 0 ); t( sp_setint(env, "scheduler.run", 0) == 0 ); t( sp_setint(env, "scheduler.run", 0) == 0 ); t( sp_getint(env, "db.test.scheduler.checkpoint") == 0 ); t( sp_getint(env, "db.test.scheduler.checkpoint_lsn") == 0 ); t( sp_getint(env, "db.test.scheduler.checkpoint_lsn_last") == 0 ); t( sp_destroy(env) == 0 ); }
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 cache_test1(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 ); i = 185; while (i < 370) { 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( i == 370 ); t( sp_setint(env, "db.test.branch", 0) == 0 ); void *cur = sp_cursor(env); t( cur != NULL ); void *o = sp_object(db); i = 0; while ((o = sp_get(cur, o))) { t( *(int*)sp_getstring(o, "key", NULL) == i ); i++; } t( sp_destroy(cur) == 0 ); t( sp_getint(env, "db.test.index.read_disk") == 2 ); t( sp_getint(env, "db.test.index.read_cache") == 553 ); t( sp_destroy(env) == 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, "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_setint(env, "db.test.compaction.cache", 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.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 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); t( sp_getint(env, "db.test.index.node_count") == 1 ); int 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++; } t( sp_setint(env, "db.test.compaction.compact", 0) == 0 ); t( sp_getint(env, "db.test.index.count") == 100 ); i = 0; while ( i < 10 ) { 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++; } t( sp_getint(env, "db.test.index.count") == 110 ); t( sp_setint(env, "db.test.compaction.compact", 0) == 0 ); t( sp_getint(env, "db.test.index.count") == 100 ); 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 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 ); }
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 ); }
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 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 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); }
static void meta_compaction(void) { void *env = sp_env(); t( env != NULL ); t( sp_setint(env, "compaction", 58) == 0 ); t( sp_getint(env, "compaction.50.mode") == 0 ); char path[64]; int i = 10; while (i < 100) { t( sp_setint(env, "compaction", i) == 0 ); i += 10; } i = 10; while (i < 100) { snprintf(path, sizeof(path), "compaction.%d.branch_wm", i); t( sp_getint(env, path) >= 0 ); i += 10; } t( sp_destroy(env) == 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 ); }
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.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_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, "sophia.status", NULL); t( strcmp(sz, "online") == 0 ); free(sz); t( sp_destroy(env) == 0 ); }
static void backup_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, "backup.path", st_r.conf->backup_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int i = 0; while ( i < 100 ) { void *o = sp_object(db); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); t( sp_setstring(o, "value", &i, sizeof(i)) == 0 ); t( sp_set(db, o) == 0 ); i++; } t( sp_getint(env, "backup.active") == 0 ); t( sp_setint(env, "backup.run", 0) == 0 ); /* state 0 */ t( sp_getint(env, "backup.active") == 1 ); /* state 1 + 2 */ t( sp_setint(env, "scheduler.run", 0) == 1 ); /* index backup completion */ t( sp_setint(env, "scheduler.run", 0) == 1 ); /* state 3 */ t( sp_setint(env, "scheduler.run", 0) == 0 ); t( sp_getint(env, "backup.active") == 0 ); t( sp_getint(env, "backup.last") == 1 ); t( sp_getint(env, "backup.last_complete") == 1 ); t( sp_destroy(env) == 0 ); /* recover backup */ char path[1024]; snprintf(path, sizeof(path), "%s/1", st_r.conf->backup_dir); env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", path, 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, "backup.path", st_r.conf->backup_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 ); db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); /* ensure correct bsn recover */ t( sp_getint(env, "metric.bsn") == 1 ); void *o = sp_object(db); t( o != NULL ); void *cur = sp_cursor(env); t( cur != NULL ); i = 0; while ((o = sp_get(cur, o))) { t( *(int*)sp_getstring(o, "key", NULL) == i ); i++; } t( i == 100 ); t( sp_destroy(cur) == 0 ); t( sp_destroy(env) == 0 ); }
static void gc_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_setint(env, "db.test.compaction.cache", 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 ); t( sp_open(env) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); void *t0 = sp_begin(env); int value = 0; int i = 0; while ( i < 100 ) { value = i; 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++; } i = 0; while ( i < 100 ) { value = i + 1; void *o = sp_document(db); 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++; } t( sp_setint(env, "db.test.compaction.compact", 0) == 0 ); i = 0; void *o = sp_document(db); t( o != NULL ); void *cur = sp_cursor(env); while ((o = sp_get(cur, o))) { t( *(int*)sp_getstring(o, "key", NULL) == i ); t( *(int*)sp_getstring(o, "value", NULL) == i + 1); i++; } sp_destroy(cur); t( sp_getint(env, "db.test.index.count") == 200 ); t( sp_getint(env, "db.test.index.count_dup") == 100 ); t( sp_setint(env, "db.test.compaction.compact", 0) == 0 ); i = 0; o = sp_document(db); t( o != NULL ); cur = sp_cursor(env); while ((o = sp_get(cur, o))) { t( *(int*)sp_getstring(o, "key", NULL) == i ); t( *(int*)sp_getstring(o, "value", NULL) == i + 1); i++; } sp_destroy(cur); t( sp_getint(env, "db.test.index.count") == 200 ); t( sp_getint(env, "db.test.index.count_dup") == 100 ); sp_destroy(t0); t( sp_destroy(env) == 0 ); }
static void npr_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, "sophia.recover", 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.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); int key = 7; int value = 8; 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 ); t( sp_setint(env, "db.test.branch", 0) == 0 ); key = 7; value = 9; o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); t( sp_destroy(env) == 0 ); /* recover */ 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 ); /* online */ 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 ); db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); /* online */ v = sp_getstring(env, "db.test.status", NULL); t( strcmp(v, "online") == 0 ); free(v); t( sp_open(env) == 0 ); /* recover */ void *tx = sp_begin(env); t( tx != NULL ); key = 7; value = 8; o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(tx, o) == 0 ); t( sp_setint(tx, "lsn", 1) == 0 ); t( sp_commit(tx) == 0 ); /* skip */ tx = sp_begin(env); t( tx != NULL ); key = 7; value = 9; o = sp_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(tx, o) == 0 ); t( sp_setint(tx, "lsn", 2) == 0 ); t( sp_commit(tx) == 0 ); /* commit */ /* retry duplicate */ tx = sp_begin(env); t( tx != NULL ); 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(tx, o) == 0 ); t( sp_setint(tx, "lsn", 2) == 0 ); t( sp_commit(tx) == 0 ); /* skip from in-memory scheme */ /* retry duplicate with lower lsn */ tx = sp_begin(env); t( tx != NULL ); 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(tx, o) == 0 ); t( sp_setint(tx, "lsn", 1) == 0 ); t( sp_commit(tx) == 0 ); /* skip from in-memory scheme */ t( sp_open(env) == 0 ); /* online */ o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(db, o); t( o != NULL ); t( *(int*)sp_getstring(o, "value", NULL) == 9 ); t( sp_getint(o, "lsn") == 2ULL ); t( sp_destroy(o) == 0 ); t( sp_destroy(env) == 0 ); }
static void scheme_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.compression_cold", "none", 0) == 0 ); t( sp_setint(env, "db.test.compression_copy", 1) == 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_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_setint(env, "db.test.compression_copy", 1) == 0 ); t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key", "string,key(0)", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key_b", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key_b", "u64,key(1)", 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, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_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, "none") == 0 ); free(v); t( sp_getint(env, "db.test.compression_copy") == 1 ); 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); t( sp_destroy(env) == 0 ); }
static void snapshot_test1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); t( sp_open(env) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); int key = 0; while (key < 10) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_getint(env, "scheduler.snapshot_active") == 0 ); t( sp_getint(env, "scheduler.snapshot_ssn") == 0 ); t( sp_getint(env, "scheduler.snapshot_ssn_last") == 0 ); t( sp_setint(env, "scheduler.snapshot", 0) == 0 ); t( sp_getint(env, "scheduler.snapshot_active") == 1 ); t( sp_getint(env, "scheduler.snapshot_ssn") == 1 ); t( sp_getint(env, "scheduler.snapshot_ssn_last") == 0 ); t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_setint(env, "scheduler.run", 0) == 0 ); t( sp_getint(env, "scheduler.snapshot_active") == 0 ); t( sp_getint(env, "scheduler.snapshot_ssn") == 0 ); t( sp_getint(env, "scheduler.snapshot_ssn_last") == 1 ); while (key < 15) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_destroy(env) == 0 ); env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); db = sp_getobject(env, "db.test"); t( sp_open(env) == 0 ); key = 0; while (key < 10) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(db, o); t( o != NULL ); sp_destroy(o); key++; } t( sp_destroy(env) == 0 ); }
static void mt_set_snapshot_recover_get(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 5) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); char value[100]; memset(value, 0, sizeof(value)); uint32_t n = 300000; uint32_t i, k; srand(82351); for (i = 0; i < n; i++) { k = rand(); *(uint32_t*)value = k; void *o = sp_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_set(db, o) == 0 ); print_current(i); } t( sp_setint(env, "log.rotate", 0) == 0 ); t( sp_setint(env, "scheduler.snapshot", 0) == 0 ); fprintf(st_r.output, " (snapshot.."); fflush(st_r.output); for (;;) { int active = sp_getint(env, "scheduler.snapshot_active"); if (!active) break; } fprintf(st_r.output, "done)"); t( sp_destroy(env) == 0 ); fprintf(st_r.output, "(recover.."); fflush(st_r.output); 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_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 ); fprintf(st_r.output, "done)"); srand(82351); for (i = 0; i < n; i++) { k = rand(); void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &k, sizeof(k)) == 0 ); o = sp_get(db, o); t( o != NULL ); t( *(uint32_t*)sp_getstring(o, "value", NULL) == k ); sp_destroy(o); print_current(i); } t( sp_destroy(env) == 0 ); }
static void compact_delete_node1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_setint(env, "compaction.node_size", 524288 /* 512K */) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int key = 0; char value[100]; memset(value, 0, sizeof(value)); while (key < 13000) { void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); t( sp_getint(env, "db.test.index.node_count") == 2 ); key = 0; while (key < 5511 ) { void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_delete(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); t( sp_getint(env, "db.test.index.node_count") == 1 ); void *o = sp_object(db); void *cur = sp_cursor(db, o); while ((o = sp_get(cur, NULL))) { t( sp_delete(db, o) == 0 ); key++; sp_destroy(o); } sp_destroy(cur); t( key == 13000 ); t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); t( sp_getint(env, "db.test.index.node_count") == 1 ); t( sp_destroy(env) == 0 ); }
static void tpr_test1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setint(env, "log.enable", 0) == 0 ); t( sp_setint(env, "log.two_phase_recover", 1) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_open(env) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); t( sp_open(env) == 0 ); int key = 7; int value = 8; void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); t( sp_setint(env, "db.test.branch", 0) == 0 ); key = 7; value = 9; o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); t( sp_destroy(env) == 0 ); env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setint(env, "log.enable", 0) == 0 ); t( sp_setint(env, "log.two_phase_recover", 1) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_open(env) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); char *v = sp_getstring(env, "db.test.status", NULL); t( strcmp(v, "recover") == 0 ); free(v); void *tx = sp_begin(env); t( tx != NULL ); key = 7; value = 8; o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(tx, o) == 0 ); t( sp_setint(tx, "lsn", 1) == 0 ); t( sp_commit(tx) == 0 ); /* skip */ tx = sp_begin(env); t( tx != NULL ); key = 7; value = 9; o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(tx, o) == 0 ); t( sp_setint(tx, "lsn", 2) == 0 ); t( sp_commit(tx) == 0 ); /* commit */ t( sp_open(env) == 0 ); v = sp_getstring(env, "db.test.status", NULL); t( strcmp(v, "online") == 0 ); free(v); o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(db, o); t( o != NULL ); t( *(int*)sp_getstring(o, "value", NULL) == 9 ); t( sp_getint(o, "lsn") == 2ULL ); t( sp_destroy(o) == 0 ); t( sp_destroy(env) == 0 ); }
static void mt_set_checkpoint_get(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 1) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); char value[100]; memset(value, 0, sizeof(value)); uint32_t n = 300000; uint32_t i, k; srand(82351); for (i = 0; i < n; i++) { k = rand(); *(uint32_t*)value = k; void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &k, sizeof(k)) == 0 ); t( sp_setstring(o, "value", value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); print_current(i); } t( sp_setint(env, "log.rotate", 0) == 0 ); t( sp_setint(env, "scheduler.checkpoint", 0) == 0 ); fprintf(st_r.output, " (checkpoint.."); for (;;) { int active = sp_getint(env, "scheduler.checkpoint_active"); if (!active) break; } fprintf(st_r.output, "done)"); /* This works only with thread = 1. * * Real data flush can happed before index got * collected and any other worker trigger * checkpoint complete. */ t( sp_setint(env, "log.gc", 0) == 0 ); t( sp_getint(env, "log.files") == 1 ); srand(82351); for (i = 0; i < n; i++) { k = rand(); void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &k, sizeof(k)) == 0 ); o = sp_get(db, o); t( o != NULL ); t( *(uint32_t*)sp_getstring(o, "value", NULL) == k ); sp_destroy(o); print_current(i); } t( sp_destroy(env) == 0 ); }
static void snapshot_recover_get(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int i = 0; while ( i < 100 ) { void *o = sp_object(db); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); t( sp_setstring(o, "value", &i, sizeof(i)) == 0 ); t( sp_set(db, o) == 0 ); i++; } t( sp_setstring(env, "snapshot", "test_snapshot", 0) == 0 ); void *snapshot = sp_getobject(env, "snapshot.test_snapshot"); t( snapshot != NULL ); i = 0; while ( i < 100 ) { void *o = sp_object(db); int value = i + 1; t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); i++; } int64_t lsn = sp_getint(env, "snapshot.test_snapshot.lsn"); t( sp_destroy(env) == 0 ); env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); /* recover snapshot */ t( sp_setstring(env, "snapshot", "test_snapshot", 0) == 0 ); snapshot = sp_getobject(env, "snapshot.test_snapshot"); t( snapshot != NULL ); t( sp_setint(env, "snapshot.test_snapshot.lsn", lsn) == 0 ); t( sp_open(env) == 0 ); db = sp_getobject(env, "db.test"); t( db != NULL ); i = 0; while ( i < 100 ) { void *o = sp_object(db); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); o = sp_get(db, o); t( *(int*)sp_getstring(o, "value", NULL) == i + 1 ); t( sp_destroy(o) == 0 ); i++; } i = 0; while ( i < 100 ) { void *o = sp_object(db); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); o = sp_get(snapshot, o); t( *(int*)sp_getstring(o, "value", NULL) == i ); t( sp_destroy(o) == 0 ); i++; } t( sp_destroy(env) == 0 ); }
static void compact_delete_node1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_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.node_size", 716800/* 700K */) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int key = 0; char value[100]; memset(value, 0, sizeof(value)); while (key < 13000) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); t( sp_getint(env, "db.test.index.node_count") == 2 ); key = 0; while (key < 6511 ) { 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 ); t( sp_getint(env, "db.test.index.node_count") == 1 ); void *o = sp_document(db); void *cur = sp_cursor(env); while ((o = sp_get(cur, o))) { int keysize; void *keyptr = sp_getstring(o, "key", &keysize); t( *(uint32_t*)keyptr == key ); void *ko = sp_document(db); t( ko != NULL ); t( sp_setstring(ko, "key", keyptr, keysize) == 0 ); t( sp_delete(db, ko) == 0 ); key++; } sp_destroy(cur); t( key == 13000 ); t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); t( sp_getint(env, "db.test.index.node_count") == 1 ); t( sp_destroy(env) == 0 ); }