# opendb_hybrid

> ## Directory

> > eXtremeDB_rt/samples/opendb_hybrid

> ## Description

> > Demonstrates opening a hybrid database using a conventional memory device and a flash simulator.

> ## Used API

> > mco_db_open_dev()

> ## Code snippet

> >         /* Using flash simulator */
> >         fsp.page_size       = P_RAMFLASH_PAGE_SIZE;
> >         fsp.pages_per_block = P_RAMFLASH_PAGES_PER_BLOCK;
> >         fsp.n_blocks        = P_RAMFLASH_NUM_BLOCKS;
> >         fsp.image_filename  = g_flash_image_file_name;

> >         /* Setup database memory device as a plain conventional memory region */
> >         dev[0].type       = MCO_MEMORY_CONV;                /* Set the device as a conventional memory device */
> >         dev[0].assignment = MCO_MEMORY_ASSIGN_DATABASE;     /* Assign the device as main database memory */
> >         dev[0].size       = P_DB_SIZE;                      /* Set the device size */
> >         dev[0].dev.conv.ptr = (char*)malloc( dev[0].size ); /* Allocate memory and set device pointer */
> >         dev[0].dev.conv.flags = 0;

> >         dev[1].type       = MCO_MEMORY_CONV;                /* Set the device as a conventional memory device */
> >         dev[1].assignment = MCO_MEMORY_ASSIGN_CACHE;        /* Assign the device as a cache buffer */
> >         dev[1].size       = P_DB_CACHE_SZ;                  /* Set the device size */
> >         dev[1].dev.conv.ptr = (char*)malloc( dev[1].size);  /* Allocate memory and set device pointer */
> >         dev[1].dev.conv.flags = 0;

> >         dev[2].type       = MCO_MEMORY_CONV;                /* Set the device as a conventional memory device */
> >         dev[2].assignment = MCO_MEMORY_ASSIGN_PERSISTENT;   /* Assign the device as a persistent storage */
> >         dev[2].size       = mco_flashsim_memory_size(&fsp); /* Set the device size */
> >         dev[2].dev.conv.ptr = (char*)malloc( dev[2].size);  /* Allocate memory and set device pointer */
> >         dev[2].dev.conv.flags = 0;

> >         /* Initialize and customize the database parameters */
> >         mco_db_params_init ( &db_params );               /* Initialize the params with default values */

> >         db_params.mode_mask                 = P_DB_MODE_MASK;
> >         db_params.mem_page_size             = P_DB_MEM_PAGE_SZ;     /* Set page size for the in-memory part */
> >         db_params.disk_page_size            = P_RAMFLASH_PAGE_SIZE; /* Set page size for the persistent part */
> >         db_params.disk_max_database_size    = P_DB_DISK_MAX_SIZE;
> >         db_params.db_max_connections        = 16;                                /* Set total number of connections to the database */

> >         db_params.meta_cache_lines          = P_DB_META_CACHE_LINES;
> >         db_params.meta_cache_ways           = P_DB_META_CACHE_WAYS;
> >         db_params.flash_gc_ratio            = P_DB_FLASH_GC_RATIO;

> >         db_params.filesys_media_ptr         = &fsp;

> >         /* Open a database on the device with given params */
> >         rc = mco_db_open_dev(db_name, hybriddb_get_dictionary(), dev, sizeof(dev)/sizeof(dev[0]), &db_params );
> >         if ( MCO_S_OK == rc ) {
> >         ...

> ## What to expect as an output

> >         ./target/bin/opendb_hybrid

> >         Initialize MCO runtime : Successful
> >         Sample 'opendb_hybrid' opens a hybrid database using conventional memory and the flash sim.

> >         eXtremeDB/rt runtime version 1.4, Fusion Debug
> >         Copyright (c) 2001-2024 McObject LLC. All Rights Reserved.

> >     	Open database : Successful

> >     	The opened database has the following characteristics:

> >     	Evaluation runtime ______ : no
> >     	Check-level _____________ : 3
> >     	Multithread support _____ : yes
> >     	Fixedrec support ________ : yes
> >     	Shared memory support ___ : no
> >     	Statistics support ______ : yes
> >     	Events support __________ : yes
> >     	Save/Load support _______ : yes
> >     	RTree index support _____ : yes
> >     	Unicode support _________ : yes
> >     	WChar support ___________ : no
> >     	Persistent storage support: yes
> >     	Direct pointers mode ____ : no

> >     	Close database : Successful------ FLASH statistic (image file NULL) ------
> >         FLASH reads                :          0        0 Mb   (0 Mb by page)
> >         FLASH progs                :          0        0 Mb
> >         FLASH erases               :          0        0 Mb
> >         FLASH copies               :          0        0 Mb
> >         FLASH is_free              :          0
> >         FLASH is_bad               :          0
> >         FLASH mark_bad             :          0
> >         FLASH syncs                :          0
> >         FLASH time                 :          0
> >         Bad block map :
> >         ................................................................................................................................
> >         ...
> >         0 bad blocks (0 not flagged). Erases min/max : 0 / 0