Adding support for BDBERL_SYSTEM_MEM which sets DB_SYSTEM_MEM flag on environment open; add support for changing default page size via BDBERL_PAGE_SIZE. Must be a power of 2.

This commit is contained in:
Dave Smith 2009-05-04 13:39:35 -06:00
parent e015bf415c
commit e3e0b99494

View file

@ -128,6 +128,11 @@ static ErlDrvRWLock* G_LOG_RWLOCK = 0;
static ErlDrvTermData G_LOG_PID;
static ErlDrvPort G_LOG_PORT;
/**
* Default page size to use for newly created databases
*/
static unsigned int G_PAGE_SIZE = 0;
/**
*
*/
@ -187,6 +192,13 @@ DRIVER_INIT(bdberl_drv)
DB_USE_ENVIRON | /* Use DB_HOME environment variable */
DB_THREAD; /* Make the environment free-threaded */
// Check for environment flag which indicates we want to use DB_SYSTEM_MEM
char* use_system_mem = getenv("BDBERL_SYSTEM_MEM");
if (use_system_mem != 0)
{
flags |= DB_SYSTEM_MEM;
}
// Initialize global environment -- use environment variable DB_HOME to
// specify where the working directory is
G_DB_ENV_ERROR = db_env_create(&G_DB_ENV, 0);
@ -247,6 +259,18 @@ DRIVER_INIT(bdberl_drv)
}
}
// Initialize default page size
char* page_size_str = getenv("BDBERL_PAGE_SIZE");
if (page_size_str != 0)
{
// Convert to integer and only set it if it is a power of 2.
unsigned int page_size = atoi(page_size_str);
if (page_size != 0 && ((page_size & (~page_size +1)) == page_size))
{
G_PAGE_SIZE = page_size;
}
}
// Make sure we can distiguish between lock timeouts and deadlocks
G_DB_ENV->set_flags(G_DB_ENV, DB_TIME_NOTGRANTED, 1);
@ -831,6 +855,15 @@ static int open_database(const char* name, DBTYPE type, unsigned int flags, Port
return rc;
}
// If a custom page size has been specified, try to use it
if (G_PAGE_SIZE > 0)
{
if (db->set_pagesize(db, G_PAGE_SIZE) != 0)
{
bdb_errcall(G_DB_ENV, "", "Failed to set page size.");
}
}
// Attempt to open our database
rc = db->open(db, 0, name, 0, type, flags, 0);
if (rc != 0)