static void conf_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_setint(env, "log.rotate_wm", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 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 *o = sp_document(db); t( sp_setstring(o, "key", "", 0) == 0 ); t( sp_set(db, o) == 0 ); o = sp_document(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 inline int workflow_upsert(void *env, void *db) { void *o = sp_document(db); if (o == NULL) return -1; int up = 777; int i = 0; sp_setstring(o, "key", &i, sizeof(i)); sp_setstring(o, "value", &up, sizeof(up)); int rc = sp_upsert(db, o); if (rc == -1) return -1; o = sp_document(db); if (o == NULL) return -1; up = 778; sp_setstring(o, "key", &i, sizeof(i)); sp_setstring(o, "value", &up, sizeof(up)); rc = sp_upsert(db, o); if (rc == -1) return -1; o = sp_document(db); if (o == NULL) return -1; sp_setstring(o, "key", &i, sizeof(i)); o = sp_get(db, o); if (o == NULL) return -1; t( *(int*)sp_getstring(o, "value", NULL) == 778 ); sp_destroy(o); return 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 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 mt_setget(void) { 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(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_document(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 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 compact_directio(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setint(env, "db.test.compaction.branch_wm", 1) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setint(env, "db.test.direct_io", 1) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); char value[100]; memset(value, 0, sizeof(value)); int key = 0; while (key < 300000) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", value, sizeof(value)) == 0 ); t( sp_set(db, o) == 0 ); if ((key % 10000) == 0 && key > 0) { if (sp_setint(env, "db.test.compaction.branch", 0) == -1) { char *e = sp_getstring(env, "sophia.error", NULL); printf("%s, %d\n", (e) ? e: "null", errno); t( 0 ); } /*t( sp_setint(env, "db.test.compaction.branch", 0) == 0 );*/ } key++; } t( sp_setint(env, "db.test.compaction.compact", 0) == 0 ); key = 0; while (key < 1000) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(db, o); t( o != NULL ); t( *(int*)sp_getstring(o, "key", NULL) == key ); sp_destroy(o); key++; } t( sp_destroy(env) == 0 ); }
static void compact_delete1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key", "u32,key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int key = 0; while (key < 20) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); key = 0; while (key < 20) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_delete(db, o) == 0 ); key++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); void *o = sp_document(db); t( o != NULL ); void *cur = sp_cursor(env); t( o != NULL ); int i = 0; while ((o = sp_get(cur, o))) { t( *(int*)sp_getstring(o, "key", NULL) == i ); i++; } t( i == 0 ); t( sp_destroy(env) == 0 ); }
static void 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_document(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) "); /* trigger iteration */ void *o = sp_document(db); sp_setint(o, "async", 1); 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 github_120(void) { /* open or create environment and database */ void *env = sp_env(); sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0); sp_setstring(env, "db", "test", 0); void *db = sp_getobject(env, "db.test"); int rc = sp_open(env); if (rc == -1) goto error; /* set */ void *o = sp_document(db); sp_setstring(o, "key", "hello", 0); sp_setstring(o, "value", "world", 0); rc = sp_set(db, o); if (rc == -1) goto error; /* get */ o = sp_document(db); sp_setstring(o, "key", "hello", 0); o = sp_get(db, o); if (o) { /* ensure key and value are correct */ int size; char *ptr = sp_getstring(o, "key", &size); t( size == 5 ); t( strncmp(ptr, "hello", 5) == 0 ); ptr = sp_getstring(o, "value", &size); t( size == 5 ); t( strncmp(ptr, "world", 5) == 0 ); sp_destroy(o); } /* delete */ o = sp_document(db); sp_setstring(o, "key", "hello", 0); rc = sp_delete(db, o); if (rc == -1) goto error; /* finish work */ sp_destroy(env); return; error:; int size; char *error = sp_getstring(env, "sophia.error", &size); printf("error: %s\n", error); free(error); sp_destroy(env); }
static void amqf_test3(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key", "u32,key",0) == 0 ); t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); t( sp_setint(env, "db.test.amqf", 1) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setint(env, "compaction.0.branch_wm", 1) == 0 ); t( sp_open(env) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); int i = 0; while (i < 100) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); t( sp_setstring(o, "value", &i, sizeof(i)) == 0 ); t( sp_set(db, o) == 0 ); i++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); i = 300; while (i < 500) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); t( sp_setstring(o, "value", &i, sizeof(i)) == 0 ); t( sp_set(db, o) == 0 ); i++; } t( sp_setint(env, "db.test.branch", 0) == 0 ); t( sp_setint(env, "db.test.compact", 0) == 0 ); i = 0; while (i < 400) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &i, sizeof(i)) == 0 ); o = sp_get(db, o); if (o) { sp_destroy(o); } i++; } t( sp_getint(env, "db.test.index.read_disk") == 232 ); t( sp_destroy(env) == 0 ); }
static void 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 checkpoint_test1(void) { void *env = sp_env(); t( env != NULL ); t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 ); t( sp_setint(env, "scheduler.threads", 0) == 0 ); t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 ); t( sp_setint(env, "log.sync", 0) == 0 ); t( sp_setint(env, "log.rotate_sync", 0) == 0 ); t( sp_setstring(env, "db", "test", 0) == 0 ); t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "key", 0) == 0 ); t( sp_setstring(env, "db.test.scheme.key", "u32,key(0)", 0) == 0 ); t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 ); t( sp_setint(env, "db.test.sync", 0) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); t( sp_open(env) == 0 ); int key = 0; while (key < 20) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "log.rotate", 0) == 0 ); t( sp_getint(env, "log.files") == 2 ); key = 40; while (key < 80) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_setstring(o, "value", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key++; } t( sp_setint(env, "log.rotate", 0) == 0 ); t( sp_getint(env, "log.files") == 3 ); t( sp_setint(env, "db.test.compaction.checkpoint", 0) == 0 ); t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_setint(env, "scheduler.run", 0) == 1 ); t( sp_getint(env, "log.files") == 1 ); t( sp_destroy(env) == 0 ); }
static void mt_set_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_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); } 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_delete(db, o) == 0 ); print_current(i); } 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 ); print_current(i); } 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_document(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_document(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_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 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 mt_set_get_anticache(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, "memory.anticache", 500 * 1024) == 0 ); t( sp_setint(env, "compaction.node_size", 100 * 1024) == 0 ); t( sp_setint(env, "compaction.page_size", 8 * 1024) == 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.storage", "anti-cache", 0) == 0 ); t( sp_setint(env, "db.test.compression_key", 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 ); uint32_t n = 700000; uint32_t i, k; char value[100]; memset(value, 0, sizeof(value)); 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 ); 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(); 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 ); sp_destroy(o); print_current(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, "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 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 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 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 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 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.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_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 branch_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.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, "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 key = 0; while (key < 1000) { 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 ); if ((key % 100 == 0) && key > 0) t( sp_setint(env, "db.test.compaction.branch", 0) == 0 ); key++; } key = 0; while (key < 1000) { void *o = sp_document(db); t( o != NULL ); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); o = sp_get(db, o); t( o != NULL ); t( *(int*)sp_getstring(o, "key", NULL) == key); sp_destroy(o); key++; } t( sp_destroy(env) == 0 ); }
static void scheme_comparator(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.index.comparator", (char*)(intptr_t)comparator, 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 ); uint32_t key = 0; while (key < 10) { void *o = sp_document(db); t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); t( sp_set(db, o) == 0 ); key++; } key = 4; void *o = sp_document(db); sp_setstring(o, "key", &key, sizeof(key)); o = sp_get(db, o); t( o != NULL ); sp_destroy(o); key = 0; o = sp_document(db); sp_setstring(o, "order", ">=", 0); sp_setstring(o, "key", &key, sizeof(key)); void *c = sp_cursor(env); while ((o = sp_get(c, o))) { t( *(uint32_t*)sp_getstring(o, "key", NULL) == key ); key++; } t(key == 10); sp_destroy(c); t( sp_destroy(env) == 0 ); }
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 github_97(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_open(env) == 0 ); void *db = sp_getobject(env, "db.test"); t( db != NULL ); /* we must pass sizeof(uint32_t) in sp_setstring() */ uint32_t 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++; } void *cur = sp_cursor(env); t( cur != NULL ); void *o = sp_document(db); t( o != NULL ); uint32_t key = 99; t( sp_setstring(o, "key", &key, sizeof(key)) == 0 ); /* < */ i = 0; while ((o = sp_get(cur, o))) i++; t( i == 1 ); sp_destroy(cur); 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 ); }