static void hc_prepare_commit_empty(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 ); int rc; void *tx = sp_begin(env); t( tx != NULL ); 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 leak_tx_tx_tx_set_get_commit1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); void *a = sp_begin(env); t( a != NULL ); void *b = sp_begin(env); t( b != NULL ); void *c = sp_begin(env); t( c != NULL ); int key = 123; void *o = sp_document(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(c, o) == 0 ); t( sp_getint(env, "performance.documents") == 1 ); t( sp_commit(c) == 0 ); t( sp_getint(env, "performance.documents") == 1 ); key = 124; o = sp_document(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(b, o) == 0 ); t( sp_getint(env, "performance.documents") == 2 ); t( sp_commit(b) == 0 ); t( sp_getint(env, "performance.documents") == 2 ); key = 125; o = sp_document(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(a, o) == 0 ); t( sp_getint(env, "performance.documents") == 3 ); t( sp_commit(a) == 0 ); t( sp_getint(env, "performance.documents") == 3 ); t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_getint(env, "performance.documents") == 0 ); t( sp_destroy(env) == 0 ); }
static void mt_upsert2(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 5) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_open(env) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.index.upsert", upsert_op, 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.index.key", "u32", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(db) == 0 ); uint32_t n = 700000; uint32_t i, k = 1234; uint32_t value = 1; void *tx = sp_begin(env); t( tx != NULL ); for (i = 0; i < n; i++) { if (i > 0 && (i % 1000) == 0) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &k, sizeof(k)) == 0 ); void *c = sp_cursor(env); t( c != NULL ); o = sp_get(c, o); t( o != NULL ); t( *(uint32_t*)sp_getstring(o, "value", NULL) == i); sp_destroy(o); sp_destroy(c); t( sp_commit(tx) == 0 ); tx = sp_begin(env); t( tx != NULL ); } void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &k, sizeof(k)) == 0 ); t( sp_setstring(o, "value", &value, sizeof(value)) == 0 ); t( sp_upsert(db, o) == 0 ); print_current(i); } t( sp_commit(tx) == 0 ); 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 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 inline void *multi_stmt_thread(void *arg) { ssthread *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_document(db); assert(o != NULL); sp_setstring(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 inline void *multi_stmt_conflict_thread0(void *arg) { ssthread *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_document(db); int key = i + j; assert(o != NULL); sp_setstring(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 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_document(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_document(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 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 PyObject * sophia_db_commit(SophiaDB *db) { ensure_is_opened(db, NULL); if (sp_commit(db->db) == -1) { PyErr_SetString(SophiaError, sp_error(db->db)); return NULL; } Py_RETURN_NONE; }
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 ); }
jint JNICALL Java_eu_unicredit_sophia_SophiaInterface_sp_1commit (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: ret = sp_commit((void*)array[0]); break; default: printf("Not supported\n"); break; }; return (jint)ret; }
static inline void *multi_stmt_conflict_thread1(void *arg) { ssthread *self = arg; void *env = ((void**)self->arg)[0]; void *db = ((void**)self->arg)[1]; int id = 1; int rc; int i = 0; while (i < 100) { rc = 0; do { void *tx = sp_begin(env); void *o = sp_document(db); sp_setstring(o, "key", &id, sizeof(id)); o = sp_get(tx, o); int v = 0; if (o) { v = *(int*)sp_getstring(o, "value", NULL); sp_destroy(o); } v++; o = sp_document(db); sp_setstring(o, "key", &id, sizeof(id)); sp_setstring(o, "value", &v, sizeof(v)); rc = sp_set(tx, o); assert(rc == 0); rc = sp_commit(tx); if (2 == rc) sp_destroy(tx); assert(rc != -1); } while (rc != 0); i++; } return NULL; }
static inline int workflow_write_read(void *env, void *db) { /* write */ void *o = sp_document(db); if (o == NULL) return -1; uint32_t key = 123; int rc; 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; /* transaction */ void *tx = sp_begin(env); if (tx == NULL) return -1; o = sp_document(db); if (o == NULL) return -1; key = 123; rc = sp_setstring(o, "key", &key, sizeof(key)); if (rc == -1) { sp_destroy(o); sp_destroy(tx); return -1; } rc = sp_setstring(o, "value", &key, sizeof(key)); if (rc == -1) { sp_destroy(o); sp_destroy(tx); return -1; } rc = sp_set(tx, o); if (rc == -1) { sp_destroy(tx); return -1; } o = sp_document(db); if (o == NULL) return -1; rc = sp_setstring(o, "key", &key, sizeof(key)); if (rc == -1) { sp_destroy(o); sp_destroy(tx); return -1; } o = sp_get(tx, o); if (o == NULL) { sp_destroy(tx); return -1; } sp_destroy(o); rc = sp_commit(tx); if (rc == -1) return -1; /* read */ 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; } o = sp_get(db, o); if (o == NULL) return -1; sp_destroy(o); /* cursor */ void *c = sp_cursor(env); if (c == NULL) return -1; o = sp_document(db); if (o == NULL) { sp_destroy(c); return -1; } o = sp_get(c, o); if (o == NULL) { sp_destroy(c); return -1; } sp_destroy(o); sp_destroy(c); return 0; }
static void secondary_index_test_unique0(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 ); /* 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", 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; void *po, *so; uint32_t a, b; tx = sp_begin(env); a = 0; b = 3; po = sp_document(primary); sp_setstring(po, "a", &a, sizeof(a)); sp_setstring(po, "b", &b, sizeof(b)); t( sp_set(tx, po) == 0 ); so = sp_document(secondary); sp_setstring(po, "a", &a, sizeof(a)); sp_setstring(po, "b", &b, sizeof(b)); t( sp_set(tx, so) == 0 ); t( sp_commit(tx) == 0 ); tx = sp_begin(env); a = 1; b = 2; po = sp_document(primary); sp_setstring(po, "a", &a, sizeof(a)); sp_setstring(po, "b", &b, sizeof(b)); t( sp_set(tx, po) == 0 ); so = sp_document(secondary); sp_setstring(po, "a", &a, sizeof(a)); sp_setstring(po, "b", &b, sizeof(b)); t( sp_set(tx, so) == 0 ); t( sp_commit(tx) == 0 ); tx = sp_begin(env); a = 2; b = 1; po = sp_document(primary); sp_setstring(po, "a", &a, sizeof(a)); sp_setstring(po, "b", &b, sizeof(b)); t( sp_set(tx, po) == 0 ); so = sp_document(secondary); sp_setstring(po, "a", &a, sizeof(a)); sp_setstring(po, "b", &b, sizeof(b)); t( sp_set(tx, so) == 0 ); t( sp_commit(tx) == 0 ); tx = sp_begin(env); a = 3; b = 0; po = sp_document(primary); sp_setstring(po, "a", &a, sizeof(a)); sp_setstring(po, "b", &b, sizeof(b)); t( sp_set(tx, po) == 0 ); so = sp_document(secondary); sp_setstring(po, "a", &a, sizeof(a)); sp_setstring(po, "b", &b, sizeof(b)); t( sp_set(tx, so) == 0 ); t( sp_commit(tx) == 0 ); uint32_t current_a = 0; uint32_t current_b = 3; void *cur = sp_cursor(env); po = sp_document(primary); sp_setstring(po, "order", ">=", 0); while ((po = sp_get(cur, po))) { t( *(uint32_t*)sp_getstring(po, "a", NULL) == current_a ); t( *(uint32_t*)sp_getstring(po, "b", NULL) == current_b ); current_a++; current_b--; } sp_destroy(cur); current_a = 3; current_b = 0; cur = sp_cursor(env); so = sp_document(secondary); sp_setstring(so, "order", ">=", 0); while ((so = sp_get(cur, so))) { t( *(uint32_t*)sp_getstring(so, "a", NULL) == current_a ); t( *(uint32_t*)sp_getstring(so, "b", NULL) == current_b ); current_a--; current_b++; } sp_destroy(cur); sp_destroy(env); }
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 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 ); }