#include "dictionary.h"
#include "../file/sd_stdio_c_iface.h"
#include "../file/kv_stdio_intercept.h"
#include "bpp_tree/bpp_tree_handler.h"
#include "flat_file/flat_file_dictionary_handler.h"
#include "open_address_file_hash/open_address_file_hash_dictionary_handler.h"
#include "open_address_hash/open_address_hash_dictionary_handler.h"
#include "skip_list/skip_list_handler.h"
#include "linear_hash/linear_hash_handler.h"
Description
Master table API.
At compile time, the master table is either used, OR it is not included at all. The directive, ION_USING_MASTER_TABLE controls this.
If the master table is used, the assumption is that the user does not bypass the master table and call dictionary_create directly.
If the master table is not used, the user must provide IDs directly to dictionary creation and the onus is on the user to resolve conflicts, if they occur.
- Copyright
- Copyright 2017 The University of British Columbia, IonDB Project Contributors (see AUTHORS.md)
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1.Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2.Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- 3.Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file ion_master_table.h.
Macros | |
#define | ION_MASTER_TABLE_CALCULATE_POS -1 |
#define | ION_MASTER_TABLE_WRITE_FROM_END -2 |
#define | ION_MASTER_TABLE_RECORD_SIZE(cp) (sizeof((cp)->id) + sizeof((cp)->use_type) + sizeof((cp)->type) + sizeof((cp)->key_size) + sizeof((cp)->value_size) + sizeof((cp)->dictionary_size) + sizeof((cp)->dictionary_type) + sizeof((cp)->dictionary_status)) |
#define | ION_MASTER_TABLE_FILENAME "ion_mt.tbl" |
File name for IonDB master table. More... | |
#define | ION_MASTER_TABLE_ID 0 |
ID of the master table. More... | |
#define | ION_MASTER_TABLE_FIND_FIRST 1 |
Flag used when searching master table; search for first instance matching criteria. More... | |
#define | ION_MASTER_TABLE_FIND_LAST -1 |
Flag used when searching master table; search for last instance matching criteria. More... | |
Variables | |
ion_dictionary_id_t | ion_master_table_next_id |
Master table resposible for managing instances. More... | |
FILE * | ion_master_table_file |
Master table file. More... | |
Macro Definition Documentation
#define ION_MASTER_TABLE_CALCULATE_POS -1 |
Definition at line 64 of file ion_master_table.h.
#define ION_MASTER_TABLE_FILENAME "ion_mt.tbl" |
File name for IonDB master table.
Needs to be relatively short for devices.
Definition at line 74 of file ion_master_table.h.
#define ION_MASTER_TABLE_FIND_FIRST 1 |
Flag used when searching master table; search for first instance matching criteria.
Definition at line 85 of file ion_master_table.h.
#define ION_MASTER_TABLE_FIND_LAST -1 |
Flag used when searching master table; search for last instance matching criteria.
Definition at line 91 of file ion_master_table.h.
#define ION_MASTER_TABLE_ID 0 |
ID of the master table.
Definition at line 79 of file ion_master_table.h.
#define ION_MASTER_TABLE_RECORD_SIZE | ( | cp | ) | (sizeof((cp)->id) + sizeof((cp)->use_type) + sizeof((cp)->type) + sizeof((cp)->key_size) + sizeof((cp)->value_size) + sizeof((cp)->dictionary_size) + sizeof((cp)->dictionary_type) + sizeof((cp)->dictionary_status)) |
Definition at line 66 of file ion_master_table.h.
#define ION_MASTER_TABLE_WRITE_FROM_END -2 |
Definition at line 65 of file ion_master_table.h.
Function Documentation
ion_err_t ion_close_all_master_table | ( | void | ) |
Closes the master table and all dictionary instances within it.
For this method to work properly, all dictionary instances must already be closed or must have been closed previously and are now re-opened.
Definition at line 259 of file ion_master_table.c.
ion_err_t ion_close_dictionary | ( | ion_dictionary_t * | dictionary | ) |
Closes a given dictionary.
- Parameters
-
dictionary A pointer to the dictionary object to close.
Definition at line 486 of file ion_master_table.c.
ion_err_t ion_close_master_table | ( | void | ) |
Closes the master table.
Definition at line 244 of file ion_master_table.c.
ion_err_t ion_delete_dictionary | ( | ion_dictionary_t * | dictionary, |
ion_dictionary_id_t | id | ||
) |
Deletes a given dictionary instance and deletes it from the master table.
- Parameters
-
dictionary A pointer to the dictionary object to delete. id The identifier identifying the dictionary metadata in the master table. Required to delete a closed dictionary without reopening it.
Definition at line 496 of file ion_master_table.c.
ion_err_t ion_delete_from_master_table | ( | ion_dictionary_id_t | id | ) |
Deletes a dictionary from the master table.
- Parameters
-
id The identifier identifying the dictionary metadata in the master table.
- Returns
- An error code describing the result of the operation.
Definition at line 437 of file ion_master_table.c.
ion_err_t ion_delete_master_table | ( | void | ) |
Deletes the master table.
Definition at line 314 of file ion_master_table.c.
ion_err_t ion_find_by_use_master_table | ( | ion_dictionary_config_info_t * | config, |
ion_dict_use_t | use_type, | ||
char | whence | ||
) |
Find first or last dictionary in master table with a given use.
- Parameters
-
config A pointer to an already allocated configuration object that will be used to open the found dictionary. use_type The integral usage type for the dictionary. This is user defined. whence Whether to find the first or the last dictionary having use_type
. This can take exactly two values, ION_MASTER_TABLE_FIND_FIRST or ION_MASTER_TABLE_FIND_LAST.
- Returns
err_ok
if a dictionary having usage typeuse_type
is found, otherwise an error code properly describing the situation and outcome.
Definition at line 396 of file ion_master_table.c.
ion_dictionary_type_t ion_get_dictionary_type | ( | ion_dictionary_id_t | id | ) |
Retrieves the type of dictionary stored under a particular id in the master table.
- Parameters
-
id The identifier identifying the dictionary metadata in the master table.
- Returns
- The type of dictionary implementation corresponding to the id.
Definition at line 447 of file ion_master_table.c.
ion_err_t ion_init_master_table | ( | void | ) |
Opens the master table.
Can be safely called multiple times without closing.
Definition at line 197 of file ion_master_table.c.
ion_err_t ion_lookup_in_master_table | ( | ion_dictionary_id_t | id, |
ion_dictionary_config_info_t * | config | ||
) |
Looks up the config of the given id.
- Parameters
-
id The identifier identifying the dictionary metadata in the master table which is to be looked up. config A pointer to an already allocated configuration object that will be read into from the master table.
Definition at line 379 of file ion_master_table.c.
ion_err_t ion_master_table_create_dictionary | ( | ion_dictionary_handler_t * | handler, |
ion_dictionary_t * | dictionary, | ||
ion_key_type_t | key_type, | ||
ion_key_size_t | key_size, | ||
ion_value_size_t | value_size, | ||
ion_dictionary_size_t | dictionary_size | ||
) |
Creates a dictionary through use of the master table.
- Parameters
-
handler A pointer to an allocated and initialized dictionary handler object that contains all implementation specific data and function pointers. dictionary A pointer to an allocated dictionary object, which will be written into when opened. key_type The type of key to be used with this dictionary, which determines the key comparison operator. key_size The size of the key type to be used with this dictionary. value_size The size of the value type to be used with this dictionary. dictionary_size The dictionary implementation specific dictionary size parameter.
- Returns
- An error code describing the result of the operation.
Definition at line 350 of file ion_master_table.c.
ion_err_t ion_master_table_get_next_id | ( | ion_dictionary_id_t * | id | ) |
Returns the next dictionary ID, then increments.
- Parameters
-
id An identifier pointer to be written into.
- Returns
- An error code describing the result of the operation.
Definition at line 177 of file ion_master_table.c.
ion_err_t ion_master_table_write | ( | ion_dictionary_config_info_t * | config, |
long | where | ||
) |
Write a record to the master table.
Automatically, this call will reposition the file position back to where it was once the call is complete.
- Parameters
-
[in] config A pointer to a previously allocated config object to write from. [in] where An integral value representing where to write to in the file. This file offset is byte-aligned, not record aligned, in general.
Two special flags can be passed in here:
ION_MASTER_TABLE_CALCULATE_POS
Calculate the position based on the passed-in config id.ION_MASTER_TABLE_WRITE_FROM_END
Write the record at the end of the file.- Returns
- An error code describing the result of the call.
Definition at line 44 of file ion_master_table.c.
ion_err_t ion_open_dictionary | ( | ion_dictionary_handler_t * | handler, |
ion_dictionary_t * | dictionary, | ||
ion_dictionary_id_t | id | ||
) |
Finds the target dictionary and opens it.
- Parameters
-
handler A pointer to the handler object to be initialized. dictionary A pointer to the dictionary object to open. id The identifier identifying the dictionary metadata in the master table.
- Returns
- An error code describing the result of the operation.
Definition at line 463 of file ion_master_table.c.
ion_err_t ion_switch_handler | ( | ion_dictionary_type_t | type, |
ion_dictionary_handler_t * | handler | ||
) |
Retrieves the type of dictionary stored under a particular id in the master table.
- Parameters
-
type The type of dictionary instance to initialize the handler to. handler A pointer to the handler to be set.
- Returns
- An error code describing the result of the operation.
Definition at line 537 of file ion_master_table.c.
Variable Documentation
FILE* ion_master_table_file |
Master table file.
Definition at line 40 of file ion_master_table.c.
ion_dictionary_id_t ion_master_table_next_id |
Master table resposible for managing instances.
Definition at line 41 of file ion_master_table.c.