gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r1852 - GNUnet/src/applications/sqstore_mysql


From: grothoff
Subject: [GNUnet-SVN] r1852 - GNUnet/src/applications/sqstore_mysql
Date: Mon, 22 Aug 2005 00:28:20 -0700 (PDT)

Author: grothoff
Date: 2005-08-22 00:28:18 -0700 (Mon, 22 Aug 2005)
New Revision: 1852

Modified:
   GNUnet/src/applications/sqstore_mysql/check.conf
   GNUnet/src/applications/sqstore_mysql/mysql.c
   GNUnet/src/applications/sqstore_mysql/mysqltest.c
Log:
fixing mantis 893

Modified: GNUnet/src/applications/sqstore_mysql/check.conf
===================================================================
--- GNUnet/src/applications/sqstore_mysql/check.conf    2005-08-22 06:43:58 UTC 
(rev 1851)
+++ GNUnet/src/applications/sqstore_mysql/check.conf    2005-08-22 07:28:18 UTC 
(rev 1852)
@@ -1,9 +1,7 @@
 [GNUNETD]
 GNUNETD_HOME = "/tmp/gnunet-mysql-sqstore-test"
 HELLOEXPIRES = 1440
-LOGLEVEL = "DEBUG"
-LOGFILE = "$GNUNETD_HOME/logs"
-KEEPLOG = "0"
+LOGLEVEL = "ERROR"
 PIDFILE = "$GNUNETD_HOME/gnunet.pid"
 HOSTS = "$GNUNETD_HOME/data/hosts/"
 HTTP-PROXY = ""
@@ -16,7 +14,7 @@
 topology = "topology_default"
 
 [NETWORK]
-PORT = 2087
+PORT = 32087
 INTERFACE = ""
 IP = ""
 HELLOEXCHANGE = YES
@@ -24,7 +22,7 @@
 
 [LOAD]
 BASICLIMITING = YES
-INTERFACES = ""
+INTERFACES = "eth0"
 MAXNETDOWNBPSTOTAL = 50000
 MAXNETUPBPSTOTAL = 50000
 MAXCPULOAD = 50

Modified: GNUnet/src/applications/sqstore_mysql/mysql.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysql.c       2005-08-22 06:43:58 UTC 
(rev 1851)
+++ GNUnet/src/applications/sqstore_mysql/mysql.c       2005-08-22 07:28:18 UTC 
(rev 1852)
@@ -179,6 +179,8 @@
   MYSQL_STMT * deleteh;
   MYSQL_STMT * deleteg;
   MYSQL_BIND dbind[7];
+  MYSQL_STMT * update;
+  MYSQL_BIND ubind[3];
 } mysqlHandle;
 
 #define INSERT_SAMPLE "INSERT INTO gn070 
(size,type,prio,anonLevel,expire,hash,value) VALUES (?,?,?,?,?,?,?)"
@@ -192,6 +194,8 @@
 #define DELETE_HASH_SAMPLE "DELETE FROM gn070 WHERE hash=? ORDER BY prio ASC 
LIMIT 1"
 #define DELETE_GENERIC_SAMPLE "DELETE FROM gn070 WHERE hash=? AND size=? AND 
type=? AND prio=? AND anonLevel=? AND expire=? AND value=? ORDER BY prio ASC 
LIMIT 1"
 
