postgres-based datastore backend More...
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
struct | ProcessResultContext |
Closure for process_result. More... | |
struct | ReplCtx |
Context for #repl_iter() function. More... | |
struct | ProcessKeysContext |
Closure for process_keys. More... | |
Macros | |
#define | BUSY_TIMEOUT GNUNET_TIME_UNIT_SECONDS |
After how many ms "busy" should a DB operation fail for good? A low value makes sure that we are more responsive to requests (especially PUTs). More... | |
#define | RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, oid" |
Functions | |
static enum GNUNET_GenericReturnValue | init_connection (struct Plugin *plugin) |
Get a database handle. More... | |
static void | postgres_plugin_estimate_size (void *cls, unsigned long long *estimate) |
Get an estimate of how much space the database is currently using. More... | |
static void | postgres_plugin_put (void *cls, const struct GNUNET_HashCode *key, bool absent, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, void *cont_cls) |
Store an item in the datastore. More... | |
static void | process_result (void *cls, PGresult *res, unsigned int num_results) |
Function invoked to process the result and call the processor of cls. More... | |
static void | postgres_plugin_get_key (void *cls, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls) |
Get one of the results for a particular key in the datastore. More... | |
static void | postgres_plugin_get_zero_anonymity (void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls) |
Select a subset of the items in the datastore and call the given iterator for each of them. More... | |
static int | repl_proc (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
Wrapper for the iterator for 'sqlite_plugin_replication_get'. More... | |
static void | postgres_plugin_get_replication (void *cls, PluginDatumProcessor proc, void *proc_cls) |
Get a random item for replication. More... | |
static void | postgres_plugin_get_expiration (void *cls, PluginDatumProcessor proc, void *proc_cls) |
Get a random item for expiration. More... | |
static void | process_keys (void *cls, PGresult *result, unsigned int num_results) |
Function to be called with the results of a SELECT statement that has returned num_results results. More... | |
static void | postgres_plugin_get_keys (void *cls, PluginKeyProcessor proc, void *proc_cls) |
Get all of the keys in the datastore. More... | |
static void | postgres_plugin_drop (void *cls) |
Drop database. More... | |
static void | postgres_plugin_remove_key (void *cls, const struct GNUNET_HashCode *key, uint32_t size, const void *data, PluginRemoveCont cont, void *cont_cls) |
Remove a particular key in the datastore. More... | |
void * | libgnunet_plugin_datastore_postgres_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_datastore_postgres_done (void *cls) |
Exit point from the plugin. More... | |
postgres-based datastore backend
Definition in file plugin_datastore_postgres.c.
#define BUSY_TIMEOUT GNUNET_TIME_UNIT_SECONDS |
After how many ms "busy" should a DB operation fail for good? A low value makes sure that we are more responsive to requests (especially PUTs).
A high value guarantees a higher success rate (SELECTs in iterate can take several seconds despite LIMIT=1).
The default value of 1s should ensure that users do not experience huge latencies while at the same time allowing operations to succeed with reasonable probability.
Definition at line 41 of file plugin_datastore_postgres.c.
|
static |
Get a database handle.
plugin | global context |
Definition at line 68 of file plugin_datastore_postgres.c.
References GNUNET_OK, GNUNET_PQ_connect_with_cfg(), GNUNET_PQ_make_prepare(), GNUNET_PQ_PREPARED_STATEMENT_END, GNUNET_SYSERR, plugin, ps, and RESULT_COLUMNS.
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Get an estimate of how much space the database is currently using.
cls | our struct Plugin * |
Definition at line 152 of file plugin_datastore_postgres.c.
References GNUNET_DB_STATUS_SUCCESS_ONE_RESULT, GNUNET_PQ_eval_prepared_singleton_select(), GNUNET_PQ_query_param_end, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint64(), plugin, and ret.
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Store an item in the datastore.
cls | closure with the struct Plugin |
key | key for the item |
absent | true if the key was not found in the bloom filter |
size | number of bytes in data |
data | content stored |
type | type of the content |
priority | priority of the content |
anonymity | anonymity-level for the content |
replication | replication-level for the content |
expiration | expiration time for the content |
cont | continuation called with success or failure status |
cont_cls | continuation closure |
Definition at line 199 of file plugin_datastore_postgres.c.
References _, anonymity, GNUNET_TESTING_PluginFunctions::cls, data, expiration, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_fixed_size(), GNUNET_PQ_query_param_uint32(), GNUNET_PQ_query_param_uint64(), GNUNET_SYSERR, key, plugin, replication, ret, size, and type.
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Function invoked to process the result and call the processor of cls.
cls | our struct ProcessResultContext |
res | result from exec |
num_results | number of results in res |
Definition at line 327 of file plugin_datastore_postgres.c.
References anonymity, GNUNET_TESTING_PluginFunctions::cls, data, GNUNET_break, GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_PQ_cleanup_result(), GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_extract_result(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint64(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_uint64(), GNUNET_PQ_result_spec_variable_size(), GNUNET_TIME_UNIT_ZERO_ABS, key, plugin, ProcessResultContext::plugin, ProcessResultContext::proc, ProcessResultContext::proc_cls, replication, res, and size.
Referenced by postgres_plugin_get_expiration(), postgres_plugin_get_key(), postgres_plugin_get_replication(), and postgres_plugin_get_zero_anonymity().
|
static |
Get one of the results for a particular key in the datastore.
cls | closure with the struct Plugin |
next_uid | return the result with lowest uid >= next_uid |
random | if true, return a random result instead of using next_uid |
key | maybe NULL (to match all entries) |
type | entries of which type are relevant? Use 0 for any type. |
proc | function to call on the matching value; will be called with NULL if nothing matches |
proc_cls | closure for proc |
Definition at line 449 of file plugin_datastore_postgres.c.
References GNUNET_BLOCK_TYPE_ANY, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint16(), GNUNET_PQ_query_param_uint32(), GNUNET_PQ_query_param_uint64(), GNUNET_TIME_UNIT_ZERO_ABS, key, plugin, ProcessResultContext::plugin, ProcessResultContext::proc, ProcessResultContext::proc_cls, process_result(), res, and type.
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Select a subset of the items in the datastore and call the given iterator for each of them.
cls | our struct Plugin * |
next_uid | return the result with lowest uid >= next_uid |
type | entries of which type should be considered? Must not be zero (ANY). |
proc | function to call on the matching value; will be called with NULL if no value matches |
proc_cls | closure for proc |
Definition at line 514 of file plugin_datastore_postgres.c.
References GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint32(), GNUNET_PQ_query_param_uint64(), GNUNET_TIME_UNIT_ZERO_ABS, plugin, ProcessResultContext::plugin, ProcessResultContext::proc, ProcessResultContext::proc_cls, process_result(), res, and type.
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Wrapper for the iterator for 'sqlite_plugin_replication_get'.
Decrements the replication counter and calls the original iterator.
cls | closure with the struct ReplCtx * |
key | key for the content |
size | number of bytes in data |
data | content stored |
type | type of the content |
priority | priority of the content |
anonymity | anonymity-level for the content |
replication | replication-level for the content |
expiration | expiration time for the content |
uid | unique identifier for the datum; maybe 0 if no unique identifier is available |
Definition at line 588 of file plugin_datastore_postgres.c.
References anonymity, data, expiration, GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_uint64(), GNUNET_SYSERR, key, plugin, ReplCtx::plugin, ReplCtx::proc, ReplCtx::proc_cls, replication, ret, size, and type.
Referenced by postgres_plugin_get_replication().
|
static |
Get a random item for replication.
Returns a single, not expired, random item from those with the highest replication counters. The item's replication counter is decremented by one IF it was positive before. Call proc with all values ZERO or NULL if the datastore is empty.
cls | closure with the struct Plugin |
proc | function to call the value (once only). |
proc_cls | closure for proc |
Definition at line 641 of file plugin_datastore_postgres.c.
References GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_end, GNUNET_TIME_UNIT_ZERO_ABS, plugin, ProcessResultContext::plugin, ReplCtx::plugin, ProcessResultContext::proc, ReplCtx::proc, ProcessResultContext::proc_cls, ReplCtx::proc_cls, process_result(), repl_proc(), and res.
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Get a random item for expiration.
Call proc with all values ZERO or NULL if the datastore is empty.
cls | closure with the struct Plugin |
proc | function to call the value (once only). |
proc_cls | closure for proc |
Definition at line 679 of file plugin_datastore_postgres.c.
References GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_absolute_time(), GNUNET_PQ_query_param_end, GNUNET_TIME_absolute_get(), plugin, ProcessResultContext::plugin, ProcessResultContext::proc, ProcessResultContext::proc_cls, and process_result().
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Function to be called with the results of a SELECT statement that has returned num_results results.
cls | closure with a struct ProcessKeysContext |
result | the postgres result |
num_results | the number of results in result |
Definition at line 729 of file plugin_datastore_postgres.c.
References GNUNET_break, GNUNET_OK, GNUNET_PQ_cleanup_result(), GNUNET_PQ_extract_result(), GNUNET_PQ_result_spec_auto_from_type, GNUNET_PQ_result_spec_end, key, ProcessKeysContext::proc, ProcessKeysContext::proc_cls, and result.
Referenced by postgres_plugin_get_keys().
|
static |
Get all of the keys in the datastore.
cls | closure with the struct Plugin * |
proc | function to call on each key |
proc_cls | closure for proc |
Definition at line 768 of file plugin_datastore_postgres.c.
References GNUNET_PQ_eval_prepared_multi_select(), GNUNET_PQ_query_param_end, plugin, ProcessKeysContext::proc, ProcessKeysContext::proc_cls, and process_keys().
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Drop database.
cls | closure with the struct Plugin * |
Definition at line 797 of file plugin_datastore_postgres.c.
References _, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_from, GNUNET_OK, GNUNET_PQ_exec_statements(), GNUNET_PQ_EXECUTE_STATEMENT_END, GNUNET_PQ_make_execute(), and plugin.
Referenced by libgnunet_plugin_datastore_postgres_init().
|
static |
Remove a particular key in the datastore.
cls | closure |
key | key for the content |
size | number of bytes in data |
data | content stored |
cont | continuation called with success or failure status |
cont_cls | continuation closure for cont |
Definition at line 825 of file plugin_datastore_postgres.c.
References _, GNUNET_TESTING_PluginFunctions::cls, data, GNUNET_DATASTORE_ENTRY_OVERHEAD, GNUNET_DB_STATUS_SUCCESS_NO_RESULTS, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log_from, GNUNET_NO, GNUNET_OK, GNUNET_PQ_eval_prepared_non_select(), GNUNET_PQ_query_param_auto_from_type, GNUNET_PQ_query_param_end, GNUNET_PQ_query_param_fixed_size(), GNUNET_SYSERR, key, plugin, ret, and size.
Referenced by libgnunet_plugin_datastore_postgres_init().
void * libgnunet_plugin_datastore_postgres_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | the struct GNUNET_DATASTORE_PluginEnvironment* |
struct Plugin *
Definition at line 885 of file plugin_datastore_postgres.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginEnvironment::cls, env, GNUNET_BLOCK_PluginFunctions::get_key, GNUNET_free, GNUNET_new, GNUNET_OK, init_connection(), plugin, postgres_plugin_drop(), postgres_plugin_estimate_size(), postgres_plugin_get_expiration(), postgres_plugin_get_key(), postgres_plugin_get_keys(), postgres_plugin_get_replication(), postgres_plugin_get_zero_anonymity(), postgres_plugin_put(), and postgres_plugin_remove_key().
void * libgnunet_plugin_datastore_postgres_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | our struct Plugin * |
Definition at line 923 of file plugin_datastore_postgres.c.
References Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DATASTORE_PluginFunctions::cls, GNUNET_free, GNUNET_PQ_disconnect(), and plugin.