eX
tremeDB作为一种内存数据库,可以根据实际应用的需要,使用多样的内存,比如本地内存,共享内存,NVRAM等等。在实际的应用中,有时候会存在运行在同一台server上的多个应用访问部署在同一个server上的
eX
tremeDB,这时候就需要使用共享内存来存储数据供多个应用访问。
当使用共享内存时,
eX
tremeDB可以由其中的某一个应用来初始化创建,或者由单独的一个进程来创建。而其它的应用只需要直接连接
eX
tremeDB。部分代码示例如下:
-
/* start eXtremeDB runtime */
-
/* optionally set access mode, default is 0666 */
-
mco_runtime_setoption(MCO_RT_OPTION_UNIX_SHM_MASK, 0600 );
-
rc = mco_runtime_start();
-
if ( rc == MCO_S_OK ) {
-
-
/* try to connect to database first */
-
rc = mco_db_connect( db_name, &connection );
-
-
if ( MCO_E_NOINSTANCE == rc ) {
-
-
/* No db found. Open the database and perform tasks of the main process */
-
rc = open_database( db_name, simpledb_get_dictionary(), DATABASE_SIZE, CACHE_SIZE,
-
MEMORY_PAGE_SIZE, PSTORAGE_PAGE_SIZE, 1, &dbmem );
-
-
if ( MCO_S_OK == rc ) {
-
-
/* connect by name */
-
rc = mco_db_connect( db_name, &connection );
-
-
/* disconnect */
-
rc = mco_db_disconnect( connection );
-
}
-
-
} else if ( MCO_S_OK == rc ) {
-
-
/* database connection successful, perform tasks of the secondary process */
-
printf("\n\n\tConnection successful, perform tasks from secondary process...\n" );
-
-
/* don't forget to disconnect when done */
-
rc = mco_db_disconnect( connection );
-
sample_rc_check("\tDisconnect secondary process", rc );
-
-
} else {
-
/* handle unexpected error on connect */
-
}
-
-
/* stop eXtremeDB runtime */
-
mco_runtime_stop();
-
}
阅读(1078) | 评论(0) | 转发(0) |