126 #define MAX_DATUM_SIZE 65536 147 #define INSERT_ENTRY \ 148 "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)" 151 #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" 154 #define DELETE_ENTRY_BY_HASH_VALUE "DELETE FROM gn090 " \ 155 "WHERE hash = ? AND " \ 160 #define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid" 162 #define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 " \ 163 "WHERE uid >= ? AND " \ 164 "(rvalue >= ? OR 0 = ?) " \ 165 "ORDER BY uid LIMIT 1" 168 #define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 " \ 169 "FORCE INDEX (idx_hash_type_uid) " \ 170 "WHERE hash=? AND " \ 172 "(rvalue >= ? OR 0 = ?) " \ 173 "ORDER BY uid LIMIT 1" 176 #define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 " \ 177 "FORCE INDEX (idx_hash_type_uid) " \ 178 "WHERE hash = ? AND " \ 181 "(rvalue >= ? OR 0 = ?) " \ 182 "ORDER BY uid LIMIT 1" 185 #define UPDATE_ENTRY "UPDATE gn090 SET " \ 186 "prio = prio + ?, " \ 187 "repl = repl + ?, " \ 188 "expire = GREATEST(expire, ?) " \ 189 "WHERE hash = ? AND vhash = ?" 192 #define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?" 195 #define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090" 198 #define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 " \ 199 "FORCE INDEX (idx_anonLevel_type_rvalue) " \ 200 "WHERE anonLevel=0 AND " \ 203 "ORDER BY uid LIMIT 1" 206 #define SELECT_IT_EXPIRATION "SELECT " RESULT_COLUMNS " FROM gn090 " \ 207 "FORCE INDEX (idx_expire) " \ 208 "WHERE expire < ? " \ 209 "ORDER BY expire ASC LIMIT 1" 212 #define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 " \ 213 "FORCE INDEX (idx_prio) " \ 214 "ORDER BY prio ASC LIMIT 1" 217 #define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 " \ 218 "FORCE INDEX (idx_repl_rvalue) " \ 219 "WHERE repl=? AND " \ 221 " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) " \ 222 "ORDER BY rvalue ASC " \ 226 #define SELECT_MAX_REPL "SELECT MAX(repl) FROM gn090" 229 #define GET_ALL_KEYS "SELECT hash from gn090" 244 unsigned long long uid)
247 uint64_t uid64 = (uint64_t) uid;
254 "Deleting value %llu from gn090 table\n",
264 "Deleting value %llu from gn090 table failed\n",
265 (
unsigned long long) uid);
279 unsigned long long *estimate)
302 *estimate = (
unsigned long long) total;
304 "Size estimate for MySQL payload is %lld\n",
371 _ (
"MySQL statement run failure"));
376 my_ulonglong rows = mysql_stmt_affected_rows (stmt);
423 _ (
"MySQL statement run failure"));
427 "Inserted value `%s' with size %u into gn090 table\n",
429 (
unsigned int) size);
503 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n",
504 (
unsigned int) value_size,
506 (
unsigned int) priority,
507 (
unsigned int) anonymity,
513 ret = proc (proc_cls,
638 uint32_t typei = (uint32_t) type;
736 "Failed to reduce replication counter\n");
827 MYSQL_STMT *statement;
847 _ (
"`%s' for `%s' failed at %s:%d with error: %s\n"),
848 "mysql_stmt_execute",
852 mysql_stmt_error (statement));
854 proc (proc_cls, NULL, 0);
857 memset (&last, 0,
sizeof(last));
890 _ (
"`%s' failed at %s:%d with error: %s\n"),
894 mysql_stmt_error (statement));
1028 "DROP TABLE gn090"))
1065 "Removing key `%s' from gn090 table failed\n",
1071 _ (
"MySQL statement run failure"));
1077 my_ulonglong rows = mysql_stmt_affected_rows (stmt);
1115 if (NULL == plugin->
mc)
1120 #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a)) 1121 #define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare (plugin->mc, \ 1124 (
"CREATE TABLE IF NOT EXISTS gn090 (" 1125 " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," 1126 " type INT(11) UNSIGNED NOT NULL DEFAULT 0," 1127 " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," 1128 " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," 1129 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," 1130 " rvalue BIGINT UNSIGNED NOT NULL," 1131 " hash BINARY(64) NOT NULL DEFAULT ''," 1132 " vhash BINARY(64) NOT NULL DEFAULT ''," 1133 " value BLOB NOT NULL DEFAULT ''," 1134 " uid BIGINT NOT NULL AUTO_INCREMENT," 1135 " PRIMARY KEY (uid)," 1136 " INDEX idx_hash_type_uid (hash(64),type,rvalue)," 1137 " INDEX idx_prio (prio)," 1138 " INDEX idx_repl_rvalue (repl,rvalue)," 1139 " INDEX idx_expire (expire)," 1140 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" 1141 ") ENGINE=InnoDB") ||
MRUNS (
"SET AUTOCOMMIT = 1") ||
1179 _ (
"Mysql database running\n"));
struct GNUNET_MYSQL_Context * mc
Handle to talk to MySQL.
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash_and_type
struct GNUNET_MYSQL_StatementHandle * select_expiration
PluginGetKeys get_keys
Iterate over all keys in the database.
PluginPut put
Function to store an item in the datastore.
#define GNUNET_MY_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
int(* PluginDatumProcessor)(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)
An processor over a set of items stored in the datastore.
void * proc_cls
Closure for proc.
PluginGetType get_zero_anonymity
Get datum (of the specified type) with anonymity level zero.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint64(const uint64_t *x)
Generate query parameter for an uint64_t in host byte order.
struct Plugin * plugin
Plugin handle.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
void * proc_cls
Closure for proc.
struct GNUNET_MYSQL_StatementHandle * insert_entry
struct GNUNET_MYSQL_Context * GNUNET_MYSQL_context_create(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Create a mysql context.
Any type of block, used as a wildcard when searching.
#define SELECT_IT_EXPIRATION
#define GNUNET_MY_result_spec_end
End of result speceter specification.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint64(uint64_t *u64)
uint64_t expected.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.FG.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_hash_value
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define SELECT_IT_REPLICATION
static void mysql_plugin_get_keys(void *cls, PluginKeyProcessor proc, void *proc_cls)
Get all of the keys in the datastore.
void * libgnunet_plugin_datastore_mysql_done(void *cls)
Exit point from the plugin.
struct GNUNET_MYSQL_StatementHandle * delete_entry_by_uid
PluginRemoveKey remove_key
Function to remove an item from the database.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
static unsigned int replication
Information we pass to GNUNET_MY_exec_prepared() to initialize the arguments of the prepared statemen...
PluginEstimateSize estimate_size
Calculate the current on-disk size of the SQ store.
static int ret
Return value of the commandline.
#define SELECT_IT_PRIORITY
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 processor for mysql_plugin_get_replication().
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_absolute_time(struct GNUNET_TIME_Absolute *at)
Absolute time expected.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_MYSQL_StatementHandle * zero_iter
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Handle for a prepared statement.
void * libgnunet_plugin_datastore_mysql_init(void *cls)
Entry point for the plugin.
int GNUNET_MY_exec_prepared(struct GNUNET_MYSQL_Context *mc, struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_QueryParam *params)
Run a prepared SELECT statement.
static void mysql_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.
void(* PluginPutCont)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Put continuation.
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define DELETE_ENTRY_BY_UID
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
PluginGetRandom get_replication
Function to get a random item with high replication score from the database, lowering the item's repl...
static int expi_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 processor for mysql_plugin_get_expiration().
PluginDrop drop
Delete the database.
Information we pass to GNUNET_MY_extract_result() to initialize the arguments of the prepared stateme...
static void mysql_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.
static void mysql_plugin_drop(void *cls)
Drop database.
#define DELETE_ENTRY_BY_HASH_VALUE
static char * value
Value of the record to add/remove.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
void(* PluginKeyProcessor)(void *cls, const struct GNUNET_HashCode *key, unsigned int count)
An processor over a set of keys stored in the datastore.
PluginGetRandom get_expiration
Function to get a random expired item or, if none are expired, either the oldest entry or one with a ...
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
void GNUNET_MYSQL_context_destroy(struct GNUNET_MYSQL_Context *mc)
Destroy a mysql context.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define INSERT_ENTRY
Prepared statements.
void GNUNET_MY_cleanup_result(struct GNUNET_MY_ResultSpec *rs)
Free all memory that was allocated in rs during GNUNET_MY_extract_result().
Context for expi_proc() function.
MYSQL_STMT * GNUNET_MYSQL_statement_get_stmt(struct GNUNET_MYSQL_StatementHandle *sh)
Get internal handle for a prepared statement.
void GNUNET_MYSQL_statements_invalidate(struct GNUNET_MYSQL_Context *mc)
Close database connection and all prepared statements (we got a DB error).
struct GNUNET_MYSQL_StatementHandle * dec_repl
#define SELECT_ENTRY_BY_HASH_AND_TYPE
PluginDatumProcessor proc
Function to call for the result (or the NULL).
struct GNUNET_MYSQL_StatementHandle * max_repl
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
static char * expiration
Credential TTL.
static char * plugin
Solver plugin name as string.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
int GNUNET_MY_extract_result(struct GNUNET_MYSQL_StatementHandle *sh, struct GNUNET_MY_ResultSpec *specs)
Extract results from a query result according to the given specification.
#define SELECT_ENTRY_BY_HASH
static void mysql_plugin_estimate_size(void *cls, unsigned long long *estimate)
Get an estimate of how much space the database is currently using.
struct GNUNET_MYSQL_StatementHandle * get_all_keys
struct GNUNET_MYSQL_StatementHandle * select_priority
#define GNUNET_MY_result_spec_auto_from_type(dst)
We expect a fixed-size result, with size determined by the type of * dst
#define GNUNET_MY_query_param_end
End of query parameter specification.
Context for repl_proc() function.
struct GNUNET_MYSQL_StatementHandle * select_entry_by_hash
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_uint32(uint32_t *u32)
uint32_t expected
void(* PluginRemoveCont)(void *cls, const struct GNUNET_HashCode *key, uint32_t size, int status, const char *msg)
Remove continuation.
void * cls
Closure to use for all of the following callbacks (except "next_request").
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_MY_QueryParam GNUNET_MY_query_param_uint32(const uint32_t *x)
Generate query parameter for an uint32_t in host byte order.
struct GNUNET_MYSQL_StatementHandle * select_entry
unsigned long long size
Size of all values we're storing.
int GNUNET_MYSQL_statement_run(struct GNUNET_MYSQL_Context *mc, const char *sql)
Run a SQL statement.
static void mysql_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.
struct Plugin * plugin
Plugin handle.
PluginDatumProcessor proc
Function to call for the result (or the NULL).
#define GNUNET_log(kind,...)
struct GNUNET_MYSQL_StatementHandle * get_size
static void mysql_plugin_get_replication(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for replication.
void * cls
Closure to use for callbacks.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
static void mysql_plugin_get_expiration(void *cls, PluginDatumProcessor proc, void *proc_cls)
Get a random item for expiration.
static unsigned int anonymity
#define SELECT_IT_NON_ANONYMOUS
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
#define GNUNET_log_from(kind, comp,...)
PluginGetKey get_key
Get a particular datum matching a given hash from the datastore.
struct GNUNET_MYSQL_StatementHandle * update_entry
uint32_t data
The data value.
static void mysql_plugin_get_zero_anonymity(void *cls, uint64_t next_uid, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls)
Get a zero-anonymity datum from the datastore.
struct GNUNET_MYSQL_StatementHandle * select_replication
struct GNUNET_MY_ResultSpec GNUNET_MY_result_spec_variable_size(void **dst, size_t *ptr_size)
Variable-size result expected.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
#define GNUNET_free(ptr)
Wrapper around free.
static int do_delete_entry(struct Plugin *plugin, unsigned long long uid)
Delete an entry from the gn090 table.
static void execute_select(struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt, PluginDatumProcessor proc, void *proc_cls, struct GNUNET_MY_QueryParam *params_select)
Run the given select statement and call 'proc' on the resulting values (which must be in particular p...