#include <stddef.h>
#include <stdint.h>
#include "op_list.h"
Go to the source code of this file.
This file contains various definitions and interface for management of in-memory, through mmaped file, growable hash table, that stores sample files.
Definition in file odb.h.
#define BUCKET_FACTOR 1 |
Definition at line 39 of file odb.h.
Referenced by check_circular_list(), odb_check_hash(), odb_grow_hashtable(), odb_hash_stat(), odb_open(), and tables_size().
#define ODB_NODE_NR_INVALID ((odb_node_nr_t)-1) |
typedef struct odb_data odb_data_t |
a "database". this is an in memory only description.
We allow to manage a database inside a mapped file with an "header" of unknown size so odb_open get a parameter to specify the size of this header. A typical use is:
struct header { int etc; ... }; odb_open(&hash, filename, ODB_RW, sizeof(header)); so on this library have no dependency on the header type.
the internal memory layout from base_memory is: the unknown header (sizeof_header) odb_descr_t the node array: (descr->size * sizeof(odb_node_t) entries the hash table: array of odb_index_t indexing the node array (descr->size * BUCKET_FACTOR) entries
typedef odb_index_t odb_hash_mask_t |
typedef struct odb_hash_stat_t odb_hash_stat_t |
typedef unsigned int odb_index_t |
typedef uint64_t odb_key_t |
typedef odb_index_t odb_node_nr_t |
typedef unsigned int odb_value_t |
enum odb_rw |
int odb_add_node | ( | odb_t * | odb, | |
odb_key_t | key, | |||
odb_value_t | value | |||
) |
Add a new node w/o regarding if a node with the same key already exists
returns EXIT_SUCCESS on success, EXIT_FAILURE on failure
Definition at line 106 of file db_insert.c.
References add_node(), and odb_t::data.
Referenced by import_from_abi(), and main().
int odb_check_hash | ( | odb_t const * | odb | ) |
check that the hash is well built
Definition at line 90 of file db_debug.c.
References BUCKET_FACTOR, check_circular_list(), check_redundant_key(), odb_descr_t::current_size, odb_t::data, odb_data::descr, odb_data::hash_base, odb_node_t::key, odb_node_t::next, odb_data::node_base, and odb_descr_t::size.
Referenced by sanity_check(), and test().
void odb_close | ( | odb_t * | odb | ) |
Close the given ODB file
Definition at line 263 of file db_manage.c.
References odb_data::base_memory, odb_t::data, odb_data::descr, odb_data::fd, odb_data::filename, odb_data::list, list_del(), odb_data::ref_count, odb_descr_t::size, and tables_size().
Referenced by close_sfile(), ibs_sfile_close(), main(), opd_24_sfile_lru_clear(), opd_close_image_samples_files(), sanity_check(), speed_test(), and test().
static __inline void odb_commit_reservation | ( | odb_data_t * | data | ) | [static] |
commit a previously successfull node reservation. This can't fail.
Definition at line 156 of file odb.h.
References odb_descr_t::current_size, and odb_data::descr.
Referenced by add_node().
static __inline unsigned int odb_do_hash | ( | odb_data_t const * | data, | |
odb_key_t | value | |||
) | [static] |
Definition at line 221 of file odb.h.
References odb_data::hash_mask.
Referenced by add_node(), odb_grow_hashtable(), and odb_update_node_with_offset().
void* odb_get_data | ( | odb_t * | odb | ) |
return the start of the mapped data
Definition at line 291 of file db_manage.c.
References odb_data::base_memory, and odb_t::data.
Referenced by import_from_abi(), main(), opd_open_24_sample_file(), opd_open_sample_file(), and operf_open_sample_file().
odb_node_t* odb_get_iterator | ( | odb_t const * | odb, | |
odb_node_nr_t * | nr | |||
) |
return a base pointer to the node array and number of node in this array caller then will iterate through:
odb_node_nr_t node_nr, pos; odb_node_t * node = odb_get_iterator(odb, &node_nr); for ( pos = 0 ; pos < node_nr ; ++pos) // do something
note than caller does not need to filter nil key as it's a valid key, The returned range is all valid (i.e. should never contain zero value).
Definition at line 13 of file db_travel.c.
References odb_descr_t::current_size, odb_t::data, odb_data::descr, and odb_data::node_base.
int odb_grow_hashtable | ( | odb_data_t * | data | ) |
grow the hashtable in such way current_size is the index of the first free node. Take care all node pointer can be invalidated by this call.
Node allocation is done in a two step way 1st) ensure a free node exist eventually, caller can setup it, 2nd) commit the node allocation with odb_commit_reservation(). This is done in this way to ensure node setup is visible from another process like pp tools in an atomic way.
returns 0 on success, non zero on failure in this case this function do nothing and errno is set by the first libc call failure allowing to retry after cleanup some program resource.
Definition at line 63 of file db_manage.c.
References odb_data::base_memory, BUCKET_FACTOR, odb_descr_t::current_size, odb_data::descr, odb_data::fd, odb_data::hash_base, odb_data::hash_mask, odb_node_t::key, odb_node_t::next, odb_data::node_base, odb_do_hash(), odb_to_descr(), odb_to_hash_base(), odb_to_node_base(), odb_descr_t::size, and tables_size().
Referenced by add_node().
void odb_hash_display_stat | ( | odb_hash_stat_t const * | stats | ) |
Definition at line 74 of file db_stat.c.
References odb_hash_stat_t::average_list_length, odb_hash_stat_t::hash_table_size, odb_hash_stat_t::max_list_length, odb_hash_stat_t::node_nr, odb_hash_stat_t::total_count, and odb_hash_stat_t::used_node_nr.
Referenced by sanity_check().
void odb_hash_free_stat | ( | odb_hash_stat_t * | stats | ) |
Definition at line 85 of file db_stat.c.
Referenced by sanity_check().
odb_hash_stat_t* odb_hash_stat | ( | odb_t const * | odb | ) |
Definition at line 28 of file db_stat.c.
References odb_hash_stat_t::average_list_length, BUCKET_FACTOR, odb_descr_t::current_size, odb_t::data, odb_data::descr, odb_data::hash_base, odb_hash_stat_t::hash_table_size, odb_hash_stat_t::max_list_length, odb_node_t::next, odb_data::node_base, odb_hash_stat_t::node_nr, odb_descr_t::size, odb_hash_stat_t::total_count, odb_hash_stat_t::used_node_nr, and odb_node_t::value.
Referenced by sanity_check().
void odb_init | ( | odb_t * | odb | ) |
odb_init - initialize a DB file
odb | the DB file to init |
Definition at line 120 of file db_manage.c.
References odb_t::data.
Referenced by create_sfile(), ibs_sfile_create(), ibs_sfile_dup(), opd_open_24_sample_file(), operf_sfile_dup(), and sfile_dup().
Definition at line 162 of file db_manage.c.
References odb_data::base_memory, BUCKET_FACTOR, odb_descr_t::current_size, odb_t::data, DEFAULT_NODE_NR, odb_data::descr, odb_data::fd, odb_data::filename, files_hash, FILES_HASH_SIZE, find_samples_data(), odb_data::hash_base, odb_data::hash_mask, odb_data::list, list_add(), list_init(), odb_data::node_base, ODB_RDONLY, ODB_RDWR, odb_to_descr(), odb_to_hash_base(), odb_to_node_base(), odb_data::offset_node, op_hash_string(), odb_data::ref_count, odb_descr_t::size, odb_data::sizeof_header, and tables_size().
Referenced by main(), opd_open_24_sample_file(), opd_open_sample_file(), operf_open_sample_file(), sanity_check(), speed_test(), and test().
int odb_open_count | ( | odb_t const * | odb | ) |
return the number of times this sample file is open
Definition at line 283 of file db_manage.c.
References odb_t::data, and odb_data::ref_count.
Referenced by get_file(), ibs_sfile_get(), and opd_put_image_sample().
void odb_sync | ( | odb_t const * | odb | ) |
issue a msync on the used size of the mmaped file
Definition at line 297 of file db_manage.c.
References odb_data::base_memory, odb_t::data, odb_data::descr, odb_descr_t::size, and tables_size().
Referenced by ibs_sfile_sync(), opd_sync_samples_files(), and sync_sfile().
update info at key by incrementing its associated value by one, if the key does not exist a new node is created and the value associated is set to one.
returns EXIT_SUCCESS on success, EXIT_FAILURE on failure
Definition at line 52 of file db_insert.c.
References odb_update_node_with_offset().
Referenced by opd_put_image_sample(), operf_sfile_log_arc(), sfile_log_arc(), speed_test(), and test().
odb_update_node_with_offset
odb | the data base object to setup | |
key | the hash key | |
offset | the offset to be added |
update info at key by adding the specified offset to its associated value, if the key does not exist a new node is created and the value associated is set to offset.
returns EXIT_SUCCESS on success, EXIT_FAILURE on failure
Definition at line 57 of file db_insert.c.
References add_node(), odb_t::data, odb_data::hash_base, odb_node_t::key, odb_node_t::next, odb_data::node_base, odb_do_hash(), and odb_node_t::value.
Referenced by odb_update_node(), operf_sfile_log_sample_count(), and sfile_log_sample_count().