sdskv-server.h 5.56 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7 8 9 10
/*
 * (C) 2018 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

#ifndef __SDSKV_SERVER_H
#define __SDSKV_SERVER_H

#include <margo.h>
11
#include <abt-io.h>
Matthieu Dorier's avatar
Matthieu Dorier committed
12
#include <sdskv-common.h>
Matthieu Dorier's avatar
Matthieu Dorier committed
13 14 15 16 17 18

#ifdef __cplusplus
extern "C" {
#endif

#define SDSKV_ABT_POOL_DEFAULT ABT_POOL_NULL
19
#define SDSKV_PROVIDER_ID_DEFAULT 0
Matthieu Dorier's avatar
Matthieu Dorier committed
20
#define SDSKV_PROVIDER_IGNORE NULL
21
#define SDSKV_COMPARE_DEFAULT NULL
Matthieu Dorier's avatar
Matthieu Dorier committed
22 23

typedef struct sdskv_server_context_t* sdskv_provider_t;
Swen Boehm's avatar
Swen Boehm committed
24
typedef int (*sdskv_compare_fn)(const void*, hg_size_t, const void*, hg_size_t);
Matthieu Dorier's avatar
Matthieu Dorier committed
25

26
typedef struct sdskv_config_t {
27 28 29 30 31
    const char*      db_name;         // name of the database
    const char*      db_path;         // path to the database
    sdskv_db_type_t  db_type;         // type of database
    const char*      db_comp_fn_name; // name of registered comparison function (can be NULL)
    int              db_no_overwrite; // prevents overwritting data if set to 1
32 33 34 35
} sdskv_config_t;

#define SDSKV_CONFIG_DEFAULT { "", "", KVDB_MAP, SDSKV_COMPARE_DEFAULT, 0 }

36 37 38
typedef void (*sdskv_pre_migration_callback_fn)(sdskv_provider_t, const sdskv_config_t*, void*);
typedef void (*sdskv_post_migration_callback_fn)(sdskv_provider_t, const sdskv_config_t*, sdskv_database_id_t, void*);

39 40 41 42
/**
 * @brief Creates a new provider.
 *
 * @param[in] mid Margo instance
43
 * @param[in] provider_id provider id
44 45 46 47 48
 * @param[in] pool Argobots pool
 * @param[out] provider provider handle
 *
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
 */
Matthieu Dorier's avatar
Matthieu Dorier committed
49 50
int sdskv_provider_register(
        margo_instance_id mid,
51
        uint16_t provider_id,
Matthieu Dorier's avatar
Matthieu Dorier committed
52 53 54
        ABT_pool pool,
        sdskv_provider_t* provider);

55 56 57 58 59 60 61 62 63
/**
 * @brief Deregister the provider's RPCs and destroys the provider.
 *
 * @param provider Provider to destroy.
 *
 * @return SDSKV_SUCCESS  or error code defined in sdskv-common.h
 */
int sdskv_provider_destroy(sdskv_provider_t provider);

64 65 66 67 68 69 70 71 72 73 74 75 76 77
/**
 * @brief Registers a comparison function for databases to use.
 *
 * @param provider provider
 * @param function_name name of the comparison function
 * @param comp_fn pointer to the comparison function
 *
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
 */
int sdskv_provider_add_comparison_function(
        sdskv_provider_t provider,
        const char* function_name,
        sdskv_compare_fn comp_fn);

78 79 80 81 82 83 84 85 86 87 88 89 90 91
/**
 * Makes the provider start managing a database. The database will
 * be created if it does not exist. Otherwise, the provider will start
 * to manage the existing database.
 *
 * @param[in] provider provider
 * @param[in] config configuration object to use for the database
 * @param[out] db_id resulting id identifying the database
 *
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
 */
int sdskv_provider_attach_database(
        sdskv_provider_t provider,
        const sdskv_config_t* config,
Matthieu Dorier's avatar
Matthieu Dorier committed
92 93 94
        sdskv_database_id_t* sb_id);

/**
95 96 97
 * Makes the provider stop managing a database and deletes the
 * database. This will effectively destroy the database if it is
 * not backed up by a file.
Matthieu Dorier's avatar
Matthieu Dorier committed
98 99 100 101
 *
 * @param provider provider
 * @param db_id id of the database to remove
 *
102
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
Matthieu Dorier's avatar
Matthieu Dorier committed
103
 */
Matthieu Dorier's avatar
Matthieu Dorier committed
104
int sdskv_provider_remove_database(
Matthieu Dorier's avatar
Matthieu Dorier committed
105 106 107 108 109 110 111 112
        sdskv_provider_t provider,
        sdskv_database_id_t db_id);

/**
 * Removes all the databases associated with a provider.
 *
 * @param provider provider
 *
113
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
Matthieu Dorier's avatar
Matthieu Dorier committed
114 115 116 117 118 119 120 121 122 123
 */
int sdskv_provider_remove_all_databases(
        sdskv_provider_t provider);

/**
 * Returns the number of databases that this provider manages.
 *
 * @param provider provider
 * @param num_db resulting number of databases
 *
124
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
Matthieu Dorier's avatar
Matthieu Dorier committed
125 126 127 128 129 130 131 132 133 134 135
 */
int sdskv_provider_count_databases(
        sdskv_provider_t provider,
        uint64_t* num_db);

/**
 * List the database ids of the databases managed by this provider.
 * The databases array must be pre-allocated with at least enough
 * space to hold all the ids (use sdskv_provider_count_databases
 * to know how many databases are managed).
 *
136 137
 * @param[in] provider provider
 * @param[out] databases resulting database ids
Matthieu Dorier's avatar
Matthieu Dorier committed
138
 *
139
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
Matthieu Dorier's avatar
Matthieu Dorier committed
140 141 142 143 144
 */
int sdskv_provider_list_databases(
        sdskv_provider_t provider,
        sdskv_database_id_t* databases);

145 146 147 148 149 150 151 152 153 154 155 156 157 158
/**
 * @brief Computes the database size.
 *
 * @param[in] provider provider.
 * @param[in] database_id Database id.
 * @param[out] size Resulting size.
 *
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
 */
int sdskv_provider_compute_database_size(
        sdskv_provider_t provider,
        sdskv_database_id_t database_id,
        size_t* size);

159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
/**
 * @brief Register custom migration callbacks to call before and
 * after a database is migrated to this provider.
 *
 * @param provider Provider in which to register the callbacks.
 * @param pre_cb Pre-migration callback.
 * @param post_cb Post-migration callback.
 * @param uargs User arguments.
 *
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
 */
int sdskv_provider_set_migration_callbacks(
        sdskv_provider_t provider,
        sdskv_pre_migration_callback_fn pre_cb,
        sdskv_post_migration_callback_fn  post_cb,
        void* uargs);

176 177 178 179 180 181 182 183
/**
 * @brief Sets the ABT-IO instance to be used by REMI for migration IO.
 *
 * @param provider Provider.
 * @param abtio ABT-IO instance.
 *
 * @return SDSKV_SUCCESS or error code defined in sdskv-common.h
 */
Matthieu Dorier's avatar
Matthieu Dorier committed
184
int sdskv_provider_set_abtio_instance(
185 186 187
        sdskv_provider_t provider,
        abt_io_instance_id abtio);

Matthieu Dorier's avatar
Matthieu Dorier committed
188 189 190 191 192
#ifdef __cplusplus
}
#endif

#endif /* __BAKE_SERVER_H */