本文整理汇总了C++中sp_env函数的典型用法代码示例。如果您正苦于以下问题:C++ sp_env函数的具体用法?C++ sp_env怎么用?C++ sp_env使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sp_env函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: multi_process
static void
multi_process(void) {
void *env = sp_env();
t( env != NULL );
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0 );
void *db = sp_open(env);
t( db != NULL );
int pid = fork();
t( pid != -1 );
if (pid == 0) {
/* new process */
void *env2 = sp_env();
t( env2 != NULL );
t( sp_ctl(env2, SPDIR, SPO_CREAT|SPO_RDWR, dbrep1) == 0 );
void *db2 = sp_open(env2);
t( db2 == NULL );
t( sp_destroy(env2) == 0 );
/* valgrind: parent db and env are unfreed here, and that
* is correct otherwise destroy would
* corrupt the database.
*/
exit(0);
} else {
int status = 0;
t( waitpid(pid, &status, 0) == pid );
t( status == 0 );
}
t( sp_destroy(db) == 0 );
t( sp_destroy(env) == 0 );
rmrf(dbrep1);
}
示例2: repository_test4
static void
repository_test4(void)
{
rmrf("./sophia");
rmrf("./logdir");
rmrf("./dir");
void *env = sp_env();
t( env != NULL );
t( sp_setstring(env, "sophia.path", "sophia", 0) == 0 );
t( sp_setint(env, "sophia.path_create", 0) == 0 );
t( sp_setint(env, "log.enable", 0) == 0 );
t( sp_setint(env, "scheduler.threads", 0) == 0 );
t( sp_open(env) == -1 );
t( sp_destroy(env) == 0 );
t( exists("sophia", "") == 0 );
mkdir("sophia", 0755);
env = sp_env();
t( env != NULL );
t( sp_setstring(env, "sophia.path", "sophia", 0) == 0 );
t( sp_setint(env, "sophia.path_create", 0) == 0 );
t( sp_setint(env, "scheduler.threads", 0) == 0 );
t( sp_setint(env, "log.enable", 0) == 0 );
t( sp_setstring(env, "db", "test", 0) == 0 );
t( sp_setint(env, "db.test.sync", 0) == 0 );
t( sp_open(env) == 0 );
t( exists("sophia", "test") == 1 );
t( sp_destroy(env) == 0 );
}
示例3: single_process_2
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 );
}
示例4: repository_test4
static void
repository_test4(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.path_create", 0) == 0 );
t( sp_setint(env, "log.enable", 0) == 0 );
t( sp_setint(env, "scheduler.threads", 0) == 0 );
t( sp_open(env) == -1 );
t( sp_destroy(env) == 0 );
t( exists(st_r.conf->sophia_dir, "") == 0 );
mkdir(st_r.conf->sophia_dir, 0755);
env = sp_env();
t( env != NULL );
t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
t( sp_setint(env, "sophia.path_create", 0) == 0 );
t( sp_setint(env, "scheduler.threads", 0) == 0 );
t( sp_setint(env, "log.enable", 0) == 0 );
t( sp_setstring(env, "db", "test", 0) == 0 );
t( sp_setint(env, "db.test.sync", 0) == 0 );
t( sp_open(env) == 0 );
t( exists(st_r.conf->sophia_dir, "test") == 1 );
t( sp_destroy(env) == 0 );
}
示例5: workflow_test
void
workflow_test(char *injection)
{
workflow_upsert_n = 0;
int i = 0;
int j = 0;
for (;; i++) {
st_scene_rmrf(NULL);
fprintf(st_r.output, " %d", i);
fflush(NULL);
/* open */
void *env = sp_env();
t( env != NULL );
t( sp_setint(env, injection, i) == 0 );
void *db = workflow_open(env);
if (db == NULL) {
sp_destroy(env); /* close(2) might fail */
continue;
}
/* write, transaction, read, get, cursor */
int rc = workflow_write_read(env, db);
if (rc == -1) {
sp_destroy(env);
continue;
}
/* upsert */
rc = workflow_upsert(env, db);
if (rc == -1) {
sp_destroy(env);
continue;
}
/* branch + compaction */
rc = workflow_compaction(env, db);
if (rc == -1) {
sp_destroy(env);
continue;
}
/* snapshot */
rc = workflow_snapshot(env, db);
if (rc == -1) {
sp_destroy(env);
continue;
}
sp_destroy(env);
/* recover */
env = sp_env();
t( env != NULL );
t( sp_setint(env, injection, j) == 0 );
db = workflow_open(env);
if (db == NULL) {
j++;
sp_destroy(env);
continue;
}
sp_destroy(env);
break;
}
}
示例6: scheme_test0
static void
scheme_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.path", st_r.conf->db_dir, 0) == 0 );
t( sp_setstring(env, "db.test.compression_cold", "zstd", 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", "key_b", 0) == 0 );
t( sp_setstring(env, "db.test.scheme.key_b", "string,key(1)", 0) == 0 );
t( sp_setstring(env, "db.test.scheme", "value", 0) == 0 );
t( sp_setint(env, "db.test.sync", 0) == 0 );
void *db = sp_getobject(env, "db.test");
t( db != NULL );
t( sp_open(env) == 0 );
t( sp_destroy(env) == 0 );
env = sp_env();
t( env != NULL );
t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
t( sp_setint(env, "scheduler.threads", 0) == 0 );
t( sp_setstring(env, "log.path", st_r.conf->log_dir, 0) == 0 );
t( sp_setint(env, "log.sync", 0) == 0 );
t( sp_setint(env, "log.rotate_sync", 0) == 0 );
t( sp_setstring(env, "db", "test", 0) == 0 );
t( sp_setstring(env, "db.test.path", st_r.conf->db_dir, 0) == 0 );
t( sp_setint(env, "db.test.sync", 0) == 0 );
db = sp_getobject(env, "db.test");
t( db != NULL );
t( sp_open(env) == 0 );
char *v = sp_getstring(env, "db.test.compression_cold", 0);
t( v != NULL );
t( strcmp(v, "zstd") == 0 );
free(v);
v = sp_getstring(env, "db.test.scheme.key", 0);
t( v != NULL );
t( strcmp(v, "u32,key(0)") == 0 );
free(v);
v = sp_getstring(env, "db.test.scheme.key_b", 0);
t( v != NULL );
t( strcmp(v, "string,key(1)") == 0 );
free(v);
v = sp_getstring(env, "db.test.scheme.value", 0);
t( v != NULL );
t( strcmp(v, "string") == 0 );
free(v);
t( sp_destroy(env) == 0 );
}
示例7: meta_scheduler
static void
meta_scheduler(void)
{
void *env = sp_env();
t( env != NULL );
t( sp_setint(env, "scheduler.threads", 2) == 0 );
t( sp_setint(env, "log.enable", 0) == 0 );
t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
t( sp_getstring(env, "scheduler.0.trace", NULL) == NULL );
t( sp_open(env) == 0 );
char *v = sp_getstring(env, "scheduler.0.trace", NULL);
t( v != NULL );
t( strcmp(v, "malfunction") != 0 );
free(v);
v = sp_getstring(env, "scheduler.1.trace", NULL);
t( v != NULL );
t( strcmp(v, "malfunction") != 0 );
free(v);
v = sp_getstring(env, "scheduler.2.trace", NULL);
t( v == NULL );
t( sp_destroy(env) == 0 );
}
示例8: meta_db
static void
meta_db(void)
{
void *env = sp_env();
t( env != NULL );
t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
t( sp_setint(env, "scheduler.threads", 0) == 0 );
t( sp_setstring(env, "db", "test", 0) == 0 );
t( sp_setstring(env, "db.test.index", "key_b", 0) == 0 );
t( sp_setint(env, "db.test.id", 777) == 0 );
t( sp_setint(env, "db.test.sync", 0) == 0 );
t( sp_open(env) == 0 );
void *db = sp_getobject(env, "db.test");
t( db != NULL );
char *s = sp_getstring(db, "name", NULL);
t( strcmp(s, "test") == 0 );
free(s);
t( sp_getint(db, "id") == 777 );
t( sp_getint(db, "key-count") == 2 );
s = sp_getstring(env, "db.test.index.key", 0);
t( s != NULL );
t( strcmp(s, "string") == 0 );
free(s);
s = sp_getstring(env, "db.test.index.key_b", 0);
t( s != NULL );
t( strcmp(s, "string") == 0 );
free(s);
t( sp_destroy(env) == 0 );
}
示例9: meta_cursor
static void
meta_cursor(void)
{
void *env = sp_env();
t( env != NULL );
t( sp_setstring(env, "sophia.path", st_r.conf->sophia_dir, 0) == 0 );
t( sp_setint(env, "scheduler.threads", 0) == 0 );
t( sp_setstring(env, "db", "test", 0) == 0 );
t( sp_setstring(env, "db.test.index", "key_b", 0) == 0 );
t( sp_setint(env, "db.test.sync", 0) == 0 );
t( sp_open(env) == 0 );
t( sp_setstring(env, "snapshot", "test_snapshot0", 0) == 0 );
fprintf(st_r.output, "\n");
void *cur = sp_getobject(env, NULL);
t( cur != NULL );
fprintf(st_r.output, "\n");
void *o = NULL;
while ((o = sp_get(cur, o))) {
char *key = sp_getstring(o, "key", 0);
char *value = sp_getstring(o, "value", 0);
fprintf(st_r.output, "%s", key);
if (value)
fprintf(st_r.output, " = %s\n", value);
else
fprintf(st_r.output, " = \n");
}
fprintf(st_r.output, "\n");
t( sp_destroy(cur) == 0 );
t( sp_destroy(env) == 0 );
}
示例10: leak_set
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 );
}
示例11: meta_empty_key
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 );
}
示例12: mt_quota_checkpoint
static void
mt_quota_checkpoint(stc *cx)
{
cx->env = sp_env();
t( cx->env != NULL );
void *c = sp_ctl(cx->env);
t( c != NULL );
t( sp_set(c, "sophia.path", cx->suite->sophiadir) == 0 );
t( sp_set(c, "memory.limit", "524288") == 0 ); /* 512k */
/* use default settings */
t( sp_set(c, "scheduler.threads", "5") == 0 );
t( sp_set(c, "log.path", cx->suite->logdir) == 0 );
t( sp_set(c, "log.sync", "0") == 0 );
t( sp_set(c, "log.rotate_sync", "0") == 0 );
t( sp_set(c, "db", "test") == 0 );
t( sp_set(c, "db.test.path", cx->suite->dir) == 0 );
t( sp_set(c, "db.test.sync", "0") == 0 );
t( sp_set(c, "db.test.index.cmp", "u32", NULL) == 0 );
cx->db = sp_get(c, "db.test");
t( cx->db != NULL );
t( sp_open(cx->env) == 0 );
char value[1000];
memset(value, 0, sizeof(value));
int i = 0;
while (i < 20000) { /* ~ 20Mb */
void *o = sp_object(cx->db);
assert(o != NULL);
sp_set(o, "key", &i, sizeof(i));
sp_set(o, "value", value, sizeof(value));
int rc = sp_set(cx->db, o);
t( rc == 0 );
i++;
}
t( sp_destroy(cx->env) == 0 );
}
示例13: gh_29
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 );
}
示例14: compact_temperature
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 );
}
示例15: github_123
static void
github_123(void)
{
rmrf("./abc");
rmrf("./abc_log");
void *env = sp_env();
t( env != NULL );
char path[] = { '.', '/', 'a', 'b', 'c' };
char path_log[] = { '.', '/', 'a', 'b', 'c', '_', 'l', 'o', 'g' };
char name[] = { 't', 'e', 's', 't' };
t( sp_setstring(env, "sophia.path", path, sizeof(path)) == 0 );
t( sp_setstring(env, "db", name, sizeof(name)) == 0 );
t( sp_setstring(env, "log.path", path_log, sizeof(path_log)) == 0 );
t( sp_open(env) == 0 );
t( exists("./", "abc") == 1 );
t( exists("./", "abc_log") == 1 );
void *db = sp_getobject(env, "db.test");
t( db != NULL );
t( sp_destroy(env) == 0 );
rmrf("./abc");
rmrf("./abc_log");
}