本文整理汇总了C++中DB_ENV::set_lg_bsize方法的典型用法代码示例。如果您正苦于以下问题:C++ DB_ENV::set_lg_bsize方法的具体用法?C++ DB_ENV::set_lg_bsize怎么用?C++ DB_ENV::set_lg_bsize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB_ENV
的用法示例。
在下文中一共展示了DB_ENV::set_lg_bsize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestSetLogBufferSize
int TestSetLogBufferSize(CuTest *ct) {
DB_ENV *dbenv;
u_int32_t v;
dbenv = NULL;
/* lg_bsize: NOT reset at run-time. */
ENV
CuAssertTrue(ct, dbenv->set_lg_bsize(dbenv, 37 * 1024) == 0);
CuAssertTrue(ct, dbenv->open(dbenv,
TEST_ENV, DB_CREATE | DB_INIT_LOG, 0666) == 0);
CuAssertTrue(ct, dbenv->get_lg_bsize(dbenv, &v) == 0);
CuAssertTrue(ct, v == 37 * 1024);
ENV
CuAssertTrue(ct, dbenv->set_lg_bsize(dbenv, 63 * 1024) == 0);
CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0);
CuAssertTrue(ct, dbenv->get_lg_bsize(dbenv, &v) == 0);
CuAssertTrue(ct, v == 37 * 1024);
return (0);
}
示例2:
void
env_open(DB_ENV **dbenvp)
{
DB_ENV *dbenv;
int ret;
/* Create the environment handle. */
if ((ret = db_env_create(&dbenv, 0)) != 0) {
fprintf(stderr,
"txnapp: db_env_create: %s\n", db_strerror(ret));
exit (1);
}
/* Set up error handling. */
dbenv->set_errpfx(dbenv, "txnapp");
dbenv->set_errfile(dbenv, stderr);
// match lladd's defaults...
dbenv->set_lg_bsize(dbenv, 1024*1024);
// match lladd's defaults...
dbenv->set_cachesize(dbenv, 0, 8204288, 0);
/* Do deadlock detection internally. */
/* if ((ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT)) != 0) {
dbenv->err(dbenv, ret, "set_lk_detect: DB_LOCK_DEFAULT");
exit (1);
}*/
dbenv->set_tx_max(dbenv, 32000);
unsigned int max;
dbenv->get_tx_max(dbenv, &max);
printf("Max xact count: %d\n", max);
/*
* Open a transactional environment:
* create if it doesn't exist
* free-threaded handle
* run recovery
* read/write owner only
*/
if ((ret = dbenv->open(dbenv, ENV_DIRECTORY,
DB_CREATE |/* DB_INIT_LOCK |*/ DB_INIT_LOG | DB_PRIVATE |
DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER | DB_THREAD,
S_IRUSR | S_IWUSR)) != 0) {
dbenv->err(dbenv, ret, "dbenv->open: %s", ENV_DIRECTORY);
exit (1);
}
*dbenvp = dbenv;
}
示例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: 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(
//.........这里部分代码省略.........
示例5: sizeof
int
main()
{
const u_int8_t *lk_conflicts;
DB_ENV *dbenv;
db_timeout_t timeout;
u_int32_t a, b, v;
int lk_modes, ncache, nmodes;
u_int8_t conflicts[40];
dbenv = NULL;
/* tx_max: NOT reset at run-time. */
system("rm -rf TESTDIR; mkdir TESTDIR");
ENV
assert(dbenv->set_tx_max(dbenv, 37) == 0);
assert(dbenv->open(dbenv,
"TESTDIR", DB_CREATE | DB_INIT_TXN, 0666) == 0);
assert(dbenv->get_tx_max(dbenv, &v) == 0);
assert(v == 37);
ENV
assert(dbenv->set_tx_max(dbenv, 63) == 0);
assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
assert(dbenv->get_tx_max(dbenv, &v) == 0);
assert(v == 37);
/* lg_max: reset at run-time. */
system("rm -rf TESTDIR; mkdir TESTDIR");
ENV
assert(dbenv->set_lg_max(dbenv, 37 * 1024 * 1024) == 0);
assert(dbenv->open(dbenv,
"TESTDIR", DB_CREATE | DB_INIT_LOG, 0666) == 0);
assert(dbenv->get_lg_max(dbenv, &v) == 0);
assert(v == 37 * 1024 * 1024);
ENV
assert(dbenv->set_lg_max(dbenv, 63 * 1024 * 1024) == 0);
assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
assert(dbenv->get_lg_max(dbenv, &v) == 0);
assert(v == 63 * 1024 * 1024);
/* lg_bsize: NOT reset at run-time. */
system("rm -rf TESTDIR; mkdir TESTDIR");
ENV
assert(dbenv->set_lg_bsize(dbenv, 37 * 1024) == 0);
assert(dbenv->open(dbenv,
"TESTDIR", DB_CREATE | DB_INIT_LOG, 0666) == 0);
assert(dbenv->get_lg_bsize(dbenv, &v) == 0);
assert(v == 37 * 1024);
ENV
assert(dbenv->set_lg_bsize(dbenv, 63 * 1024) == 0);
assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
assert(dbenv->get_lg_bsize(dbenv, &v) == 0);
assert(v == 37 * 1024);
/* lg_regionmax: NOT reset at run-time. */
system("rm -rf TESTDIR; mkdir TESTDIR");
ENV
assert(dbenv->set_lg_regionmax(dbenv, 137 * 1024) == 0);
assert(dbenv->open(dbenv,
"TESTDIR", DB_CREATE | DB_INIT_LOG, 0666) == 0);
assert(dbenv->get_lg_regionmax(dbenv, &v) == 0);
assert(v == 137 * 1024);
ENV
assert(dbenv->set_lg_regionmax(dbenv, 163 * 1024) == 0);
assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
assert(dbenv->get_lg_regionmax(dbenv, &v) == 0);
assert(v == 137 * 1024);
/* lk_get_lk_conflicts: NOT reset at run-time. */
system("rm -rf TESTDIR; mkdir TESTDIR");
ENV
memset(conflicts, 'a', sizeof(conflicts));
nmodes = 6;
assert(dbenv->set_lk_conflicts(dbenv, conflicts, nmodes) == 0);
assert(dbenv->open(dbenv,
"TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
assert(dbenv->get_lk_conflicts(dbenv, &lk_conflicts, &lk_modes) == 0);
assert(lk_conflicts[0] == 'a');
assert(lk_modes == 6);
ENV
memset(conflicts, 'b', sizeof(conflicts));
nmodes = 8;
assert(dbenv->set_lk_conflicts(dbenv, conflicts, nmodes) == 0);
assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
assert(dbenv->get_lk_conflicts(dbenv, &lk_conflicts, &lk_modes) == 0);
assert(lk_conflicts[0] == 'a');
assert(lk_modes == 6);
/* lk_detect: NOT reset at run-time. */
system("rm -rf TESTDIR; mkdir TESTDIR");
ENV
assert(dbenv->set_lk_detect(dbenv, DB_LOCK_MAXLOCKS) == 0);
assert(dbenv->open(dbenv,
"TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
assert(dbenv->get_lk_detect(dbenv, &v) == 0);
assert(v == DB_LOCK_MAXLOCKS);
ENV
assert(dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT) == 0);
assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
assert(dbenv->get_lk_detect(dbenv, &v) == 0);
//.........这里部分代码省略.........
示例6: malloc
void
op_tds(u_int ops, int update, u_int32_t flags)
{
DB *dbp;
DBT key, data;
DB_ENV *dbenv;
DB_TXN *txn;
char *keybuf, *databuf;
DB_MPOOL_STAT *gsp;
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);
#ifdef DB_AUTO_COMMIT
DB_BENCH_ASSERT(dbenv->set_flags(dbenv, DB_AUTO_COMMIT, 1) == 0);
#endif
DB_BENCH_ASSERT(dbenv->set_flags(dbenv, flags, 1) == 0);
#ifdef DB_LOG_INMEMORY
if (!(flags & DB_LOG_INMEMORY))
#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, "a", NULL, DB_BTREE, DB_CREATE, 0666) == 0);
if (update) {
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;
dbenv->memp_stat(dbenv, &gsp, NULL, 0);
DB_BENCH_ASSERT(gsp->st_page_out == 0);
} else {
DB_BENCH_ASSERT(dbp->put(dbp, NULL, &key, &data, 0) == 0);
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;
dbenv->memp_stat(dbenv, &gsp, NULL, 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);
}
示例7: sizeof
/*
* This should be done before the program is open for business.
* As such, it does not need to be reentrant.
*/
int
open_db_env(char *topdir)
{
DB_ENV *tmpenv = NULL;
int st;
struct stat64 sbuf;
char logdir[MAXPATHLEN+1];
char tmpdir[MAXPATHLEN+1];
char *dirarr[3];
int i;
if (topdir == NULL) {
return (-1);
}
snprintf(logdir, sizeof (tmpdir), "%s/.logs", topdir);
snprintf(tmpdir, sizeof (tmpdir), "%s/.tmp", topdir);
dirarr[0] = topdir;
dirarr[1] = logdir;
dirarr[2] = tmpdir;
/* first, set up the environment */
st = db_env_create(&tmpenv, 0);
if (st != 0) {
return (st);
}
/* make sure the directories exist */
for (i = 0; i < 3; i++) {
st = stat64(dirarr[i], &sbuf);
if ((st != 0) && (errno == ENOENT)) {
st = mkdirp(dirarr[i], 0744);
if (st == 0) {
st = stat64(dirarr[i], &sbuf);
}
}
if ((st == 0) && (!S_ISDIR(sbuf.st_mode))) {
st = -1;
break;
}
}
if (st != 0) {
return (st);
}
st = tmpenv->set_data_dir(tmpenv, topdir);
if (st != 0) {
return (st);
}
st = tmpenv->set_lg_dir(tmpenv, logdir);
if (st != 0) {
return (st);
}
st = tmpenv->set_tmp_dir(tmpenv, tmpdir);
if (st != 0) {
return (st);
}
st = tmpenv->set_flags(tmpenv, env_fl, 1);
if (st != 0) {
return (st);
}
/* overall database cache size */
st = tmpenv->set_cachesize(tmpenv, 0, (60 * MEGA), 1);
st = tmpenv->set_shm_key(tmpenv, FSM_SHM_MASTER_KEY);
if (st != 0) {
return (st);
}
/* log buffer in memory */
st = tmpenv->set_lg_bsize(tmpenv, (30 * MEGA));
if (st != 0) {
return (st);
}
/* set up additional error logging */
tmpenv->set_errcall(tmpenv, fsmdb_log_err);
/* Increase the number of locks available */
tmpenv->set_lk_max_locks(tmpenv, 10000);
tmpenv->set_lk_max_lockers(tmpenv, 10000);
tmpenv->set_lk_max_objects(tmpenv, 10000);
/* Increase the number of concurrent transactions available */
/* Note: Default in 4.4-20 is '20'. In later versions it's 100 */
tmpenv->set_tx_max(tmpenv, 100);
st = tmpenv->open(tmpenv, topdir, env_ofl, 0644);
if (st != 0) {
/* check for a major failure */
//.........这里部分代码省略.........