Author: grothoff Date: 2008-03-01 18:55:36 -0700 (Sat, 01 Mar 2008) New Revision: 6496
Added: GNUnet/src/applications/dstore_mysql/dstore_quota_test.c Modified: GNUnet/src/applications/dstore_mysql/Makefile.am GNUnet/src/applications/dstore_mysql/check.conf GNUnet/src/applications/dstore_mysql/dstore_mysql.c GNUnet/src/applications/dstore_mysql/dstore_test.c Log: dstore improvements Modified: GNUnet/src/applications/dstore_mysql/Makefile.am =================================================================== --- GNUnet/src/applications/dstore_mysql/Makefile.am 2008-03-02 01:37:06 UTC (rev 6495) +++ GNUnet/src/applications/dstore_mysql/Makefile.am 2008-03-02 01:55:36 UTC (rev 6496) @@ -9,7 +9,8 @@ libgnunetmodule_dstore_mysql.la check_PROGRAMS = \ - dstore_test + dstore_test \ + dstore_quota_test TESTS = $(check_PROGRAMS) @@ -35,3 +36,9 @@ dstore_test_LDADD = \ $(top_builddir)/src/server/libgnunetcore.la \ $(top_builddir)/src/util/libgnunetutil.la + +dstore_quota_test_SOURCES = \ + dstore_quota_test.c +dstore_quota_test_LDADD = \ + $(top_builddir)/src/server/libgnunetcore.la \ + $(top_builddir)/src/util/libgnunetutil.la Modified: GNUnet/src/applications/dstore_mysql/check.conf =================================================================== --- GNUnet/src/applications/dstore_mysql/check.conf 2008-03-02 01:37:06 UTC (rev 6495) +++ GNUnet/src/applications/dstore_mysql/check.conf 2008-03-02 01:55:36 UTC (rev 6496) @@ -46,3 +46,5 @@ WEAKRANDOM = YES +[DSTORE] +QUOTA = 1 Modified: GNUnet/src/applications/dstore_mysql/dstore_mysql.c =================================================================== --- GNUnet/src/applications/dstore_mysql/dstore_mysql.c 2008-03-02 01:37:06 UTC (rev 6495) +++ GNUnet/src/applications/dstore_mysql/dstore_mysql.c 2008-03-02 01:55:36 UTC (rev 6496) @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2006, 2007 Christian Grothoff (and other contributing authors) + (C) 2006, 2007, 2008 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -19,7 +19,7 @@ */ /** - * @file applications/dstore_mysql/dstore.c + * @file applications/dstore_mysql/dstore_mysql.c * @brief MySQL based implementation of the dstore service * @author Christian Grothoff * @todo Indexes, statistics @@ -61,10 +61,12 @@ static unsigned int stat_dstore_size; +static unsigned int stat_dstore_quota; + /** * Estimate of the per-entry overhead (including indices). */ -#define OVERHEAD ((4+4+8+8*2+sizeof(GNUNET_HashCode)*2+32)) +#define OVERHEAD ((4*2+4*2+8*2+8*2+sizeof(GNUNET_HashCode)*5+8)) struct GNUNET_BloomFilter *bloom; @@ -81,22 +83,25 @@ static MYSQL *dbf; -#define SELECT_VALUE_STMT "SELECT size, value FROM gn073dstore WHERE hash=? AND type=? AND expire >= ?" +#define SELECT_VALUE_STMT "SELECT size, value FROM gn080dstore FORCE INDEX (hashidx) WHERE hash=? AND type=? AND expire >= ? LIMIT 1 OFFSET ?" static MYSQL_STMT *select_value; -#define SELECT_OLD_VALUE_STMT "SELECT hash, type, expire, puttime, size, value FROM gn073dstore ORDER BY puttime ASC LIMIT 1" +#define COUNT_VALUE_STMT "SELECT count(*) FROM gn080dstore FORCE INDEX (hashidx) WHERE hash=? AND type=? AND expire >= ?" +static MYSQL_STMT *count_value; + +#define SELECT_OLD_VALUE_STMT "SELECT hash, vhash, type, size, value FROM gn080dstore FORCE INDEX (expireidx) ORDER BY puttime ASC LIMIT 1" static MYSQL_STMT *select_old_value; -#define DELETE_VALUE_STMT "DELETE FROM gn073dstore WHERE hash = ? AND type = ? AND "\ - "expire = ? AND puttime = ? AND size = ? AND value = ?" +#define DELETE_VALUE_STMT "DELETE FROM gn080dstore WHERE hash = ? AND vhash = ? AND type = ? AND "\ + "size = ? AND value = ?" static MYSQL_STMT *delete_value; -#define INSERT_VALUE_STMT "INSERT INTO gn073dstore (puttime, expire, hash, type, size, value) "\ - "VALUES (?, ?, ?, ?, ?, ?)" +#define INSERT_VALUE_STMT "INSERT INTO gn080dstore (size, type, puttime, expire, hash, vhash, value) "\ + "VALUES (?, ?, ?, ?, ?, ?, ?)" static MYSQL_STMT *insert_value; -#define UPDATE_VALUE_STMT "UPDATE gn073dstore SET puttime=?, expire=? "\ - "WHERE hash=? AND type=? AND size=? AND value=?" +#define UPDATE_VALUE_STMT "UPDATE gn080dstore FORCE INDEX (allidx) SET puttime=?, expire=? "\ + "WHERE hash=? AND vhash=? AND type=? AND size=?" static MYSQL_STMT *update_value; /** @@ -124,11 +129,14 @@ if (dbf == NULL) return GNUNET_SYSERR; PEND (select_value); + PEND (count_value); PEND (select_old_value); PEND (delete_value); PEND (insert_value); PEND (update_value); +#undef PEND mysql_close (dbf); + payload = 0; dbf = NULL; return GNUNET_OK; } @@ -188,16 +196,18 @@ return GNUNET_SYSERR; } - mysql_query (dbf, "DROP TABLE gn073dstore"); + mysql_query (dbf, "DROP TABLE gn080dstore"); mysql_query (dbf, - "CREATE TEMPORARY TABLE gn073dstore (" + "CREATE TEMPORARY TABLE gn080dstore (" " size INT(11) UNSIGNED NOT NULL DEFAULT 0," " type INT(11) UNSIGNED NOT NULL DEFAULT 0," " puttime BIGINT UNSIGNED NOT NULL DEFAULT 0," " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," " hash BINARY(64) NOT NULL DEFAULT ''," + " vhash BINARY(64) PRIMARY KEY," " value BLOB NOT NULL DEFAULT ''," " INDEX hashidx (hash(64),type,expire)," + " INDEX allidx (hash(64),vhash(64),type,size)," " INDEX expireidx (puttime)" ") ENGINE=InnoDB"); if (mysql_error (dbf)[0]) { @@ -220,10 +230,12 @@ _("`%s' failed at %s:%d with error: %s"), "mysql_stmt_prepare", __FILE__, __LINE__, \ mysql_stmt_error (a)); iclose(); return GNUNET_SYSERR; } } PINIT (select_value, SELECT_VALUE_STMT); + PINIT (count_value, COUNT_VALUE_STMT); PINIT (select_old_value, SELECT_OLD_VALUE_STMT); PINIT (delete_value, DELETE_VALUE_STMT); PINIT (insert_value, INSERT_VALUE_STMT); PINIT (update_value, UPDATE_VALUE_STMT); +#undef PINIT return GNUNET_OK; } @@ -235,12 +247,12 @@ static int checkQuota () { - MYSQL_BIND rbind[6]; + MYSQL_BIND rbind[5]; unsigned int v_size; unsigned int v_type; - GNUNET_CronTime v_puttime; - GNUNET_CronTime v_expire; GNUNET_HashCode v_key; + GNUNET_HashCode vhash; + unsigned long k_length; unsigned long h_length; unsigned long v_length; @@ -252,30 +264,29 @@ "DStore above qutoa (have %llu, allowed %llu), will delete some data.\n", payload, quota); #endif + k_length = sizeof (GNUNET_HashCode); h_length = sizeof (GNUNET_HashCode); v_length = GNUNET_MAX_BUFFER_SIZE; memset (rbind, 0, sizeof (rbind)); rbind[0].buffer_type = MYSQL_TYPE_BLOB; rbind[0].buffer_length = sizeof (GNUNET_HashCode); - rbind[0].length = &h_length; + rbind[0].length = &k_length; rbind[0].buffer = &v_key; - rbind[1].buffer_type = MYSQL_TYPE_LONG; - rbind[1].is_unsigned = 1; - rbind[1].buffer = &v_type; - rbind[2].buffer_type = MYSQL_TYPE_LONGLONG; + rbind[1].buffer_type = MYSQL_TYPE_BLOB; + rbind[1].buffer_length = sizeof (GNUNET_HashCode); + rbind[1].length = &h_length; + rbind[1].buffer = &vhash; + rbind[2].buffer_type = MYSQL_TYPE_LONG; rbind[2].is_unsigned = 1; - rbind[2].buffer = &v_expire; - rbind[3].buffer_type = MYSQL_TYPE_LONGLONG; + rbind[2].buffer = &v_type; + rbind[3].buffer_type = MYSQL_TYPE_LONG; rbind[3].is_unsigned = 1; - rbind[3].buffer = &v_puttime; - rbind[4].buffer_type = MYSQL_TYPE_LONG; - rbind[4].is_unsigned = 1; - rbind[4].buffer = &v_size; - rbind[5].buffer_type = MYSQL_TYPE_BLOB; - rbind[5].buffer_length = GNUNET_MAX_BUFFER_SIZE; - rbind[5].length = &v_length; - rbind[5].buffer = GNUNET_malloc (GNUNET_MAX_BUFFER_SIZE); + rbind[3].buffer = &v_size; + rbind[4].buffer_type = MYSQL_TYPE_BLOB; + rbind[4].buffer_length = GNUNET_MAX_BUFFER_SIZE; + rbind[4].length = &v_length; + rbind[4].buffer = GNUNET_malloc (GNUNET_MAX_BUFFER_SIZE); GNUNET_mutex_lock (lock); mysql_thread_init (); @@ -286,14 +297,14 @@ _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_execute", __FILE__, __LINE__, mysql_stmt_error (select_old_value)); - GNUNET_free (rbind[5].buffer); + GNUNET_free (rbind[4].buffer); iclose (); mysql_thread_end (); GNUNET_mutex_unlock (lock); return GNUNET_SYSERR; } GNUNET_GE_ASSERT (coreAPI->ectx, - mysql_stmt_field_count (select_old_value) == 6); + mysql_stmt_field_count (select_old_value) == 5); if (mysql_stmt_bind_result (select_old_value, rbind)) { GNUNET_GE_LOG (coreAPI->ectx, @@ -301,21 +312,20 @@ _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_bind_result", __FILE__, __LINE__, mysql_stmt_error (select_old_value)); - GNUNET_free (rbind[5].buffer); + GNUNET_free (rbind[4].buffer); iclose (); mysql_thread_end (); GNUNET_mutex_unlock (lock); return GNUNET_SYSERR; } - if ((0 != mysql_stmt_fetch (select_old_value)) || - (h_length != sizeof (GNUNET_HashCode))) + if (0 != mysql_stmt_fetch (select_old_value)) { GNUNET_GE_LOG (coreAPI->ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, _("`%s' failed at %s:%d with error: %s\n"), - "mysql_stmt_bind_result", + "mysql_stmt_fetch", __FILE__, __LINE__, mysql_stmt_error (select_old_value)); - GNUNET_free (rbind[5].buffer); + GNUNET_free (rbind[4].buffer); mysql_stmt_reset (select_old_value); mysql_thread_end (); GNUNET_mutex_unlock (lock); @@ -329,12 +339,14 @@ _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_bind_param", __FILE__, __LINE__, mysql_stmt_error (delete_value)); - GNUNET_free (rbind[5].buffer); + GNUNET_free (rbind[4].buffer); iclose (); mysql_thread_end (); GNUNET_mutex_unlock (lock); return GNUNET_SYSERR; } + GNUNET_GE_BREAK(NULL, h_length == sizeof (GNUNET_HashCode)); + if (mysql_stmt_execute (delete_value)) { GNUNET_GE_LOG (coreAPI->ectx, @@ -342,17 +354,19 @@ _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_execute", __FILE__, __LINE__, mysql_stmt_error (delete_value)); - GNUNET_free (rbind[5].buffer); + GNUNET_free (rbind[4].buffer); iclose (); mysql_thread_end (); GNUNET_mutex_unlock (lock); return GNUNET_SYSERR; } - GNUNET_free (rbind[5].buffer); + GNUNET_free (rbind[4].buffer); payload -= v_length + OVERHEAD; mysql_stmt_reset (delete_value); mysql_thread_end (); GNUNET_mutex_unlock (lock); + if (bloom != NULL) + GNUNET_bloomfilter_remove (bloom, &v_key); if (payload * 10 > quota * 9) return GNUNET_NO; return GNUNET_OK; @@ -368,13 +382,16 @@ unsigned int type, GNUNET_CronTime discard_time, unsigned int size, const char *data) { - MYSQL_BIND rbind[6]; + MYSQL_BIND rbind[7]; GNUNET_CronTime now; + unsigned long k_length; unsigned long h_length; unsigned long v_length; + GNUNET_HashCode vhash; if (size > MAX_CONTENT_SIZE) return GNUNET_SYSERR; + GNUNET_hash(data, size, &vhash); GNUNET_mutex_lock (lock); mysql_thread_init (); iopen (); @@ -382,6 +399,7 @@ /* first try UPDATE */ h_length = sizeof (GNUNET_HashCode); + k_length = sizeof (GNUNET_HashCode); v_length = size; memset (rbind, 0, sizeof (rbind)); rbind[0].buffer_type = MYSQL_TYPE_LONGLONG; @@ -392,18 +410,18 @@ rbind[1].buffer = &discard_time; rbind[2].buffer_type = MYSQL_TYPE_BLOB; rbind[2].buffer_length = sizeof (GNUNET_HashCode); - rbind[2].length = &h_length; + rbind[2].length = &k_length; rbind[2].buffer = (void *) key; - rbind[3].buffer_type = MYSQL_TYPE_LONG; - rbind[3].is_unsigned = 1; - rbind[3].buffer = &type; + rbind[3].buffer_type = MYSQL_TYPE_BLOB; + rbind[3].buffer_length = sizeof (GNUNET_HashCode); + rbind[3].length = &h_length; + rbind[3].buffer = &vhash; rbind[4].buffer_type = MYSQL_TYPE_LONG; rbind[4].is_unsigned = 1; - rbind[4].buffer = &size; - rbind[5].buffer_type = MYSQL_TYPE_BLOB; - rbind[5].buffer_length = size; - rbind[5].length = &v_length; - rbind[5].buffer = (void *) data; + rbind[4].buffer = &type; + rbind[5].buffer_type = MYSQL_TYPE_LONG; + rbind[5].is_unsigned = 1; + rbind[5].buffer = &size; if (mysql_stmt_bind_param (update_value, rbind)) { @@ -427,6 +445,35 @@ mysql_stmt_reset (update_value); /* now try INSERT */ + h_length = sizeof (GNUNET_HashCode); + k_length = sizeof (GNUNET_HashCode); + v_length = size; + memset (rbind, 0, sizeof (rbind)); + rbind[0].buffer_type = MYSQL_TYPE_LONG; + rbind[0].is_unsigned = 1; + rbind[0].buffer = &size; + rbind[1].buffer_type = MYSQL_TYPE_LONG; + rbind[1].is_unsigned = 1; + rbind[1].buffer = &type; + rbind[2].buffer_type = MYSQL_TYPE_LONGLONG; + rbind[2].is_unsigned = 1; + rbind[2].buffer = &now; + rbind[3].buffer_type = MYSQL_TYPE_LONGLONG; + rbind[3].is_unsigned = 1; + rbind[3].buffer = &discard_time; + rbind[4].buffer_type = MYSQL_TYPE_BLOB; + rbind[4].buffer_length = sizeof (GNUNET_HashCode); + rbind[4].length = &k_length; + rbind[4].buffer = (void *) key; + rbind[5].buffer_type = MYSQL_TYPE_BLOB; + rbind[5].buffer_length = sizeof (GNUNET_HashCode); + rbind[5].length = &h_length; + rbind[5].buffer = &vhash; + rbind[6].buffer_type = MYSQL_TYPE_BLOB; + rbind[6].buffer_length = size; + rbind[6].length = &v_length; + rbind[6].buffer = (void*) data; + if (mysql_stmt_bind_param (insert_value, rbind)) { GNUNET_GE_LOG (coreAPI->ectx, @@ -444,7 +491,7 @@ GNUNET_GE_LOG (coreAPI->ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, _("`%s' failed at %s:%d with error: %s\n"), - "mysql_stmt_bind_param", + "mysql_stmt_execute", __FILE__, __LINE__, mysql_stmt_error (insert_value)); iclose (); mysql_thread_end (); @@ -477,13 +524,15 @@ d_get (const GNUNET_HashCode * key, unsigned int type, GNUNET_ResultProcessor handler, void *closure) { - MYSQL_BIND qbind[3]; + MYSQL_BIND qbind[4]; MYSQL_BIND rbind[2]; unsigned int v_size; unsigned long h_length; unsigned long v_length; GNUNET_CronTime now; unsigned int cnt; + unsigned long long total; + unsigned int off; GNUNET_mutex_lock (lock); if ((bloom != NULL) && (GNUNET_NO == GNUNET_bloomfilter_test (bloom, key))) @@ -512,57 +561,145 @@ qbind[2].is_unsigned = 1; qbind[2].buffer = &now; + total = -1; + memset (rbind, 0, sizeof (rbind)); + rbind[0].buffer_type = MYSQL_TYPE_LONGLONG; + rbind[0].buffer = &total; + rbind[0].is_unsigned = GNUNET_YES; + mysql_thread_init (); iopen (); - if (mysql_stmt_bind_param (select_value, qbind)) + + if (mysql_stmt_bind_param (count_value, qbind)) { GNUNET_GE_LOG (coreAPI->ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_bind_param", - __FILE__, __LINE__, mysql_stmt_error (select_value)); + __FILE__, __LINE__, mysql_stmt_error (count_value)); iclose (); mysql_thread_end (); GNUNET_mutex_unlock (lock); return GNUNET_SYSERR; } - if (mysql_stmt_execute (select_value)) + if (mysql_stmt_execute (count_value)) { GNUNET_GE_LOG (coreAPI->ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_execute", - __FILE__, __LINE__, mysql_stmt_error (select_value)); + __FILE__, __LINE__, mysql_stmt_error (count_value)); iclose (); GNUNET_mutex_unlock (lock); mysql_thread_end (); return GNUNET_SYSERR; } + - memset (rbind, 0, sizeof (rbind)); - rbind[0].buffer_type = MYSQL_TYPE_LONG; - rbind[0].is_unsigned = 1; - rbind[0].buffer = &v_size; - rbind[1].buffer_type = MYSQL_TYPE_BLOB; - rbind[1].buffer_length = GNUNET_MAX_BUFFER_SIZE; - rbind[1].length = &v_length; - rbind[1].buffer = GNUNET_malloc (GNUNET_MAX_BUFFER_SIZE); - if (mysql_stmt_bind_result (select_value, rbind)) + if (mysql_stmt_bind_result (count_value, rbind)) { GNUNET_GE_LOG (coreAPI->ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, _("`%s' failed at %s:%d with error: %s\n"), "mysql_stmt_bind_result", - __FILE__, __LINE__, mysql_stmt_error (select_value)); + __FILE__, __LINE__, mysql_stmt_error (count_value)); iclose (); mysql_thread_end (); GNUNET_mutex_unlock (lock); - GNUNET_free (rbind[1].buffer); return GNUNET_SYSERR; } + if (0 != mysql_stmt_fetch (count_value)) + { + GNUNET_GE_LOG (coreAPI->ectx, + GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, + _("`%s' failed at %s:%d with error: %s\n"), + "mysql_stmt_fetch", + __FILE__, __LINE__, mysql_stmt_error (count_value)); + mysql_stmt_reset (count_value); + iclose (); + GNUNET_mutex_unlock (lock); + mysql_thread_end (); + return GNUNET_SYSERR; + } + if (-1 == total) + { + GNUNET_GE_LOG (coreAPI->ectx, + GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, + _("`%s' failed at %s:%d with error: %s\n"), + "mysql_stmt_fetch", + __FILE__, __LINE__, mysql_stmt_error (count_value)); + iclose (); + GNUNET_mutex_unlock (lock); + mysql_thread_end (); + return GNUNET_SYSERR; + } + mysql_stmt_reset (count_value); + if ((handler == NULL) || (total == 0)) + { + GNUNET_mutex_unlock (lock); + mysql_thread_end (); + return (int) total; + } + + off = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, total); + qbind[3].buffer_type = MYSQL_TYPE_LONG; + qbind[3].is_unsigned = 1; + qbind[3].buffer = &off; + cnt = 0; - while (0 == mysql_stmt_fetch (select_value)) + while (cnt < total) { + off = (off + 1) % total; + if (mysql_stmt_bind_param (select_value, qbind)) + { + GNUNET_GE_LOG (coreAPI->ectx, + GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, + _("`%s' failed at %s:%d with error: %s\n"), + "mysql_stmt_bind_param", + __FILE__, __LINE__, mysql_stmt_error (select_value)); + iclose (); + mysql_thread_end (); + GNUNET_mutex_unlock (lock); + return GNUNET_SYSERR; + } + if (mysql_stmt_execute (select_value)) + { + GNUNET_GE_LOG (coreAPI->ectx, + GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, + _("`%s' failed at %s:%d with error: %s\n"), + "mysql_stmt_execute", + __FILE__, __LINE__, mysql_stmt_error (select_value)); + iclose (); + GNUNET_mutex_unlock (lock); + mysql_thread_end (); + return GNUNET_SYSERR; + } + memset (rbind, 0, sizeof (rbind)); + rbind[0].buffer_type = MYSQL_TYPE_LONG; + rbind[0].is_unsigned = 1; + rbind[0].buffer = &v_size; + rbind[1].buffer_type = MYSQL_TYPE_BLOB; + rbind[1].buffer_length = GNUNET_MAX_BUFFER_SIZE; + rbind[1].length = &v_length; + rbind[1].buffer = GNUNET_malloc (GNUNET_MAX_BUFFER_SIZE); + if (mysql_stmt_bind_result (select_value, rbind)) + { + GNUNET_GE_LOG (coreAPI->ectx, + GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, + _("`%s' failed at %s:%d with error: %s\n"), + "mysql_stmt_bind_result", + __FILE__, __LINE__, mysql_stmt_error (select_value)); + iclose (); + mysql_thread_end (); + GNUNET_mutex_unlock (lock); + GNUNET_free (rbind[1].buffer); + return GNUNET_SYSERR; + } + if (0 != mysql_stmt_fetch (select_value)) + { + GNUNET_GE_BREAK(NULL, 0); + break; + } if (v_length != v_size) { GNUNET_GE_BREAK (NULL, 0); @@ -572,7 +709,8 @@ GNUNET_free (rbind[1].buffer); return cnt; } - handler (key, type, v_size, rbind[1].buffer, closure); + if (GNUNET_OK != handler (key, type, v_size, rbind[1].buffer, closure)) + break; cnt++; } mysql_stmt_reset (select_value); @@ -658,7 +796,12 @@ } stats = capi->request_service ("stats"); if (stats != NULL) - stat_dstore_size = stats->create (gettext_noop ("# bytes in dstore")); + { + stat_dstore_size = stats->create (gettext_noop ("# bytes in dstore")); + stat_dstore_quota = stats->create (gettext_noop ("# max bytes allowed in dstore")); + stats->set(stat_dstore_quota, + quota); + } return &api; } Added: GNUnet/src/applications/dstore_mysql/dstore_quota_test.c =================================================================== --- GNUnet/src/applications/dstore_mysql/dstore_quota_test.c (rev 0) +++ GNUnet/src/applications/dstore_mysql/dstore_quota_test.c 2008-03-02 01:55:36 UTC (rev 6496) @@ -0,0 +1,115 @@ +/* + This file is part of GNUnet. + (C) 2006, 2008 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/* + * @file applications/dstore/dstore_quota_test.c + * @brief Test for the dstore implementations. + * @author Nils Durner + */ + +#include "platform.h" +#include "gnunet_util.h" +#include "gnunet_protocols.h" +#include "gnunet_dstore_service.h" +#include "core.h" + +#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0) + +/** + * Quota is 1 MB. Each iteration of the test puts in about 1 MB of + * data. We do 10 iterations. Afterwards we check that the data from + * the first 5 iterations has all been discarded and that at least + * some of the data from the last iteration is still there. + */ +static int +test (GNUNET_Dstore_ServiceAPI * api) +{ + GNUNET_HashCode k; + GNUNET_HashCode n; + unsigned int i; + unsigned int j; + char buf[3200]; + + memset(buf, 1, sizeof(buf)); + memset (&k, 0, sizeof (GNUNET_HashCode)); + for (i = 0; i < 10; i++) + { + fprintf(stderr, "."); + GNUNET_hash (&k, sizeof (GNUNET_HashCode), &n); + for (j=i;j<sizeof(buf);j+=10) + { + buf[j] = i; + ASSERT (GNUNET_OK == api->put (&k, + i, + GNUNET_get_time() + 30 * GNUNET_CRON_MINUTES, + j, + buf)); + ASSERT (0 != api->get (&k, i, NULL, NULL)); + } + k = n; + } + fprintf(stderr, "\n"); + memset (&k, 0, sizeof (GNUNET_HashCode)); + for (i = 0; i < 10; i++) + { + fprintf(stderr, "."); + GNUNET_hash (&k, sizeof (GNUNET_HashCode), &n); + if (i < 5) + ASSERT (0 == api->get (&k, i, NULL, NULL)); + if (i == 9) + ASSERT (0 != api->get (&k, i, NULL, NULL)); + k = n; + } + fprintf(stderr, "\n"); + return GNUNET_OK; +FAILURE: + return GNUNET_SYSERR; +} + +int +main (int argc, char *argv[]) +{ + GNUNET_Dstore_ServiceAPI *api; + int ok; + struct GNUNET_GC_Configuration *cfg; + struct GNUNET_CronManager *cron; + + cfg = GNUNET_GC_create (); + if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) + { + GNUNET_GC_free (cfg); + return -1; + } + cron = GNUNET_cron_create (NULL); + GNUNET_CORE_init (NULL, cfg, cron, NULL); + api = GNUNET_CORE_request_service ("dstore"); + if (api != NULL) + { + ok = test (api); + GNUNET_CORE_release_service (api); + } + else + ok = GNUNET_SYSERR; + GNUNET_CORE_done (); + if (ok == GNUNET_SYSERR) + return 1; + return 0; +} + +/* end of dstore_quota_test.c */ Property changes on: GNUnet/src/applications/dstore_mysql/dstore_quota_test.c ___________________________________________________________________ Name: svn:eol-style + native Modified: GNUnet/src/applications/dstore_mysql/dstore_test.c =================================================================== --- GNUnet/src/applications/dstore_mysql/dstore_test.c 2008-03-02 01:37:06 UTC (rev 6495) +++ GNUnet/src/applications/dstore_mysql/dstore_test.c 2008-03-02 01:55:36 UTC (rev 6496) @@ -33,7 +33,7 @@ static int error; -static void +static int checkIt (const GNUNET_HashCode * key, unsigned int type, unsigned int size, const char *data, void *cls) { @@ -47,6 +47,7 @@ printf ("ERROR: Invalid data\n"); error = 3; } + return GNUNET_OK; } /** _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn