gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: -fix datacache to return 2x num_closest


From: gnunet
Subject: [gnunet] branch master updated: -fix datacache to return 2x num_closest in both directions
Date: Wed, 23 Feb 2022 00:30:39 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 0209b47ae -fix datacache to return 2x num_closest in both directions
0209b47ae is described below

commit 0209b47aeddf61686fe08e946d8909860cfb161a
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Feb 23 00:30:36 2022 +0100

    -fix datacache to return 2x num_closest in both directions
---
 src/datacache/plugin_datacache_heap.c     | 16 +++++++++-------
 src/datacache/plugin_datacache_postgres.c | 12 +++++++++---
 src/datacache/plugin_datacache_sqlite.c   | 12 ++++++++++--
 src/dht/gnunet-service-dht_datacache.c    |  2 +-
 src/include/gnunet_datacache_plugin.h     | 11 ++++++-----
 5 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/src/datacache/plugin_datacache_heap.c 
b/src/datacache/plugin_datacache_heap.c
index 09e66d892..5b50468a5 100644
--- a/src/datacache/plugin_datacache_heap.c
+++ b/src/datacache/plugin_datacache_heap.c
@@ -427,15 +427,16 @@ struct GetClosestContext
 {
   struct Value **values;
 
+  const struct GNUNET_HashCode *key;
+
   enum GNUNET_BLOCK_Type type;
 
   unsigned int num_results;
 
-  const struct GNUNET_HashCode *key;
 };
 
 
-static int
+static enum GNUNET_GenericReturnValue
 find_closest (void *cls,
               const struct GNUNET_HashCode *key,
               void *value)
@@ -458,8 +459,9 @@ find_closest (void *cls,
       j = i;
       break;
     }
-    if (1 == GNUNET_CRYPTO_hash_cmp (&gcc->values[i]->key,
-                                     key))
+    if (1 ==
+        GNUNET_CRYPTO_hash_cmp (&gcc->values[i]->key,
+                                key))
     {
       j = i;
       break;
@@ -499,14 +501,14 @@ heap_plugin_get_closest (void *cls,
   struct GetClosestContext gcc = {
     .values = values,
     .type = type,
-    .num_results = num_results,
+    .num_results = num_results * 2,
     .key = key
   };
 
   GNUNET_CONTAINER_multihashmap_iterate (plugin->map,
                                          &find_closest,
                                          &gcc);
-  for (unsigned int i = 0; i < num_results; i++)
+  for (unsigned int i = 0; i < num_results * 2; i++)
   {
     if (NULL == values[i])
       return i;
@@ -519,7 +521,7 @@ heap_plugin_get_closest (void *cls,
           values[i]->path_info_len,
           values[i]->path_info);
   }
-  return num_results;
+  return num_results * 2;
 }
 
 
diff --git a/src/datacache/plugin_datacache_postgres.c 
b/src/datacache/plugin_datacache_postgres.c
index 4e48d89df..1a83cda86 100644
--- a/src/datacache/plugin_datacache_postgres.c
+++ b/src/datacache/plugin_datacache_postgres.c
@@ -108,14 +108,20 @@ init_connection (struct Plugin *plugin)
                             "SELECT length(value) AS len,oid,key FROM gn011dc"
                             " ORDER BY prox ASC, discard_time ASC LIMIT 1",
                             0),
-    /* FIXME: do key >= ASC +  UNION key <=  DESC! */
     GNUNET_PQ_make_prepare ("get_closest",
-                            "SELECT discard_time,type,value,path,key FROM 
gn011dc"
+                            "(SELECT discard_time,type,value,path,key FROM 
gn011dc"
                             " WHERE key >= $1"
                             "   AND discard_time >= $2"
                             "   AND ( (type = $3) OR ( 0 = $3) )"
                             " ORDER BY key ASC"
-                            " LIMIT $4",
+                            " LIMIT $4)"
+                            " UNION "
+                            "(SELECT discard_time,type,value,path,key FROM 
gn011dc"
+                            " WHERE key <= $1"
+                            "   AND discard_time >= $2"
+                            "   AND ( (type = $3) OR ( 0 = $3) )"
+                            " ORDER BY key DESC"
+                            " LIMIT $4)",
                             4),
     GNUNET_PQ_make_prepare ("delrow",
                             "DELETE FROM gn011dc WHERE oid=$1",
diff --git a/src/datacache/plugin_datacache_sqlite.c 
b/src/datacache/plugin_datacache_sqlite.c
index 46ff66dce..e5ee3e5a8 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -651,11 +651,19 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
                                 &plugin->del_stmt)) ||
       (SQLITE_OK !=
        sq_prepare (plugin->dbh,
-                   "SELECT value,expire,path,type,key FROM ds091 "
+                   "SELECT * FROM ("
+                   " SELECT value,expire,path,type,key FROM ds091 "
                    " WHERE key>=?1 "
                    "  AND expire >= ?2"
                    "  AND ( (type=?3) or (0 == ?3) )"
-                   " ORDER BY KEY ASC LIMIT ?4",
+                   " ORDER BY KEY ASC LIMIT ?4)"
+                   "UNION "
+                   "SELECT * FROM ("
+                   " SELECT value,expire,path,type,key FROM ds091 "
+                   " WHERE key>=?1 "
+                   "  AND expire >= ?2"
+                   "  AND ( (type=?3) or (0 == ?3) )"
+                   " ORDER BY KEY ASC LIMIT ?4)",
                    &plugin->get_closest_stmt)))
   {
     LOG_SQLITE (plugin->dbh,
diff --git a/src/dht/gnunet-service-dht_datacache.c 
b/src/dht/gnunet-service-dht_datacache.c
index 880c72cb2..91bdfe3da 100644
--- a/src/dht/gnunet-service-dht_datacache.c
+++ b/src/dht/gnunet-service-dht_datacache.c
@@ -36,7 +36,7 @@
  * How many "closest" results to we return for migration when
  * asked (at most)?
  */
-#define NUM_CLOSEST 42
+#define NUM_CLOSEST 4
 
 
 /**
diff --git a/src/include/gnunet_datacache_plugin.h 
b/src/include/gnunet_datacache_plugin.h
index 914aaf15c..34bf5f277 100644
--- a/src/include/gnunet_datacache_plugin.h
+++ b/src/include/gnunet_datacache_plugin.h
@@ -158,15 +158,16 @@ struct GNUNET_DATACACHE_PluginFunctions
 
 
   /**
-   * Iterate over the results that are "close" to a particular key in
-   * the datacache.  "close" is defined as numerically larger than @a
-   * key (when interpreted as a circular address space), with small
-   * distance.
+   * Iterate over the results that are "close" to a particular key in the
+   * datacache.  "close" is defined as returning the @a num_results that are
+   * numerically closest and larger than @a key and also @a num_results that
+   * are numerically lower than @a key. Thus, the maximum number of results
+   * returned is actually twice @a num_results.
    *
    * @param cls closure (internal context for the plugin)
    * @param key area of the keyspace to look into
    * @param type desired block type for the replies
-   * @param num_results number of results that should be returned to @a iter
+   * @param num_results half the number of results that should be returned to 
@a iter
    * @param iter maybe NULL (to just count)
    * @param iter_cls closure for @a iter
    * @return the number of results found

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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