Create a database on the specified device(s).
MCO_RET mco_db_open_dev( /*IN*/ const char * dbname, /*IN*/ mco_dictionary_h dict, /*IN*/ mco_device_t * devs, /*IN*/ mco_size_t n_devs, /*IN*/ mco_db_params_t * params );
dbname | The name of the database to open. Taken from the declare database dbname DDL statement. Note that the maximum database name length is 16 characters |
dict | A handle to the dictionary that was created by the eXtremeDB schema compiler mcocomp . Normally, this handle is passed in by dbname_get_dictionary() |
devs | Memory devices (array of mco_device_t ) |
n_devs | Number of device specifications in array devs |
params | Database specification parameters |
This function creates the database
dbname
on the devices defined bydevs
according to the parameters specified inparams
. (See mco_device_t for detailed description of the memory device structuredevs
andmco_db_params_t
for the database parametersparams
.
The following example code demonstrates how to define the memory devices and database parameters and call mco_db_open_dev()
for an all-in-memory database:
Application snippet: /* All-in-memory example */ #define DATABASE_SEGMENT_SIZE 16 * 1024 * 1024 #define MEMORY_PAGE_SIZE 128 const char * dbname = "convdb"; int main(int argc, char* argv[]) { MCO_RET rc; mco_device_t dev; mco_db_params_t db_params; mco_runtime_start(); /* setup memory device as a plain conventional memory region */ dev.type = MCO_MEMORY_CONV; /* conventional mem. */ dev.assignment = MCO_MEMORY_ASSIGN_DATABASE; /* main database mem.*/ dev.size = DATABASE_SEGMENT_SIZE; /* device size */ dev.dev.conv.ptr = (void*)malloc( DATABASE_SEGMENT_SIZE ); if( !dev.dev.conv.ptr ) exit; /* initialize and customize the database parameters */ mco_db_params_init ( &db_params );/* initialize with default values */ db_params.mem_page_size = MEMORY_PAGE_SIZE; /* in-mem. part */ db_params.disk_page_size = 0; /* disable disk operations */ db_params.db_max_connections = 1; /* total connections to db */ /* open a database on the device with given params */ rc = mco_db_open_dev(dbname, convdb_get_dictionary(), &dev, 1, &db_params ); ... }
The next example code demonstrates how to define the memory devices and database parameters and call mco_db_open_dev()
for a persistent database:
/* Persistent database example */ #define MEMORY_PAGE_SIZE 128 #define DISK_PAGE_SIZE 128 #define DB_LOG_TYPE REDO_LOG #define REDO_LOG_SIZE ( 2 * 1024 * 1024 ) const char * dbname = "diskdb"; int main(int argc, char* argv[]) { MCO_RET rc; mco_device_t dev[4]; mco_db_params_t db_params; dev[0].type = MCO_MEMORY_CONV; dev[0].assignment = MCO_MEMORY_ASSIGN_DATABASE; dev[0].size = DATABASE_SEGMENT_SIZE; dev[1].type = MCO_MEMORY_CONV; dev[1].assignment = MCO_MEMORY_ASSIGN_CACHE; dev[1].size = CACHE_SEGMENT_SIZE; dev[2].type = MCO_MEMORY_FILE; dev[2].assignment = MCO_MEMORY_ASSIGN_PERSISTENT; sprintf( dev[2].dev.file.name, FILE_PREFIX "%s.dbs", dbname ); dev[2].dev.file.flags = MCO_FILE_OPEN_DEFAULT; dev[3].type = MCO_MEMORY_FILE; dev[3].assignment = MCO_MEMORY_ASSIGN_LOG; sprintf( dev[3].dev.file.name, FILE_PREFIX "%s.log", dbname ); dev[3].dev.file.flags = MCO_FILE_OPEN_DEFAULT; /* allocate memory for the database and cache*/ dev[0].dev.conv.ptr = (void*)malloc( DATABASE_SEGMENT_SIZE ); if( !dev[0].dev.conv.ptr ) exit; dev[1].dev.conv.ptr = (void*)malloc( CACHE_SEGMENT_SIZE ); if( !dev[1].dev.conv.ptr ) exit; /* set default database parameters */ mco_db_params_init ( &db_params ); /* customize the parameters */ db_params.mem_page_size = MEMORY_PAGE_SIZE; db_params.disk_page_size = DISK_PAGE_SIZE; db_params.db_max_connections = 1; db_params.disk_max_database_size = MAXIMUM_DATABASE_SIZE; db_params.db_log_type = DB_LOG_TYPE; db_params.log_params.redo_log_limit = REDO_LOG_SIZE; rc = mco_db_open_dev( dbname , diskdb_get_dictionary(), dev, sizeof(dev)/sizeof(dev[0]), &db_params ); ... }