Commit d3261f1a authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added function to get the size of a database

parent 5cbe5727
......@@ -129,6 +129,20 @@ int sdskv_provider_list_databases(
sdskv_provider_t provider,
sdskv_database_id_t* databases);
/**
* @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);
#ifdef __cplusplus
}
#endif
......
......@@ -2244,3 +2244,30 @@ static int sdskv_post_migration_callback(remi_fileset_t fileset, void* uargs)
return -106;
return 0;
}
int sdskv_provider_compute_database_size(
sdskv_provider_t provider,
sdskv_database_id_t database_id,
size_t* size)
{
int ret;
// find the database
auto it = provider->databases.find(database_id);
if(it == provider->databases.end()) {
return SDSKV_ERR_UNKNOWN_DB;
}
auto database = it->second;
database->sync();
/* create a fileset */
remi_fileset_t fileset = database->create_and_populate_fileset();
if(fileset == REMI_FILESET_NULL) {
return SDSKV_OP_NOT_IMPL;
}
/* issue the migration */
ret = remi_fileset_compute_size(fileset, 0, size);
if(ret != REMI_SUCCESS) {
return SDSKV_ERR_REMI;
}
return SDSKV_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment