[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r395 - in GNUnet/src: applications/sqstore_mysql applicatio
From: |
grothoff |
Subject: |
[GNUnet-SVN] r395 - in GNUnet/src: applications/sqstore_mysql applications/sqstore_sqlite include util |
Date: |
Sun, 6 Mar 2005 15:33:10 -0800 (PST) |
Author: grothoff
Date: 2005-03-06 15:33:08 -0800 (Sun, 06 Mar 2005)
New Revision: 395
Modified:
GNUnet/src/applications/sqstore_mysql/mysql.c
GNUnet/src/applications/sqstore_mysql/mysqltest.c
GNUnet/src/applications/sqstore_sqlite/sqlite.c
GNUnet/src/applications/sqstore_sqlite/sqlitetest.c
GNUnet/src/include/gnunet_sqstore_service.h
GNUnet/src/util/dso.c
Log:
extending testcases, minor bugfixes
Modified: GNUnet/src/applications/sqstore_mysql/mysql.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysql.c 2005-03-06 22:11:38 UTC
(rev 394)
+++ GNUnet/src/applications/sqstore_mysql/mysql.c 2005-03-06 23:33:08 UTC
(rev 395)
@@ -604,7 +604,7 @@
if (iter == NULL)
SNPRINTF(scratch,
n,
- "SELECT count(*) FROM gn070 WHERE hash='%s' AND type=%u",
+ "SELECT COUNT(*) FROM gn070 WHERE hash='%s' AND type=%u",
escapedHash,
type);
else
@@ -617,7 +617,7 @@
if (iter == NULL)
SNPRINTF(scratch,
n,
- "SELECT count(*) FROM gn070 WHERE hash='%s'",
+ "SELECT COUNT(*) FROM gn070 WHERE hash='%s'",
escapedHash);
else
SNPRINTF(scratch,
@@ -956,20 +956,25 @@
LOG(LOG_DEBUG,
"MySQL is executing deletion request for content of query '%s' and type
%u\n",
&enc,
- ntohl(value->type));
+ value == NULL ? 0 : ntohl(value->type));
MUTEX_LOCK(&dbh->DATABASE_Lock_);
- contentSize = ntohl(value->size)-sizeof(Datastore_Value);
+ if (value != NULL) {
+ contentSize = ntohl(value->size)-sizeof(Datastore_Value);
+ escapedBlock = MALLOC(2*contentSize+1);
+ mysql_real_escape_string(dbh->dbf,
+ escapedBlock,
+ (char *)&value[1],
+ contentSize);
+ } else {
+ escapedBlock = NULL;
+ contentSize = 0;
+ }
+
escapedHash = MALLOC(2*sizeof(HashCode512)+1);
mysql_real_escape_string(dbh->dbf,
escapedHash,
(char *)key,
sizeof(HashCode512));
- escapedBlock = MALLOC(2*contentSize+1);
- mysql_real_escape_string(dbh->dbf,
- escapedBlock,
- (char *)&value[1],
- contentSize);
-
n = sizeof(HashCode512)*2+contentSize*2+400+1;
scratch = MALLOC(n);
if(value == NULL) {
@@ -997,7 +1002,7 @@
}
mysql_query(dbh->dbf, scratch);
FREE(escapedHash);
- FREE(escapedBlock);
+ FREENONNULL(escapedBlock);
FREE(scratch);
if(mysql_error(dbh->dbf)[0]) {
LOG_MYSQL(LOG_ERROR,
@@ -1118,7 +1123,7 @@
GNUNET_ASSERT(avgRowLen >= 0);
/* find number of entries (rows) */
mysql_query(dbh->dbf,
- "SELECT count(*) FROM gn070");
+ "SELECT COUNT(*) FROM gn070");
if (!(sql_res=mysql_store_result(dbh->dbf))) {
MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
DIE_MYSQL("mysql_store_result", dbh);
Modified: GNUnet/src/applications/sqstore_mysql/mysqltest.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysqltest.c 2005-03-06 22:11:38 UTC
(rev 394)
+++ GNUnet/src/applications/sqstore_mysql/mysqltest.c 2005-03-06 23:33:08 UTC
(rev 395)
@@ -79,6 +79,38 @@
return ret;
}
+
+static int priorityCheck(const HashCode512 * key,
+ const Datastore_Value * val,
+ int * closure) {
+ int id;
+
+ id = (*closure);
+ if (id == ntohl(val->prio))
+ return OK;
+ else
+ return SYSERR;
+}
+
+static int multipleCheck(const HashCode512 * key,
+ const Datastore_Value * val,
+ Datastore_Value ** last) {
+ if (*last != NULL) {
+ if ( ((*last)->size == val->size) &&
+ (0 == memcmp(*last,
+ val,
+ ntohl(val->size)) ) )
+ return SYSERR; /* duplicate! */
+ FREE(*last);
+ }
+ *last = MALLOC(ntohl(val->size));
+ memcpy(*last,
+ val,
+ ntohl(val->size));
+ return OK;
+}
+
+
/**
* Add testcode here!
*/
@@ -133,9 +165,41 @@
FREE(value);
}
+
+ i = 42;
+ value = initValue(i);
+ memset(&key, 256-i, sizeof(HashCode512));
+ api->put(&key, value);
+ ASSERT(1 == api->iterateExpirationTime(ANY_BLOCK,
+ (Datum_Iterator) &priorityCheck,
+ &i));
+ api->update(&key,
+ value,
+ 4);
+ i += 4;
+ ASSERT(1 == api->iterateExpirationTime(ANY_BLOCK,
+ (Datum_Iterator) &priorityCheck,
+ &i));
+ FREE(value);
+
+ /* test multiple results */
+ value = initValue(i+1);
+ api->put(&key, value);
+ FREE(value);
+
+ value = NULL;
+ ASSERT(2 == api->iterateExpirationTime(ANY_BLOCK,
+ (Datum_Iterator) &multipleCheck,
+ &value));
+ FREE(value);
+ api->del(&key,
+ NULL);
+ api->del(&key,
+ NULL);
+ ASSERT(0 == api->iterateExpirationTime(ANY_BLOCK,
+ NULL,
+ NULL));
- /* FIXME: test 'update' here! */
-
api->drop();
return OK;
FAILURE:
Modified: GNUnet/src/applications/sqstore_sqlite/sqlite.c
===================================================================
--- GNUnet/src/applications/sqstore_sqlite/sqlite.c 2005-03-06 22:11:38 UTC
(rev 394)
+++ GNUnet/src/applications/sqstore_sqlite/sqlite.c 2005-03-06 23:33:08 UTC
(rev 395)
@@ -213,7 +213,7 @@
sqlite3_stmt *stmt;
double ret = SYSERR;
- i = sq_prepare("Select anonLevel from gn070 where hash = ?",
+ i = sq_prepare("SELECT anonLevel FROM gn070 WHERE hash = ?",
&stmt);
if (i == SQLITE_OK) {
sqlite3_bind_text(stmt,
@@ -253,7 +253,7 @@
double val) {
sqlite3_stmt *stmt;
- if (sq_prepare("REPLACE into gn070(hash, anonLevel, type) values (?, ?, ?)",
+ if (sq_prepare("REPLACE INTO gn070(hash, anonLevel, type) VALUES (?, ?, ?)",
&stmt) == SQLITE_OK) {
sqlite3_bind_text(stmt,
1,
@@ -506,6 +506,7 @@
char *fn = STRDUP(dbh->fn);
sqlite_shutdown();
UNLINK(fn);
+ FREE(fn);
}
@@ -762,7 +763,7 @@
}
sqlite3_reset(dbh->exists);
- n = sq_prepare("DELETE FROM gn070 WHERE hash = ?",
+ n = sq_prepare("DELETE FROM gn070 WHERE hash = ?", /* ORDER BY prio ASC
LIMIT 1" -- not available */
&stmt);
if (n == SQLITE_OK) {
sqlite3_bind_blob(stmt,
@@ -774,8 +775,8 @@
}
} else {
n = sq_prepare("DELETE FROM gn070 WHERE hash = ? and "
- "value = ? and size = ? and type = ? and prio = ? and
anonLevel = ? "
- "and expire = ?",
+ "value = ? AND size = ? AND type = ? AND prio = ? AND
anonLevel = ? "
+ "AND expire = ?", /* ORDER BY prio ASC LIMIT 1" -- not
available in sqlite */
&stmt);
if (n == SQLITE_OK) {
escapedBlock = MALLOC(2 * (ntohl(value->size)-sizeof(Datastore_Value)) +
1);
@@ -913,6 +914,7 @@
nX = strlen(dir) + 6 + 4 + 256; /* 6 = "gnunet", 4 = ".dat" */
dbh->fn = MALLOC(strlen(dir) + 6 + 4 + 256);
SNPRINTF(dbh->fn, nX, "%s/gnunet.dat", dir);
+ FREE(dir);
if (sqlite3_open(dbh->fn, &dbh->dbf) != SQLITE_OK) {
LOG(LOG_ERROR,
@@ -931,13 +933,13 @@
if (sqlite3_step(stmt) == SQLITE_DONE) {
if (sqlite3_exec(dbh->dbf,
"CREATE TABLE gn070 ("
- " size integer NOT NULL default 0,"
- " type integer NOT NULL default 0,"
- " prio integer NOT NULL default 0,"
- " anonLevel integer NOT NULL default 0,"
- " expire integer NOT NULL default 0,"
- " hash text NOT NULL default '',"
- " value blob NOT NULL default '')", NULL, NULL,
+ " size INTEGER NOT NULL DEFAULT 0,"
+ " type INTEGER NOT NULL DEFAULT 0,"
+ " prio INTEGER NOT NULL DEFAULT 0,"
+ " anonLevel INTEGER NOT NULL DEFAULT 0,"
+ " expire INTEGER NOT NULL DEFAULT 0,"
+ " hash TEXT NOT NULL DEFAULT '',"
+ " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
NULL) != SQLITE_OK) {
LOG_SQLITE(LOG_ERROR, "sqlite_query");
FREE(dbh->fn);
@@ -954,16 +956,16 @@
sqlite3_exec(dbh->dbf, "CREATE INDEX idx_expire ON gn070 (expire)",
NULL, NULL, NULL);
- if ( (sq_prepare("SELECT count(*) FROM gn070 where hash=?",
+ if ( (sq_prepare("SELECT COUNT(*) FROM gn070 WHERE hash=?",
&dbh->countContent) != SQLITE_OK) ||
- (sq_prepare("SELECT length(hash), length(value) "
- "from gn070 WHERE hash=?",
+ (sq_prepare("SELECT LENGTH(hash), LENGTH(value) "
+ "FROM gn070 WHERE hash=?",
&dbh->exists) != SQLITE_OK) ||
- (sq_prepare("UPDATE gn070 SET prio = prio + ? where "
- "hash = ? and value = ? and prio + ? < ?",
+ (sq_prepare("UPDATE gn070 SET prio = prio + ? WHERE "
+ "hash = ? AND value = ? AND prio + ? < ?",
&dbh->updPrio) != SQLITE_OK) ||
- (sq_prepare("insert into gn070 (size, type, prio, "
- "anonLevel, expire, hash, value) values "
+ (sq_prepare("INSERT INTO gn070 (size, type, prio, "
+ "anonLevel, expire, hash, value) VALUES "
"(?, ?, ?, ?, ?, ?, ?)",
&dbh->insertContent) != SQLITE_OK) ) {
LOG_SQLITE(LOG_ERROR,
Modified: GNUnet/src/applications/sqstore_sqlite/sqlitetest.c
===================================================================
--- GNUnet/src/applications/sqstore_sqlite/sqlitetest.c 2005-03-06 22:11:38 UTC
(rev 394)
+++ GNUnet/src/applications/sqstore_sqlite/sqlitetest.c 2005-03-06 23:33:08 UTC
(rev 395)
@@ -1,4 +1,23 @@
/*
+ This file is part of GNUnet.
+ (C) 2004, 2005 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/sqstore_sqlite/sqlitetest.c
* @brief Test for the sqstore implementations.
* @author Christian Grothoff
@@ -73,6 +92,38 @@
return ret;
}
+static int priorityCheck(const HashCode512 * key,
+ const Datastore_Value * val,
+ int * closure) {
+ int id;
+
+ id = (*closure);
+ if (id + 1 == ntohl(val->prio))
+ return OK;
+ else
+ return SYSERR;
+}
+
+static int multipleCheck(const HashCode512 * key,
+ const Datastore_Value * val,
+ Datastore_Value ** last) {
+ if (*last != NULL) {
+ if ( ((*last)->size == val->size) &&
+ (0 == memcmp(*last,
+ val,
+ ntohl(val->size)) ) )
+ return SYSERR; /* duplicate! */
+ FREE(*last);
+ }
+ *last = MALLOC(ntohl(val->size));
+ memcpy(*last,
+ val,
+ ntohl(val->size));
+ return OK;
+}
+
+
+
/**
* Add testcode here!
*/
@@ -119,10 +170,48 @@
(Datum_Iterator) &iterateDown,
&i));
ASSERT(0 == i);
-
-
- /* FIXME: test 'update' here! */
-
+
+ for (i=0;i<256;i+=2) {
+ memset(&key, 256-i, sizeof(HashCode512));
+ value = initValue(i);
+ ASSERT(1 == api->del(&key, value));
+ FREE(value);
+ }
+
+
+ i = 42;
+ value = initValue(i);
+ memset(&key, 256-i, sizeof(HashCode512));
+ api->put(&key, value);
+ ASSERT(1 == api->iterateExpirationTime(ANY_BLOCK,
+ (Datum_Iterator) &priorityCheck,
+ &i));
+ api->update(&key,
+ value,
+ 4);
+ i += 4;
+ ASSERT(1 == api->iterateExpirationTime(ANY_BLOCK,
+ (Datum_Iterator) &priorityCheck,
+ &i));
+ FREE(value);
+
+ /* test multiple results */
+ value = initValue(i+1);
+ api->put(&key, value);
+ FREE(value);
+
+ value = NULL;
+ ASSERT(2 == api->iterateExpirationTime(ANY_BLOCK,
+ (Datum_Iterator) &multipleCheck,
+ &value));
+ FREE(value);
+ api->del(&key,
+ NULL);
+ api->del(&key,
+ NULL);
+ ASSERT(0 == api->iterateExpirationTime(ANY_BLOCK,
+ NULL,
+ NULL));
api->drop();
return OK;
FAILURE:
Modified: GNUnet/src/include/gnunet_sqstore_service.h
===================================================================
--- GNUnet/src/include/gnunet_sqstore_service.h 2005-03-06 22:11:38 UTC (rev
394)
+++ GNUnet/src/include/gnunet_sqstore_service.h 2005-03-06 23:33:08 UTC (rev
395)
@@ -140,8 +140,15 @@
*
* @param value maybe NULL, then all items under the
* given key are deleted
- * @return the number of items deleted (at most 1!), 0 if
- * none were found, SYSERR on errors
+ * @return the number of items deleted (if possible, the
+ * database should delete only ONE matching item and
+ * pick the one with the lowest priority [and then
+ * lowest expiration time]; if the DB cannot do that,
+ * deleting multiple entries will be 'tolerated' for now,
+ * but the result is a slightly worse performance of the
+ * peer; however, that there are multiple matches should
+ * also be rare).
+ * 0 if no matching items were found, SYSERR on errors
*/
int (*del)(const HashCode512 * key,
const Datastore_Value * value);
Modified: GNUnet/src/util/dso.c
===================================================================
--- GNUnet/src/util/dso.c 2005-03-06 22:11:38 UTC (rev 394)
+++ GNUnet/src/util/dso.c 2005-03-06 23:33:08 UTC (rev 395)
@@ -101,9 +101,11 @@
}
void unloadDynamicLibrary(void * libhandle) {
+ /* when valgrinding, comment out these lines
+ to get decent traces for memory leaks on exit */
lt_dlclose(libhandle);
if (0 != lt_dlexit())
- LOG_STRERROR(LOG_WARNING, "lt_dlexit");
+ LOG_STRERROR(LOG_WARNING, "lt_dlexit");
}
void * trybindDynamicMethod(void * libhandle,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r395 - in GNUnet/src: applications/sqstore_mysql applications/sqstore_sqlite include util,
grothoff <=