static void object_readonly1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_open(env) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); int key = 7; void *o = sp_object(db); t(o != NULL); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "order", ">", 0) == 0 ); void *c = sp_cursor(db, o); o = sp_get(c, NULL); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == -1 ); sp_destroy(o); sp_destroy(c); sp_destroy(env); }
static void mt_setget(void) { char value[100]; memset(value, 0, sizeof(value)); uint32_t n = 1000000; uint32_t i, k; srand(82351); for (i = 0; i < n; i++) { k = rand(); *(uint32_t*)value = k; void *o = sp_object(st_r.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(st_r.db, o) == 0 ); print_current(i); } srand(82351); for (i = 0; i < n; i++) { k = rand(); void *o = sp_object(st_r.db); t( o != NULL ); t( sp_setstring(o, "key", &k, sizeof(k)) == 0 ); o = sp_get(st_r.db, o); t( o != NULL ); t( *(uint32_t*)sp_getstring(o, "value", NULL) == k ); sp_destroy(o); print_current(i); } }
static void batch_set_commit_get(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); 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 ); o = sp_object(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(db, o); t( o != NULL ); sp_destroy(o); t( sp_destroy(env) == 0 ); }
static void meta_empty_key(void) { void *env = sp_env(); t( env != NULL ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "log.enable", 0) == 0 ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); void *o = sp_object(db); t( sp_setstring(o, "key", "", 0) == 0 ); t( sp_set(db, o) == 0 ); o = sp_object(db); t( sp_setstring(o, "key", "", 0) == 0 ); o = sp_get(db, o); t( o != NULL ); int key_size; void *key = sp_getstring(o, "key", &key_size); t( key_size == 0 ); t( key != NULL ); sp_destroy(o); t( sp_destroy(env) == 0 ); }
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 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.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; while (key < 20) { void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); 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_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 ); void *o = sp_object(db); t( o != NULL ); void *cur = sp_cursor(db, o); t( o != NULL ); int i = 0; while ((o = sp_get(cur, NULL))) { t( *(int*)sp_getstring(o, "key", NULL) == i ); i++; sp_destroy(o); } t( i == 0 ); 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 ); }
static void mt_set_delete_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_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 value[100]; memset(value, 0, sizeof(value)); uint32_t n = 700000; 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); } 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_delete(db, o) == 0 ); print_current(i); } 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 ); print_current(i); } t( sp_destroy(env) == 0 ); }
static void multipart_cursor1(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_b", 0) == 0 ); t( sp_setstring(env, "db.test.index.key_b", "u32", 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "string", 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 ); char key_a[] = "hello"; uint32_t i = 0; while (i < 546) { void *o = sp_object(db); sp_setstring(o, "key", key_a, sizeof(key_a)); sp_setstring(o, "key_b", &i, sizeof(i)); sp_setstring(o, "value", &i, sizeof(i)); t( sp_set(db, o) == 0); i++; } i = 322; void *cur = sp_cursor(env); t( cur != NULL ); void *o = sp_object(db); sp_setstring(o, "key", key_a, sizeof(key_a)); sp_setstring(o, "key_b", &i, sizeof(i)); sp_setstring(o, "value", &i, sizeof(i)); while ((o = sp_get(cur, o))) { int asize; t( strcmp(key_a, sp_getstring(o, "key", &asize)) == 0 ); int bsize; t( *(uint32_t*)sp_getstring(o, "key_b", &bsize) == i ); int vsize; t( *(uint32_t*)sp_getstring(o, "value", &vsize) == i ); t( asize == sizeof(key_a) ); t( bsize == sizeof(i) ); t( vsize == sizeof(i) ); i++; } sp_destroy(cur); t( i == 546 ); 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 ddl_open_online0(void) { rmrf("./logdir"); rmrf("./dir0"); rmrf("./dir1"); void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_open(env) == 0 ); t( sp_setstring(env, "db", "s0", 0) == 0 ); t( sp_setstring(env, "db.s0.path", "dir0", 0) == 0 ); t( sp_setstring(env, "db.s0.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.s0.sync", 0) == 0 ); void *s0 = sp_getobject(env, "db.s0"); t( s0 != NULL ); t( sp_open(s0) == 0 ); int key = 7; void *o = sp_object(s0); sp_setstring(o, "key", &key, sizeof(key)); t( sp_set(s0, o) == 0 ); key = 8; o = sp_object(s0); sp_setstring(o, "key", &key, sizeof(key)); t( sp_set(s0, o) == 0 ); key = 9; o = sp_object(s0); sp_setstring(o, "key", &key, sizeof(key)); t( sp_set(s0, o) == 0 ); t( sp_destroy(s0) == 0 ); t( sp_destroy(s0) == 0 ); /* shutdown */ t( sp_setstring(env, "db", "s0", 0) == 0 ); t( sp_setstring(env, "db.s0.path", "dir0", 0) == 0 ); t( sp_setstring(env, "db.s0.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.s0.sync", 0) == 0 ); /* ban open existing databases */ s0 = sp_getobject(env, "db.s0"); t( s0 != NULL ); t( sp_open(s0) == -1 ); t( sp_destroy(env) == 0 ); rmrf("./logdir"); rmrf("./dir0"); rmrf("./dir1"); }
static void snapshot_get(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int i = 0; while ( i < 100 ) { void *o = sp_object(db); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); t( sp_setstring(o, "value", &i, sizeof(i)) == 0 ); t( sp_set(db, o) == 0 ); i++; } t( sp_setstring(env, "snapshot", "test_snapshot", 0) == 0 ); void *snapshot = sp_getobject(env, "snapshot.test_snapshot"); t( snapshot != NULL ); i = 0; while ( i < 100 ) { void *o = sp_object(db); int value = i + 1; t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); i++; } i = 0; while ( i < 100 ) { void *o = sp_object(db); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); o = sp_get(snapshot, o); t( *(int*)sp_getstring(o, "value", NULL) == i ); t( sp_destroy(o) == 0 ); i++; } t( sp_destroy(env) == 0 ); }
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 ); }
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_quota_checkpoint(stc *cx) { cx->env = sp_env(); t( cx->env != NULL ); void *c = sp_ctl(cx->env); t( c != NULL ); t( sp_set(c, "sophia.path", cx->suite->sophiadir) == 0 ); t( sp_set(c, "memory.limit", "524288") == 0 ); /* 512k */ /* use default settings */ t( sp_set(c, "scheduler.threads", "5") == 0 ); t( sp_set(c, "log.path", cx->suite->logdir) == 0 ); t( sp_set(c, "log.sync", "0") == 0 ); t( sp_set(c, "log.rotate_sync", "0") == 0 ); t( sp_set(c, "db", "test") == 0 ); t( sp_set(c, "db.test.path", cx->suite->dir) == 0 ); t( sp_set(c, "db.test.sync", "0") == 0 ); t( sp_set(c, "db.test.index.cmp", "u32", NULL) == 0 ); cx->db = sp_get(c, "db.test"); t( cx->db != NULL ); t( sp_open(cx->env) == 0 ); char value[1000]; memset(value, 0, sizeof(value)); int i = 0; while (i < 20000) { /* ~ 20Mb */ void *o = sp_object(cx->db); assert(o != NULL); sp_set(o, "key", &i, sizeof(i)); sp_set(o, "value", value, sizeof(value)); int rc = sp_set(cx->db, o); t( rc == 0 ); i++; } t( sp_destroy(cx->env) == 0 ); }
static inline void *multi_stmt_conflict_thread(void *arg) { soworker *self = arg; void *env = ((void**)self->arg)[0]; void *db = ((void**)self->arg)[1]; int i = 0; while (i < 2000) { int rc; void *tx = sp_begin(env); assert( tx != NULL ); int j = 0; while (j < 10) { void *o = sp_object(db); int key = i + j; assert(o != NULL); sp_set(o, "key", &key, sizeof(key)); rc = sp_set(tx, o); assert(rc != -1); j++; } rc = sp_commit(tx); assert(rc != -1); if (rc == 2) sp_destroy(tx); i++; } return NULL; }
static void object_set_get(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_open(env) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); int key = 7; void *o = sp_object(db); t(o != NULL); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); int size = 0; t( *(int*)sp_getstring(o, "key", &size) == key ); t( size == sizeof(key) ); t( *(int*)sp_getstring(o, "value", &size) == key ); t( size == sizeof(key) ); sp_destroy(o); sp_destroy(env); }
static inline void *multi_stmt_thread(void *arg) { soworker *self = arg; void *env = ((void**)self->arg)[0]; void *db = ((void**)self->arg)[1]; int i = 0; while (i < 2000) { int rc; void *tx = sp_begin(env); assert( tx != NULL ); int j = 0; while (j < 10) { char key[100]; int keylen = snprintf(key, sizeof(key), "key_%" PRIiPTR "_%d_%d", (uintptr_t)self, i, j); void *o = sp_object(db); assert(o != NULL); sp_set(o, "key", key, keylen + 1); rc = sp_set(tx, o); assert(rc != -1); j++; } rc = sp_commit(tx); assert(rc == 0); i++; } return NULL; }
static void hc_prepare_commit_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", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_open(env) == 0 ); void *db = sp_getobject(env, "db.test"); int key = 7; int rc; void *a = sp_begin(env); t( a != NULL ); void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(a, o) == 0 ); t( sp_setint(a, "half_commit", 1) == 0 ); rc = sp_commit(a); t( rc == 0 ); void *b = sp_begin(env); t( b != NULL ); o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(b, o) == 0 ); t( sp_setint(b, "half_commit", 1) == 0 ); rc = sp_commit(b); /* this should fail in default conditions */ t( rc == 0 ); rc = sp_commit(a); t( rc == 0 ); rc = sp_commit(b); t( rc == 0 ); t( sp_destroy(env) == 0 ); }
static void multipart_set_get0(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_b", 0) == 0 ); t( sp_setstring(env, "db.test.index.key_b", "u32", 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "string", 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 ); char key_a[] = "hello"; uint32_t key_b = 7; void *o = sp_object(db); sp_setstring(o, "key", key_a, sizeof(key_a)); t( sp_set(db, o) == -1 ); o = sp_object(db); sp_setstring(o, "key", key_a, sizeof(key_a)); sp_setstring(o, "key_b", &key_b, sizeof(key_b)); t( sp_set(db, o) == 0); o = sp_object(db); sp_setstring(o, "key", key_a, sizeof(key_a)); o = sp_get(db, o); t( o == NULL ); o = sp_object(db); sp_setstring(o, "key", key_a, sizeof(key_a)); sp_setstring(o, "key_b", &key_b, sizeof(key_b)); o = sp_get(db, o); t( o != NULL ); sp_destroy(o); t( sp_destroy(env) == 0 ); }
void st_scene_truncate(stscene *g, stc *cx) { printf(".truncate"); fflush(NULL); void *o = sp_object(cx->db); t( o != NULL ); void *c = sp_cursor(cx->db, o); t( c != NULL ); while ((o = sp_get(c))) { void *k = sp_object(cx->db); t( k != NULL ); int keysize; void *key = sp_get(o, "key", &keysize); sp_set(k, "key", key, keysize); t( sp_delete(cx->db, k) == 0 ); } t( sp_destroy(c) == 0 ); }
static void shutdown_transaction6(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 *a = sp_begin(env); t( a != NULL ); sp_destroy(db); /* unref */ sp_destroy(db); /* schedule shutdown, unlink */ void *o = sp_object(db); t( o != NULL ); uint32_t key = 7; t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(a, o) == 0 ); /* ok */ key = 8; o = sp_object(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == -1 ); t( sp_setint(env, "scheduler.run", 0) == 0 ); t( sp_destroy(a) == 0 ); t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_destroy(env) == 0 ); }
static void hc_prepare_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 ); t( sp_open(env) == 0 ); void *db = sp_getobject(env, "db.test"); int rc; void *tx = sp_begin(env); t( tx != NULL ); int key = 7; void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(tx, o) == 0 ); o = sp_object(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(tx, o); t( o != NULL ); t( *(int*)sp_getstring(o, "value", NULL) == key ); sp_destroy(o); t( sp_setint(tx, "half_commit", 1) == 0 ); rc = sp_commit(tx); t( rc == 0 ); rc = sp_commit(tx); t( rc == 0 ); t( sp_destroy(env) == 0 ); }
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 inline void *single_stmt_thread(void *arg) { soworker *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_object(db); assert(o != NULL); sp_set(o, "key", key, keylen + 1); sp_set(o, "value", &i, sizeof(i)); int rc = sp_set(db, o); assert(rc != -1); i++; } return NULL; }
jlong JNICALL Java_eu_unicredit_sophia_SophiaInterface_sp_1object (JNIEnv * env, jobject obj, jlongArray args) { jlong* array = (*env)->GetLongArrayElements(env, args,JNI_FALSE); jint size = (*env)->GetArrayLength(env, args); void* ret = NULL; switch(size) { case 0: printf("Not supported\n"); break; case 1: ret = sp_object((void*)array[0]); break; default: printf("Not supported\n"); break; }; return (jlong)ret; }
static void mt_quota_age(stc *cx) { cx->env = sp_env(); t( cx->env != NULL ); void *c = sp_ctl(cx->env); t( c != NULL ); t( sp_set(c, "sophia.path", cx->suite->sophiadir) == 0 ); t( sp_set(c, "memory.limit", "524288") == 0 ); /* 512k */ /* 100Mb branch_wm to avoid branching */ t( sp_set(c, "compaction.80.mode", "3") == 0 ); t( sp_set(c, "compaction.80.branch_wm", "104857600") == 0 ); t( sp_set(c, "compaction.80.branch_age_period", "1") == 0 ); t( sp_set(c, "compaction.80.branch_age", "1") == 0 ); t( sp_set(c, "compaction.80.branch_prio", "3") == 0 ); t( sp_set(c, "compaction.80.branch_age_wm", "500000") == 0 ); t( sp_set(c, "scheduler.threads", "5") == 0 ); t( sp_set(c, "log.path", cx->suite->logdir) == 0 ); t( sp_set(c, "log.sync", "0") == 0 ); t( sp_set(c, "log.rotate_sync", "0") == 0 ); t( sp_set(c, "db", "test") == 0 ); t( sp_set(c, "db.test.path", cx->suite->dir) == 0 ); t( sp_set(c, "db.test.sync", "0") == 0 ); t( sp_set(c, "db.test.index.cmp", "u32", NULL) == 0 ); cx->db = sp_get(c, "db.test"); t( cx->db != NULL ); t( sp_open(cx->env) == 0 ); char value[1000]; memset(value, 0, sizeof(value)); int i = 0; while (i < 20000) { /* ~ 20Mb */ void *o = sp_object(cx->db); assert(o != NULL); sp_set(o, "key", &i, sizeof(i)); sp_set(o, "value", value, sizeof(value)); int rc = sp_set(cx->db, o); t( rc == 0 ); i++; } t( sp_destroy(cx->env) == 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", 3) == 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.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 object_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, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_open(env) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); void *o = sp_object(db); t(o != NULL); sp_destroy(o); sp_destroy(env); }
static void get_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_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_open(env) == 0 ); void *db = sp_getobject(env, "db.test"); uint32_t key = 7; void *o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key = 8; o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); void *cursor; /* default */ cursor = sp_cursor(env); o = sp_object(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(cursor, o); t( o != NULL ); sp_destroy(o); sp_destroy(cursor); /* cache only */ cursor = sp_cursor(env); o = sp_object(db); t( o != NULL ); t( sp_setint(o, "cache_only", 1) == 0 ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(cursor, o); t( o == NULL ); sp_destroy(cursor); t( sp_setint(env, "db.test.branch", 0) == 0 ); /* start by filling cache (gte) */ cursor = sp_cursor(env); o = sp_object(db); t( o != NULL ); o = sp_get(cursor, o); t( o != NULL ); t( *(uint32_t*)sp_getstring(o, "key", NULL) == 7 ); /* continue from cache */ t( sp_setint(o, "cache_only", 1) == 0 ); o = sp_get(cursor, o); t( o != NULL ); t( *(uint32_t*)sp_getstring(o, "key", NULL) == 8 ); sp_destroy(o); sp_destroy(cursor); t( sp_destroy(env) == 0 ); }