# flash-crud

## Directory

> eXtremeDB_rt/samples/flash-crud/

## Description

> "flash-crud" sample demonstrates CRUD operations atop of the flash simulator.

## Used API

> mco_system_get_current_time()

## Code snippet

>         static MCO_RET create_database(const char *db_name, mco_device_t *devs)
>         {
>             mco_db_params_t db_params;
>             /* Using flash simulator */
>             mco_flashsim_params_t fsp = {0};

>             devs[0].assignment = MCO_MEMORY_ASSIGN_DATABASE;
>             devs[0].size = P_DB_SIZE;
>             devs[0].type = MCO_MEMORY_CONV;
>             devs[0].dev.conv.ptr = (char*)malloc(devs[0].size);

>             devs[1].assignment = MCO_MEMORY_ASSIGN_CACHE;
>             devs[1].size = P_DB_CACHE_SZ;
>             devs[1].type = MCO_MEMORY_CONV;
>             devs[1].dev.conv.ptr = (char*)malloc(devs[1].size);

>             devs[2].assignment = MCO_MEMORY_ASSIGN_PERSISTENT;
>             devs[2].size = P_FLASHSIM_SZ;
>             devs[2].type = MCO_MEMORY_CONV;
>             devs[2].dev.conv.ptr = (char*)malloc(devs[2].size);

>             fsp.page_size = P_RAMFLASH_PAGE_SIZE;
>             fsp.pages_per_block = P_RAMFLASH_PAGES_PER_BLOCK;
>             fsp.n_blocks = P_RAMFLASH_NUM_BLOCKS;
>             fsp.print_stat = MCO_YES;
>             fsp.image_filename = g_flash_image_file_name;

>             mco_db_params_init(&db_params);
>             db_params.mode_mask = P_DB_MODE_MASK;
>             db_params.mem_page_size = P_DB_MEM_PAGE_SZ;
>             db_params.disk_page_size = P_DB_DISK_PAGE_SZ;
>             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;

>             return mco_db_open_dev(db_name, crud_get_dictionary(), devs, 4, &db_params);
>         }

## What to expect as an output

>     	1421 iterations done, 12753 objects. Data file size 1550336, Used db size 1551104
>     	1422 iterations done, 12753 objects. Data file size 1550336, Used db size 1551104
>     	1426 read iterations
>     	14261 write iterations
>     	------ FLASH statistic (image file <NULL>) ------
>     	FLASH reads                :   59507998    67978 Mb   (116226 Mb by page)
>     	FLASH progs                :      24944       48 Mb
>     	FLASH erases               :        557       69 Mb
>     	FLASH copies               :      10656       20 Mb
>     	FLASH is_free              :          0
>     	FLASH is_bad               :       1087
>     	FLASH mark_bad             :          0
>     	FLASH syncs                :       1428
>     	FLASH time                 :          0
>     	Bad block map :
>     	........
>     	0 bad blocks