+#define UPDATE_SAMPLE "UPDATE gn070 SET prio=prio+? WHERE hash=? AND value=?"
+
 static mysqlHandle * dbh;
 
 /**
@@ -319,9 +323,11 @@
     dbhI->selectc = mysql_stmt_init(dbhI->dbf);
     dbhI->selects = mysql_stmt_init(dbhI->dbf);
     dbhI->selectsc = mysql_stmt_init(dbhI->dbf);
+    dbhI->update = mysql_stmt_init(dbhI->dbf);
     dbhI->deleteh = mysql_stmt_init(dbhI->dbf);
     dbhI->deleteg = mysql_stmt_init(dbhI->dbf);
     if ( (dbhI->insert == NULL) ||
+        (dbhI->update == NULL) ||
         (dbhI->select == NULL) ||
         (dbhI->selectc == NULL) ||
         (dbhI->selects == NULL) ||
@@ -331,6 +337,8 @@
       BREAK();
       if (dbhI->insert != NULL)
        mysql_stmt_close(dbhI->insert);
+      if (dbhI->update != NULL)
+       mysql_stmt_close(dbhI->update);
       if (dbhI->select != NULL)
        mysql_stmt_close(dbhI->select);
       if (dbhI->selectc != NULL)
@@ -362,6 +370,9 @@
        mysql_stmt_prepare(dbhI->selectsc,
                           SELECT_TYPE_SAMPLE_COUNT,
                           strlen(SELECT_TYPE_SAMPLE_COUNT)) ||
+       mysql_stmt_prepare(dbhI->update,
+                          UPDATE_SAMPLE,
+                          strlen(UPDATE_SAMPLE)) ||
        mysql_stmt_prepare(dbhI->deleteh,
                           DELETE_HASH_SAMPLE,
                           strlen(DELETE_HASH_SAMPLE)) ||
@@ -379,6 +390,7 @@
       mysql_stmt_close(dbhI->selects);
       mysql_stmt_close(dbhI->selectsc);
       mysql_stmt_close(dbhI->insert);
+      mysql_stmt_close(dbhI->update);
       mysql_stmt_close(dbhI->deleteh);
       mysql_stmt_close(dbhI->deleteg);
       mysql_close(dbhI->dbf);
@@ -410,6 +422,12 @@
     dbhI->dbind[4].buffer_type = MYSQL_TYPE_LONG; /* anon level */
     dbhI->dbind[5].buffer_type = MYSQL_TYPE_LONGLONG; /* expiration */
     dbhI->dbind[6].buffer_type = MYSQL_TYPE_BLOB; /* value */
+    memset(dbhI->ubind,
+          0,
+          sizeof(dbhI->ubind));
+    dbhI->ubind[0].buffer_type = MYSQL_TYPE_LONG;
+    dbhI->ubind[1].buffer_type = MYSQL_TYPE_BLOB;
+    dbhI->ubind[2].buffer_type = MYSQL_TYPE_BLOB;
     dbhI->prepare = YES;
   } else    
     dbhI->prepare = NO;
@@ -424,6 +442,7 @@
   if (dbhI->dbf == NULL)
     return SYSERR;
   if (dbhI->prepare == YES) {
+    mysql_stmt_free_result(dbhI->update);
     mysql_stmt_free_result(dbhI->insert);
     mysql_stmt_free_result(dbhI->select);
     mysql_stmt_free_result(dbhI->selectc);
@@ -431,6 +450,7 @@
     mysql_stmt_free_result(dbhI->selectsc);
     mysql_stmt_free_result(dbhI->deleteh);
     mysql_stmt_free_result(dbhI->deleteg);
+    mysql_stmt_close(dbhI->update);
     mysql_stmt_close(dbhI->insert);
     mysql_stmt_close(dbhI->select);
     mysql_stmt_close(dbhI->selectc);
@@ -792,10 +812,11 @@
        datasize = MAX_DATUM_SIZE;
        continue;
       }
+#if DEBUG_MYSQL
       LOG(LOG_DEBUG,
          "Found in database block with type %u.\n",
          ntohl(*(int*)&datum[1]));
