本文整理汇总了C++中DB_ENV::log_set_config方法的典型用法代码示例。如果您正苦于以下问题:C++ DB_ENV::log_set_config方法的具体用法?C++ DB_ENV::log_set_config怎么用?C++ DB_ENV::log_set_config使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB_ENV
的用法示例。
在下文中一共展示了DB_ENV::log_set_config方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: optimisticDb_create
OptimisticDb* optimisticDb_create()
{
OptimisticDb *optimisticDb;
DB_ENV *envp;
u_int32_t envFlags;
int ret;
/* Allocate memory */
optimisticDb = malloc( sizeof( OptimisticDb ) );
ret = db_env_create( &envp, 0 );
if( ret != 0 ) {
printf( "Failed to create anvironment for optimistic database store\n" );
exit(1);
}
envFlags =
DB_CREATE |
DB_INIT_LOCK |
DB_INIT_LOG |
DB_INIT_TXN |
DB_INIT_MPOOL |
DB_PRIVATE /* Don't put region files on disk */
;
/* Store database logs entirely in memory */
envp->log_set_config( envp, DB_LOG_IN_MEMORY, 1 );
/* Increase the cache size */
envp->set_cachesize( envp, 0, 100 * 1024 * 1024, 1 );
envp->set_errfile( envp, stderr );
ret = envp->open( envp, NULL, envFlags, 0 );
if( ret != 0 ) {
printf( "Failed to create environment for optimistic database store\n");
exit( 1 );
}
optimisticDb->envp = envp;
optimisticDb->isOpen = 0;
return optimisticDb;
}
示例2: pool
int
main(void)
{
/* Initialize our handles */
DB *dbp = NULL;
DB_ENV *envp = NULL;
thread_t writer_threads[NUMWRITERS];
int i, ret, ret_t;
u_int32_t env_flags;
/* Application name */
const char *prog_name = "txn_guide_inmemory";
/* Create the environment */
ret = db_env_create(&envp, 0);
if (ret != 0) {
fprintf(stderr, "Error creating environment handle: %s\n",
db_strerror(ret));
goto err;
}
env_flags =
DB_CREATE | /* Create the environment if it does not exist */
DB_INIT_LOCK | /* Initialize the locking subsystem */
DB_INIT_LOG | /* Initialize the logging subsystem */
DB_INIT_TXN | /* Initialize the transactional subsystem. This
* also turns on logging. */
DB_INIT_MPOOL | /* Initialize the memory pool (in-memory cache) */
DB_PRIVATE | /* Region files are backed by heap memory. */
DB_THREAD; /* Cause the environment to be free-threaded */
/* Specify in-memory logging */
ret = envp->log_set_config(envp, DB_LOG_IN_MEMORY, 1);
if (ret != 0) {
fprintf(stderr, "Error setting log subsystem to in-memory: %s\n",
db_strerror(ret));
goto err;
}
/*
* Specify the size of the in-memory log buffer.
*/
ret = envp->set_lg_bsize(envp, 10 * 1024 * 1024);
if (ret != 0) {
fprintf(stderr, "Error increasing the log buffer size: %s\n",
db_strerror(ret));
goto err;
}
/*
* Specify the size of the in-memory cache.
*/
ret = envp->set_cachesize(envp, 0, 10 * 1024 * 1024, 1);
if (ret != 0) {
fprintf(stderr, "Error increasing the cache size: %s\n",
db_strerror(ret));
goto err;
}
/*
* Indicate that we want db to perform lock detection internally.
* Also indicate that the transaction with the fewest number of
* write locks will receive the deadlock notification in
* the event of a deadlock.
*/
ret = envp->set_lk_detect(envp, DB_LOCK_MINWRITE);
if (ret != 0) {
fprintf(stderr, "Error setting lock detect: %s\n",
db_strerror(ret));
goto err;
}
/* Now actually open the environment */
ret = envp->open(envp, NULL, env_flags, 0);
if (ret != 0) {
fprintf(stderr, "Error opening environment: %s\n",
db_strerror(ret));
goto err;
}
/*
* If we had utility threads (for running checkpoints or
* deadlock detection, for example) we would spawn those
* here. However, for a simple example such as this,
* that is not required.
*/
/* Open the database */
ret = open_db(&dbp, prog_name, NULL,
envp, DB_DUPSORT);
if (ret != 0)
goto err;
/* Initialize a mutex. Used to help provide thread ids. */
(void)mutex_init(&thread_num_lock, NULL);
/* Start the writer threads. */
for (i = 0; i < NUMWRITERS; i++)
(void)thread_create(
//.........这里部分代码省略.........
示例3: malloc
static void
b_inmem_op_tds(u_int ops, int update, u_int32_t env_flags, u_int32_t log_flags)
{
DB *dbp;
DBT key, data;
DB_ENV *dbenv;
DB_MPOOL_STAT *gsp;
DB_TXN *txn;
char *keybuf, *databuf;
DB_BENCH_ASSERT((keybuf = malloc(keysize)) != NULL);
DB_BENCH_ASSERT((databuf = malloc(datasize)) != NULL);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = keybuf;
key.size = keysize;
memset(keybuf, 'a', keysize);
data.data = databuf;
data.size = datasize;
memset(databuf, 'b', datasize);
DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
dbenv->set_errfile(dbenv, stderr);
/* General environment configuration. */
#ifdef DB_AUTO_COMMIT
DB_BENCH_ASSERT(dbenv->set_flags(dbenv, DB_AUTO_COMMIT, 1) == 0);
#endif
if (env_flags != 0)
DB_BENCH_ASSERT(dbenv->set_flags(dbenv, env_flags, 1) == 0);
/* Logging configuration. */
if (log_flags != 0)
#if DB_VERSION_MINOR >= 7
DB_BENCH_ASSERT(
dbenv->log_set_config(dbenv, log_flags, 1) == 0);
#else
DB_BENCH_ASSERT(dbenv->set_flags(dbenv, log_flags, 1) == 0);
#endif
#ifdef DB_LOG_INMEMORY
if (!(log_flags & DB_LOG_INMEMORY))
#endif
#ifdef DB_LOG_IN_MEMORY
if (!(log_flags & DB_LOG_IN_MEMORY))
#endif
DB_BENCH_ASSERT(dbenv->set_lg_max(dbenv, logbufsize * 10) == 0);
DB_BENCH_ASSERT(dbenv->set_lg_bsize(dbenv, logbufsize) == 0);
DB_BENCH_ASSERT(dbenv->open(dbenv, "TESTDIR",
DB_CREATE | DB_PRIVATE | DB_INIT_LOCK |
DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN, 0666) == 0);
DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0);
DB_BENCH_ASSERT(dbp->set_pagesize(dbp, pagesize) == 0);
DB_BENCH_ASSERT(dbp->open(
dbp, NULL, TESTFILE, NULL, DB_BTREE, DB_CREATE, 0666) == 0);
if (update) {
(void)dbenv->memp_stat(dbenv, &gsp, NULL, DB_STAT_CLEAR);
TIMER_START;
for (; ops > 0; --ops)
DB_BENCH_ASSERT(
dbp->put(dbp, NULL, &key, &data, 0) == 0);
TIMER_STOP;
if (dbenv->memp_stat(dbenv, &gsp, NULL, 0) == 0)
DB_BENCH_ASSERT(gsp->st_page_out == 0);
} else {
DB_BENCH_ASSERT(dbp->put(dbp, NULL, &key, &data, 0) == 0);
(void)dbenv->memp_stat(dbenv, &gsp, NULL, DB_STAT_CLEAR);
TIMER_START;
for (; ops > 0; --ops) {
DB_BENCH_ASSERT(
dbenv->txn_begin(dbenv, NULL, &txn, 0) == 0);
DB_BENCH_ASSERT(
dbp->get(dbp, NULL, &key, &data, 0) == 0);
DB_BENCH_ASSERT(txn->commit(txn, 0) == 0);
}
TIMER_STOP;
if (dbenv->memp_stat(dbenv, &gsp, NULL, 0) == 0)
DB_BENCH_ASSERT(gsp->st_cache_miss == 0);
}
DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
}
示例4: malloc
static struct nb_db *
nb_db_berkeleydb_open(const struct nb_db_opts *opts)
{
struct nb_db_berkeleydb *berkeleydb = malloc(sizeof(*berkeleydb));
if (berkeleydb == NULL) {
fprintf(stderr, "malloc(%zu) failed", sizeof(*berkeleydb));
goto error_1;
}
int r;
r = mkdir(opts->path, 0777);
if (r != 0 && errno != EEXIST) {
fprintf(stderr, "mkdir: %d\n", r);
goto error_1;
}
DB_ENV *env;
DB *db;
int env_flags = DB_REGION_INIT;
r = db_env_create(&env, 0);
if (r != 0) {
fprintf(stderr, "db_env_create: %s\n",
db_strerror(r));
goto error_1;
}
r = env->set_cachesize(env, 0, 0, 1);
if (r != 0) {
fprintf(stderr, "set_cachesize: %s\n",
db_strerror(r));
goto error_2;
}
env_flags |= DB_TXN_WRITE_NOSYNC;
r = env->set_flags(env, env_flags, 1);
if (r != 0) {
fprintf(stderr, "set_flags: %s\n",
db_strerror(r));
goto error_2;
}
int log_flags = DB_LOG_AUTO_REMOVE;
r = env->log_set_config(env, log_flags, 1);
int env_open_flags = DB_CREATE|DB_INIT_MPOOL;
r = env->open(env, opts->path, env_open_flags, 0666);
if (r != 0) {
fprintf(stderr, "env->open: %s\n",
db_strerror(r));
goto error_2;
}
r = db_create(&db, env, 0);
if (r != 0) {
fprintf(stderr, "db_create: %s\n",
db_strerror(r));
goto error_2;
}
int open_flags = DB_CREATE;
r = db->open(db, NULL, "data.bdb", NULL, DB_BTREE, open_flags, 0664);
if (r != 0) {
fprintf(stderr, "db->open: %s\n",
db_strerror(r));
goto error_3;
}
berkeleydb->env = env;
berkeleydb->db = db;
return (struct nb_db *) berkeleydb;
error_3:
db->close(db, 0);
error_2:
env->close(env, 0);
error_1:
return NULL;
}