mariadb/bdb/log/log_method.c

189 lines
4.2 KiB
C
Raw Normal View History

2001-03-05 01:42:05 +01:00
/*-
* See the file LICENSE for redistribution information.
*
2002-10-30 12:57:05 +01:00
* Copyright (c) 1999-2002
2001-03-05 01:42:05 +01:00
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
2002-10-30 12:57:05 +01:00
static const char revid[] = "$Id: log_method.c,v 11.32 2002/05/30 22:16:47 bostic Exp $";
2001-03-05 01:42:05 +01:00
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
2002-10-30 12:57:05 +01:00
#ifdef HAVE_RPC
#include <rpc/rpc.h>
#endif
2001-03-05 01:42:05 +01:00
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#endif
#include "db_int.h"
2002-10-30 12:57:05 +01:00
#include "dbinc/log.h"
2001-03-05 01:42:05 +01:00
#ifdef HAVE_RPC
2002-10-30 12:57:05 +01:00
#include "dbinc_auto/db_server.h"
#include "dbinc_auto/rpc_client_ext.h"
2001-03-05 01:42:05 +01:00
#endif
static int __log_set_lg_bsize __P((DB_ENV *, u_int32_t));
static int __log_set_lg_dir __P((DB_ENV *, const char *));
2002-10-30 12:57:05 +01:00
static int __log_set_lg_max __P((DB_ENV *, u_int32_t));
static int __log_set_lg_regionmax __P((DB_ENV *, u_int32_t));
2001-03-05 01:42:05 +01:00
/*
* __log_dbenv_create --
* Log specific initialization of the DB_ENV structure.
*
* PUBLIC: void __log_dbenv_create __P((DB_ENV *));
*/
void
__log_dbenv_create(dbenv)
DB_ENV *dbenv;
{
2002-10-30 12:57:05 +01:00
/*
* !!!
* Our caller has not yet had the opportunity to reset the panic
* state or turn off mutex locking, and so we can neither check
* the panic state or acquire a mutex in the DB_ENV create path.
*/
2001-03-05 01:42:05 +01:00
2002-10-30 12:57:05 +01:00
dbenv->lg_bsize = LG_BSIZE_DEFAULT;
dbenv->lg_regionmax = LG_BASE_REGION_SIZE;
2001-03-05 01:42:05 +01:00
#ifdef HAVE_RPC
/*
* If we have a client, overwrite what we just setup to
* point to client functions.
*/
if (F_ISSET(dbenv, DB_ENV_RPCCLIENT)) {
dbenv->set_lg_bsize = __dbcl_set_lg_bsize;
dbenv->set_lg_dir = __dbcl_set_lg_dir;
2002-10-30 12:57:05 +01:00
dbenv->set_lg_max = __dbcl_set_lg_max;
dbenv->set_lg_regionmax = __dbcl_set_lg_regionmax;
dbenv->log_archive = __dbcl_log_archive;
dbenv->log_cursor = __dbcl_log_cursor;
dbenv->log_file = __dbcl_log_file;
dbenv->log_flush = __dbcl_log_flush;
dbenv->log_put = __dbcl_log_put;
dbenv->log_stat = __dbcl_log_stat;
} else
2001-03-05 01:42:05 +01:00
#endif
2002-10-30 12:57:05 +01:00
{
dbenv->set_lg_bsize = __log_set_lg_bsize;
dbenv->set_lg_dir = __log_set_lg_dir;
dbenv->set_lg_max = __log_set_lg_max;
dbenv->set_lg_regionmax = __log_set_lg_regionmax;
dbenv->log_archive = __log_archive;
dbenv->log_cursor = __log_cursor;
dbenv->log_file = __log_file;
dbenv->log_flush = __log_flush;
dbenv->log_put = __log_put;
dbenv->log_stat = __log_stat;
}
2001-03-05 01:42:05 +01:00
}
/*
* __log_set_lg_bsize --
* Set the log buffer size.
*/
static int
__log_set_lg_bsize(dbenv, lg_bsize)
DB_ENV *dbenv;
u_int32_t lg_bsize;
{
2002-10-30 12:57:05 +01:00
u_int32_t lg_max;
2001-03-05 01:42:05 +01:00
ENV_ILLEGAL_AFTER_OPEN(dbenv, "set_lg_bsize");
2002-10-30 12:57:05 +01:00
if (lg_bsize == 0)
lg_bsize = LG_BSIZE_DEFAULT;
2001-03-05 01:42:05 +01:00
/* Let's not be silly. */
2002-10-30 12:57:05 +01:00
lg_max = dbenv->lg_size == 0 ? LG_MAX_DEFAULT : dbenv->lg_size;
if (lg_bsize > lg_max / 4) {
2001-03-05 01:42:05 +01:00
__db_err(dbenv, "log buffer size must be <= log file size / 4");
return (EINVAL);
}
dbenv->lg_bsize = lg_bsize;
return (0);
}
/*
* __log_set_lg_max --
* Set the maximum log file size.
*/
static int
__log_set_lg_max(dbenv, lg_max)
DB_ENV *dbenv;
u_int32_t lg_max;
{
2002-10-30 12:57:05 +01:00
LOG *region;
if (lg_max == 0)
lg_max = LG_MAX_DEFAULT;
if (F_ISSET(dbenv, DB_ENV_OPEN_CALLED)) {
if (!LOGGING_ON(dbenv))
return (__db_env_config(
dbenv, "set_lg_max", DB_INIT_LOG));
region = ((DB_LOG *)dbenv->lg_handle)->reginfo.primary;
/* Let's not be silly. */
if (lg_max < region->buffer_size * 4)
goto err;
region->log_nsize = lg_max;
} else {
/* Let's not be silly. */
if (lg_max < dbenv->lg_bsize * 4)
goto err;
dbenv->lg_size = lg_max;
}
return (0);
err: __db_err(dbenv, "log file size must be >= log buffer size * 4");
return (EINVAL);
}
/*
* __log_set_lg_regionmax --
* Set the region size.
*/
static int
__log_set_lg_regionmax(dbenv, lg_regionmax)
DB_ENV *dbenv;
u_int32_t lg_regionmax;
{
ENV_ILLEGAL_AFTER_OPEN(dbenv, "set_lg_regionmax");
2001-03-05 01:42:05 +01:00
/* Let's not be silly. */
2002-10-30 12:57:05 +01:00
if (lg_regionmax != 0 && lg_regionmax < LG_BASE_REGION_SIZE) {
__db_err(dbenv,
"log file size must be >= %d", LG_BASE_REGION_SIZE);
2001-03-05 01:42:05 +01:00
return (EINVAL);
}
2002-10-30 12:57:05 +01:00
dbenv->lg_regionmax = lg_regionmax;
2001-03-05 01:42:05 +01:00
return (0);
}
/*
* __log_set_lg_dir --
* Set the log file directory.
*/
static int
__log_set_lg_dir(dbenv, dir)
DB_ENV *dbenv;
const char *dir;
{
if (dbenv->db_log_dir != NULL)
2002-10-30 12:57:05 +01:00
__os_free(dbenv, dbenv->db_log_dir);
2001-03-05 01:42:05 +01:00
return (__os_strdup(dbenv, dir, &dbenv->db_log_dir));
}