-
+#endif
       if( SYSERR == iter(&key,
                         datum,
                         closure) ) {
@@ -1008,51 +1029,42 @@
 static int update(const HashCode512 * key,
                  const Datastore_Value * value,
                  int delta) {
-  char * escapedHash;
-  char * escapedBlock;
-  char * scratch;
-  int n;
-  int contentSize;
+  unsigned long contentSize;
+  unsigned long twenty;
 
+  twenty = sizeof(HashCode512);
   MUTEX_LOCK(&dbh->DATABASE_Lock_);
   contentSize = ntohl(value->size)-sizeof(Datastore_Value);
-
-  escapedHash = MALLOC(2*sizeof(HashCode512)+1);
-  mysql_escape_string(escapedHash,
-                     (char *)key,
-                     sizeof(HashCode512));
-  escapedBlock = MALLOC(2*contentSize+1);
-  mysql_escape_string(escapedBlock,
-                     (char *)&value[1],
-                     contentSize);
-  n = contentSize*2+sizeof(HashCode512)*2+100+1;
-  scratch = MALLOC(n);
-
+  dbh->ubind[0].buffer = (char*) δ
+  dbh->ubind[1].buffer = (char*) key;
+  dbh->ubind[1].length = &twenty;
+  dbh->ubind[2].buffer = (char*) &value[1];
+  dbh->ubind[2].length = &contentSize;
+  GNUNET_ASSERT(mysql_stmt_param_count(dbh->update) <= 3);
+  if (mysql_stmt_bind_param(dbh->update,
+                           dbh->ubind)) {
+    LOG(LOG_ERROR,
+       _("`%s' failed at %s:%d with error: %s\n"),
+       "mysql_stmt_bind_param",
+       __FILE__, __LINE__,
+       mysql_stmt_error(dbh->update));
+    MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
+    return SYSERR;
+  }  
   /* NOTE: as the table entry for 'prio' is defined as unsigned,
    * mysql will zero the value if its about to go negative. (This
    * will generate a warning though, but its probably not seen
    * at all in this context.)
    */
-  SNPRINTF(scratch,
-          n,
-          "UPDATE gn070"
-          " SET prio=prio+%d"
-          " WHERE hash='%s'"
-          " AND value='%s'",
-          delta,
-          escapedHash,
-          escapedBlock);
-  mysql_query(dbh->dbf,
-             scratch);
-  FREE(scratch);
-  FREE(escapedHash);
-  FREE(escapedBlock);
-  if (mysql_error(dbh->dbf)[0]) {
-    LOG_MYSQL(LOG_ERROR, "mysql_query", dbh);
+  if (mysql_stmt_execute(dbh->update)) {
+    LOG(LOG_ERROR,
+       _("`%s' failed at %s:%d with error: %s\n"),
+       "mysql_stmt_execute",
+       __FILE__, __LINE__,
+       mysql_stmt_error(dbh->update));
     MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
     return SYSERR;
   }
-
   MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
   return OK;
 }
@@ -1123,14 +1135,7 @@
   MUTEX_UNLOCK(&dbh->DATABASE_Lock_);
 
   bytesUsed = rowsInTable * avgRowLen;
-
-#if DEBUG_MYSQL
-  LOG(LOG_DEBUG,
-      "estimateContentAvailable (q=%d)\n",
-      kbUsed);
-#endif
-
-  return(bytesUsed);
+  return bytesUsed;
 }
 
 /**

Modified: GNUnet/src/applications/sqstore_mysql/mysqltest.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysqltest.c   2005-08-22 06:43:58 UTC 
(rev 1851)
+++ GNUnet/src/applications/sqstore_mysql/mysqltest.c   2005-08-22 07:28:18 UTC 
(rev 1852)
@@ -251,6 +251,12 @@
     errexit(_("Could not initialize libgnunetutil!\n"));
   initCore();
   api = requestService("sqstore");
+  if (api == NULL) {
+    BREAK();
+    doneCore();
+    doneUtil();
+    return 1;
+  }
   ok = SYSERR;
   if (api != NULL) {
     api->drop();
@@ -259,6 +265,8 @@
     if (api != NULL) {
       ok = test(api);
       releaseService(api);
+    } else {
+      BREAK();
     }
   }
   doneCore();





reply via email to

[Prev in Thread] Current Thread [Next in Thread]