31 #define LOG(kind, ...) GNUNET_log_from (kind, "datacache-postgres", __VA_ARGS__)
36 #define OVERHEAD (sizeof(struct GNUNET_HashCode) + 24)
71 "CREATE TEMPORARY SEQUENCE IF NOT EXISTS gn011dc_oid_seq"),
73 " oid OID NOT NULL DEFAULT nextval('gn011dc_oid_seq'),"
74 " type INTEGER NOT NULL,"
75 " prox INTEGER NOT NULL,"
76 " discard_time BIGINT NOT NULL,"
77 " key BYTEA NOT NULL,"
78 " value BYTEA NOT NULL,"
79 " path BYTEA DEFAULT NULL)"),
81 "ALTER SEQUENCE gnu011dc_oid_seq OWNED BY gn011dc.oid"),
83 "CREATE INDEX IF NOT EXISTS idx_oid ON gn011dc (oid)"),
85 "CREATE INDEX IF NOT EXISTS idx_key ON gn011dc (key)"),
87 "CREATE INDEX IF NOT EXISTS idx_dt ON gn011dc (discard_time)"),
89 "ALTER TABLE gn011dc ALTER value SET STORAGE EXTERNAL"),
95 "SELECT discard_time,type,value,path FROM gn011dc "
96 "WHERE key=$1 AND type=$2 AND discard_time >= $3",
99 "SELECT discard_time,type,value,path FROM gn011dc "
100 "WHERE key=$1 AND discard_time >= $2",
103 "SELECT length(value) AS len,oid,key FROM gn011dc"
104 " WHERE discard_time < $1"
105 " ORDER BY discard_time ASC LIMIT 1",
108 "SELECT length(value) AS len,oid,key FROM gn011dc"
109 " ORDER BY prox ASC, discard_time ASC LIMIT 1",
112 "(SELECT discard_time,type,value,path,key FROM gn011dc"
114 " AND discard_time >= $2"
115 " AND ( (type = $3) OR ( 0 = $3) )"
119 "(SELECT discard_time,type,value,path,key FROM gn011dc"
121 " AND discard_time >= $2"
122 " AND ( (type = $3) OR ( 0 = $3) )"
127 "DELETE FROM gn011dc WHERE oid=$1",
130 "INSERT INTO gn011dc (type, prox, discard_time, key, value, path) "
131 "VALUES ($1, $2, $3, $4, $5, $6)",
137 "datacache-postgres",
169 unsigned int path_info_len,
173 uint32_t type32 = (uint32_t)
type;
181 path_info_len *
sizeof(
struct
231 unsigned int num_results)
235 for (
unsigned int i = 0; i < num_results; i++)
272 "Found result of size %u bytes and type %u in database\n",
274 (
unsigned int)
type);
275 if ((NULL != hrc->
iter) &&
287 "Ending iteration (client error)\n");
315 uint32_t type32 = (uint32_t)
type;
336 (0 ==
type) ?
"getk" :
"getkt",
337 (0 ==
type) ? paramk : paramkt,
399 "Ending iteration (no more results)\n");
448 unsigned int num_results)
452 if (NULL == erc->
iter)
454 for (
unsigned int i = 0; i < num_results; i++)
494 "Found result of size %u bytes and type %u in database\n",
496 (
unsigned int)
type);
508 "Ending iteration (client error)\n");
535 unsigned int num_results,
540 uint32_t num_results32 = (uint32_t) num_results;
541 uint32_t type32 = (uint32_t)
type;
564 "Ending iteration (postgres error)\n");
571 "Ending iteration (no more results)\n");
607 "Postgres datacache running\n");
struct GNUNET_MQ_Envelope * env
static int ret
Return value of the commandline.
static size_t data_size
Number of bytes in data.
struct Plugin * plugin
The process handle to the testbed service.
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t data
The data value.
static int result
Global testing status.
GNUNET_DB_QueryStatus
Status code returned from functions running database commands.
@ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
The transaction succeeded, but yielded zero results.
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
helper functions for Postgres DB interactions
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.
#define GNUNET_PQ_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_multi_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params, GNUNET_PQ_PostgresResultHandler rh, void *rh_cls)
Execute a named prepared statement that is a SELECT statement which may return multiple results in co...
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32(const char *name, uint32_t *u32)
uint32_t expected.
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_singleton_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params, struct GNUNET_PQ_ResultSpec *rs)
Execute a named prepared statement that is a SELECT statement which must return a single result in co...
struct GNUNET_PQ_PreparedStatement GNUNET_PQ_make_prepare(const char *name, const char *sql, unsigned int num_args)
Create a struct GNUNET_PQ_PreparedStatement.
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_execute(const char *sql)
Create a struct GNUNET_PQ_ExecuteStatement where errors are fatal.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)
We expect a fixed-size result, with size determined by the type of * dst
void GNUNET_PQ_disconnect(struct GNUNET_PQ_Context *db)
Disconnect from the database, destroying the prepared statements and releasing other associated resou...
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time(const char *name, struct GNUNET_TIME_Absolute *at)
Absolute time expected.
struct GNUNET_PQ_Context * GNUNET_PQ_connect_with_cfg(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *load_path_suffix, const struct GNUNET_PQ_ExecuteStatement *es, const struct GNUNET_PQ_PreparedStatement *ps)
Connect to a postgres database using the configuration option "CONFIG" in section.
struct GNUNET_PQ_ExecuteStatement GNUNET_PQ_make_try_execute(const char *sql)
Create a struct GNUNET_PQ_ExecuteStatement where errors should be tolerated.
#define GNUNET_PQ_query_param_end
End of query parameter specification.
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size(const char *name, void **dst, size_t *sptr)
Variable-size result expected.
void GNUNET_PQ_cleanup_result(struct GNUNET_PQ_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_PQ_extract_result().
#define GNUNET_PQ_PREPARED_STATEMENT_END
Terminator for prepared statement list.
enum GNUNET_GenericReturnValue GNUNET_PQ_extract_result(PGresult *result, struct GNUNET_PQ_ResultSpec *rs, int row)
Extract results from a query result according to the given specification.
#define GNUNET_PQ_EXECUTE_STATEMENT_END
Terminator for executable statement list.
enum GNUNET_DB_QueryStatus GNUNET_PQ_eval_prepared_non_select(struct GNUNET_PQ_Context *db, const char *statement_name, const struct GNUNET_PQ_QueryParam *params)
Execute a named prepared statement that is NOT a SELECT statement in connection using the given param...
#define GNUNET_PQ_result_spec_end
End of result parameter specification.
enum GNUNET_GenericReturnValue(* GNUNET_DATACACHE_Iterator)(void *cls, const struct GNUNET_HashCode *key, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute exp, unsigned int path_info_len, const struct GNUNET_DHT_PathElement *path_info)
An iterator over a set of items stored in the datacache.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
static unsigned int size
Size of the "table".
#define OVERHEAD
Per-entry overhead estimate.
void * libgnunet_plugin_datacache_postgres_done(void *cls)
Exit point from the plugin.
static int init_connection(struct Plugin *plugin)
Get a database handle.
static unsigned int postgres_plugin_get(void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results for a particular key in the datastore.
static unsigned int postgres_plugin_get_closest(void *cls, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, unsigned int num_results, GNUNET_DATACACHE_Iterator iter, void *iter_cls)
Iterate over the results that are "close" to a particular key in the datacache.
void * libgnunet_plugin_datacache_postgres_init(void *cls)
Entry point for the plugin.
static void extract_result_cb(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.
static ssize_t postgres_plugin_put(void *cls, const struct GNUNET_HashCode *key, uint32_t prox, size_t data_size, const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time, unsigned int path_info_len, const struct GNUNET_DHT_PathElement *path_info)
Store an item in the datastore.
static int postgres_plugin_del(void *cls)
Delete the entry with the lowest expiration value from the datacache right now.
static void handle_results(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.
void * cls
Closure for all of the callbacks.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
GNUNET_DATACACHE_DeleteNotifyCallback delete_notify
Function to call whenever the plugin needs to discard content that it was asked to store.
void * cls
Closure to use for callbacks.
struct returned by the initialization function of the plugin
void * cls
Closure to pass to all plugin functions.
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
Handle to Postgres database.
Information needed to run a list of SQL statements using GNUNET_PQ_exec_statements().
Information needed to prepare a list of SQL statements using GNUNET_PQ_prepare_statements().
Description of a DB query parameter.
Description of a DB result cell.
Time for absolute times used by GNUnet, in microseconds.
Closure for handle_results.
void * iter_cls
Closure for iter.
const struct GNUNET_HashCode * key
Key used.
GNUNET_DATACACHE_Iterator iter
Function to call on each result, may be NULL.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
unsigned int num_items
Number of key-value pairs in the database.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_PQ_Context * dbh
Native Postgres database handle.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model