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 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 gh_5(void) { void *env = sp_env(); t( env != NULL ); t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 ); void *db = sp_open(env); t( db != NULL ); char k1[] = "key-1"; char v1[] = "val-1"; t( sp_set(db, k1, sizeof(k1), v1, sizeof(v1)) == 0); char k2[] = "key-10"; char v2[] = "val-10"; t( sp_set(db, k2, sizeof(k2), v2, sizeof(v2)) == 0); size_t ressize = 0; void *res = NULL; t( sp_get(db, k1, sizeof(k1), &res, &ressize) == 1 ); t( ressize == sizeof(v1) ); t( strcmp(v1, res) == 0 ); free(res); t( sp_destroy(db) == 0 ); t( sp_destroy(env) == 0 ); t( rmrf(dbrep) == 0 ); }
jint JNICALL Java_eu_unicredit_sophia_SophiaInterface_sp_1set (JNIEnv * env, jobject obj, jlongArray args) { jlong* array = (*env)->GetLongArrayElements(env, args,JNI_FALSE); jint size = (*env)->GetArrayLength(env, args); int ret = -1; switch(size) { case 0: printf("Not supported\n"); break; case 1: printf("Not supported\n"); break; case 2: ret = sp_set((void*)array[0], (void*)array[1]); break; case 3: ret = sp_set((void*)array[0], (void*)array[1], (void*)array[2]); break; case 4: ret = sp_set((void*)array[0], (void*)array[1], (void*)array[2], (void*)array[3]); break; default: printf("Not supported\n"); break; }; return (jint)ret; }
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 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 single_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 ); void *db2 = sp_open(env2); t( db2 != NULL ); uint32_t k = 1; t( sp_set(db2, &k, sizeof(k), &k, sizeof(k)) == 0 ); size_t vsize = 0; void *vp = NULL; t( sp_get(db2, &k, sizeof(k), &vp, &vsize) == 1 ); t( vsize == sizeof(k) ); t( *(uint32_t*)vp == k ); free(vp); 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( sp_destroy(db2) == 0 ); t( sp_destroy(env2) == 0 ); t( rmrf(dbrep1) == 0 ); t( rmrf(dbrep2) == 0 ); }
static inline int workflow_compaction(void *env, void *db) { /* branch oom */ int rc = sp_setint(env, "db.test.branch", 0); if (rc == -1) return -1; uint32_t key = 123; int count = 0; while (count < 10) { void *o = sp_document(db); if (o == NULL) return -1; rc = sp_setstring(o, "key", &key, sizeof(key)); if (rc == -1) { sp_destroy(o); return -1; } rc = sp_setstring(o, "value", &key, sizeof(key)); if (rc == -1) { sp_destroy(o); return -1; } rc = sp_set(db, o); if (rc == -1) return -1; key++; count++; } rc = sp_setint(env, "db.test.branch", 0); if (rc == -1) return -1; /* put some statements in log */ while (count < 15) { void *o = sp_document(db); if (o == NULL) return -1; rc = sp_setstring(o, "key", &key, sizeof(key)); if (rc == -1) { sp_destroy(o); return -1; } rc = sp_setstring(o, "value", &key, sizeof(key)); if (rc == -1) { sp_destroy(o); return -1; } rc = sp_set(db, o); if (rc == -1) return -1; key++; count++; } /* compaction oom */ rc = sp_setint(env, "db.test.compact", 0); if (rc == -1) return -1; return 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 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 inline void st_phase_commit(stc *cx) { switch (cx->phase_scene) { case 0: break; case 1: t( sp_set(sp_ctl(cx->env), "db.test.branch") == 0 ); break; case 2: t( sp_set(sp_ctl(cx->env), "db.test.branch") == 0 ); t( sp_set(sp_ctl(cx->env), "db.test.compact") == 0 ); break; case 3: t( sp_set(sp_ctl(cx->env), "log.rotate") == 0 ); t( sp_set(sp_ctl(cx->env), "log.gc") == 0 ); break; case 4: if (cx->phase == 0) { t( sp_set(sp_ctl(cx->env), "db.test.branch") == 0 ); t( sp_set(sp_ctl(cx->env), "log.rotate") == 0 ); t( sp_set(sp_ctl(cx->env), "log.gc") == 0 ); cx->phase = 1; } else if (cx->phase == 1) { t( sp_set(sp_ctl(cx->env), "db.test.compact") == 0 ); cx->phase = 0; } break; default: t(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 github_104(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key", "string,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 ); char key_a[] = "aa"; char key_b[] = "bb"; char key_c[] = "cc"; char key_d[] = "dd"; void *o = sp_document(db); t( sp_setstring(o, "key", key_a, sizeof(key_a)) == 0 ); t( sp_set(db, o) == 0 ); o = sp_document(db); t( sp_setstring(o, "key", key_b, sizeof(key_b)) == 0 ); t( sp_set(db, o) == 0 ); o = sp_document(db); t( sp_setstring(o, "key", key_c, sizeof(key_c)) == 0 ); t( sp_set(db, o) == 0 ); o = sp_document(db); t( sp_setstring(o, "key", key_d, sizeof(key_d)) == 0 ); t( sp_set(db, o) == 0 ); void *cur = sp_cursor(env); t( cur != NULL ); o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", key_b, sizeof(key_b)) == 0 ); t( sp_setstring(o, "order", "<=", 0) == 0 ); int i = 0; while ((o = sp_get(cur, o))) { printf(" %s", (char*)sp_getstring(o, "key", 0)); i++; } fflush(NULL); t( i == 2 ); sp_destroy(cur); t( sp_destroy(env) == 0 ); }
static void hc_prepare_rollback1(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_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(tx, o) == 0 ); o = sp_document(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_destroy(tx); t( rc == 0 ); 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", &key, sizeof(key)) == 0 ); t( sp_set(tx, o) == 0 ); 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 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 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 transaction_batch_test0(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); void *tx = sp_begin(env); t( tx != NULL ); t( sp_setstring(tx, "isolation", "batch", 0) == 0 ); t( sp_setstring(tx, "isolation", "batch", 0) == -1 ); t( sp_setstring(tx, "isolation", "serializable", 0) == -1 ); uint32_t a = 7; uint32_t b = 8; void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &a, sizeof(a)) == 0 ); t( sp_set(tx, o) == 0 ); o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &b, sizeof(a)) == 0 ); t( sp_set(tx, o) == 0 ); o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &a, sizeof(a)) == 0 ); o = sp_get(tx, o); /* error */ t( sp_commit(tx) == 0 ); o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &a, sizeof(a)) == 0 ); o = sp_get(db, o); t( o != NULL ); sp_destroy(o); 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 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 inline void *spr_worker(void *arg) { char value[100]; memset(value, 0, sizeof(value)); while (spr_start) { if (spr_pause) { sleep(1); continue; } uint32_t key = rand() % 100000000; void *o = sp_document(spr_db); sp_setstring(o, "key", &key, sizeof(key)); sp_setstring(o, "value", &key, sizeof(key)); int rc = sp_set(spr_db, o); if (rc == -1) { } /* o = sp_document(spr_db); sp_setstring(o, "key", &key, sizeof(key)); o = sp_get(spr_db, o); if (o) { sp_destroy(o); } */ } return NULL; }
static void compact_temperature(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_setint(env, "compaction.0.compact_mode", 1) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key", "u32,key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 ); t( sp_setint(env, "db.test.temperature", 1) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int key = 0; while (key < 20) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); t( sp_destroy(env) == 0 ); }
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 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 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 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 gh_29(void) { void *env = sp_env(); t( env != NULL ); t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 ); void *db = sp_open(env); t( db != NULL ); int i; for (i = 1; i <= 10; i++) { char key[4]; int len = snprintf(key, sizeof(key), "%d", i); t( sp_set(db, key, len, key, len) == 0 ); } for (i = 1; i <= 10; i++) { char key[4]; int len = snprintf(key, sizeof(key), "%d", i); size_t vsize = 0; void *vp = NULL; t( sp_get(db, key, len, &vp, &vsize) == 1 ); t( vsize == len ); t( memcmp(key, vp, len) == 0 ); free(vp); } t( sp_destroy(db) == 0 ); t( sp_destroy(env) == 0 ); t( rmrf(dbrep) == 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_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 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 ); }