Chinaunix首页 | 论坛 | 博客
  • 博客访问: 62926
  • 博文数量: 33
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 345
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-02 08:41
文章分类

全部博文(33)

文章存档

2015年(13)

2014年(20)

我的朋友

分类: 数据库开发技术

2014-12-12 20:41:57

    eXtremeDB作为一种内存数据库,可以根据实际应用的需要,使用多样的内存,比如本地内存,共享内存,NVRAM等等。在实际的应用中,有时候会存在运行在同一台server上的多个应用访问部署在同一个server上的eXtremeDB,这时候就需要使用共享内存来存储数据供多个应用访问。
    当使用共享内存时,eXtremeDB可以由其中的某一个应用来初始化创建,或者由单独的一个进程来创建。而其它的应用只需要直接连接eXtremeDB。部分代码示例如下:

点击(此处)折叠或打开

  1. /* start eXtremeDB runtime */
  2.   /* optionally set access mode, default is 0666 */
  3.   mco_runtime_setoption(MCO_RT_OPTION_UNIX_SHM_MASK, 0600 );
  4.   rc = mco_runtime_start();
  5.   if ( rc == MCO_S_OK ) {

  6.     /* try to connect to database first */
  7.     rc = mco_db_connect( db_name, &connection );
  8.     
  9.     if ( MCO_E_NOINSTANCE == rc ) {
  10.         
  11.       /* No db found. Open the database and perform tasks of the main process */
  12.       rc = open_database( db_name, simpledb_get_dictionary(), DATABASE_SIZE, CACHE_SIZE,
  13.                                    MEMORY_PAGE_SIZE, PSTORAGE_PAGE_SIZE, 1, &dbmem );
  14.                                      
  15.       if ( MCO_S_OK == rc ) {

  16.         /* connect by name */
  17.         rc = mco_db_connect( db_name, &connection );
  18.        
  19.         /* disconnect */
  20.         rc = mco_db_disconnect( connection );
  21.       }
  22.   
  23.     } else if ( MCO_S_OK == rc ) {
  24.       
  25.       /* database connection successful, perform tasks of the secondary process */
  26.       printf("\n\n\tConnection successful, perform tasks from secondary process...\n" );

  27.       /* don't forget to disconnect when done */
  28.       rc = mco_db_disconnect( connection );
  29.       sample_rc_check("\tDisconnect secondary process", rc );
  30.   
  31.     } else {
  32.       /* handle unexpected error on connect */
  33.     }
  34.         
  35.     /* stop eXtremeDB runtime */
  36.     mco_runtime_stop();
  37.   }

阅读(1038) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~