aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-11-03 17:09:04 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-11-03 17:09:04 +0300
commit0825c58337d3fd8f766eaf0a77961bbe3ec09c35 (patch)
tree8161a49467900c6d8a580edde7519ae0f3a76535 /src
parent5419087e8314be3e96bce4a7cdc0ad1c506d09f2 (diff)
downloadrspamd-0825c58337d3fd8f766eaf0a77961bbe3ec09c35.tar.gz
rspamd-0825c58337d3fd8f766eaf0a77961bbe3ec09c35.zip
Do not free elements that are still in cache.
Diffstat (limited to 'src')
-rw-r--r--src/kvstorage.c29
-rw-r--r--src/kvstorage.h2
2 files changed, 31 insertions, 0 deletions
diff --git a/src/kvstorage.c b/src/kvstorage.c
index 41b787dc5..f5b314e29 100644
--- a/src/kvstorage.c
+++ b/src/kvstorage.c
@@ -160,6 +160,7 @@ rspamd_kv_storage_insert (struct rspamd_kv_storage *storage, gpointer key,
/* First try to search it in cache */
elt = storage->cache->lookup_func (storage->cache, key);
if (elt) {
+ storage->cache->steal_func (storage->cache, elt);
if (elt->flags & KV_ELT_DIRTY) {
/* Element is in backend storage queue */
elt->flags |= KV_ELT_NEED_FREE;
@@ -555,6 +556,7 @@ struct rspamd_kv_hash_cache {
cache_replace replace_func; /*< this callback is called when element is replace */
cache_lookup lookup_func; /*< this callback is used for lookup of element */
cache_delete delete_func; /*< this callback is called when an element is deleted */
+ cache_steal steal_func; /*< this callback is used to replace duplicates in cache */
cache_destroy destroy_func; /*< this callback is used for destroying all elements inside cache */
GHashTable *hash;
};
@@ -625,6 +627,17 @@ rspamd_kv_hash_delete (struct rspamd_kv_cache *c, gpointer key)
}
/**
+ * Steal an element from cache
+ */
+static void
+rspamd_kv_hash_steal (struct rspamd_kv_cache *c, struct rspamd_kv_element *elt)
+{
+ struct rspamd_kv_hash_cache *cache = (struct rspamd_kv_hash_cache *)c;
+
+ g_hash_table_steal (cache->hash, ELT_KEY (elt));
+}
+
+/**
* Destroy the whole cache
*/
static void
@@ -661,6 +674,7 @@ rspamd_kv_hash_new (void)
new->lookup_func = rspamd_kv_hash_lookup;
new->replace_func = rspamd_kv_hash_replace;
new->delete_func = rspamd_kv_hash_delete;
+ new->steal_func = rspamd_kv_hash_steal;
new->destroy_func = rspamd_kv_hash_destroy;
return (struct rspamd_kv_cache *)new;
@@ -675,6 +689,7 @@ struct rspamd_kv_radix_cache {
cache_replace replace_func; /*< this callback is called when element is replace */
cache_lookup lookup_func; /*< this callback is used for lookup of element */
cache_delete delete_func; /*< this callback is called when an element is deleted */
+ cache_steal steal_func; /*< this callback is used to replace duplicates in cache */
cache_destroy destroy_func; /*< this callback is used for destroying all elements inside cache */
radix_tree_t *tree;
};
@@ -776,6 +791,19 @@ rspamd_kv_radix_delete (struct rspamd_kv_cache *c, gpointer key)
}
/**
+ * Delete an element from cache
+ */
+static void
+rspamd_kv_radix_steal (struct rspamd_kv_cache *c, struct rspamd_kv_element *elt)
+{
+ struct rspamd_kv_radix_cache *cache = (struct rspamd_kv_radix_cache *)c;
+ guint32 rkey = rspamd_kv_radix_validate (ELT_KEY (elt));
+
+
+ radix32tree_delete (cache->tree, rkey, 0xffffffff);
+}
+
+/**
* Destroy the whole cache
*/
static void
@@ -802,6 +830,7 @@ rspamd_kv_radix_new (void)
new->lookup_func = rspamd_kv_radix_lookup;
new->replace_func = rspamd_kv_radix_replace;
new->delete_func = rspamd_kv_radix_delete;
+ new->steal_func = rspamd_kv_radix_steal;
new->destroy_func = rspamd_kv_radix_destroy;
return (struct rspamd_kv_cache *)new;
diff --git a/src/kvstorage.h b/src/kvstorage.h
index ffff000db..fb5848274 100644
--- a/src/kvstorage.h
+++ b/src/kvstorage.h
@@ -38,6 +38,7 @@ typedef struct rspamd_kv_element* (*cache_insert)(struct rspamd_kv_cache *cache,
typedef gboolean (*cache_replace)(struct rspamd_kv_cache *cache, gpointer key, struct rspamd_kv_element *elt);
typedef struct rspamd_kv_element* (*cache_lookup)(struct rspamd_kv_cache *cache, gpointer key);
typedef struct rspamd_kv_element* (*cache_delete)(struct rspamd_kv_cache *cache, gpointer key);
+typedef void (*cache_steal)(struct rspamd_kv_cache *cache, struct rspamd_kv_element* elt);
typedef void (*cache_destroy)(struct rspamd_kv_cache *cache);
/* Callbacks for backend */
@@ -89,6 +90,7 @@ struct rspamd_kv_cache {
cache_replace replace_func; /*< this callback is called when element is replace */
cache_lookup lookup_func; /*< this callback is used for lookup of element */
cache_delete delete_func; /*< this callback is called when an element is deleted */
+ cache_steal steal_func; /*< this callback is used to replace duplicates in cache */
cache_destroy destroy_func; /*< this callback is used for destroying all elements inside cache */
};
struct rspamd_kv_backend {