[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] New force-delete option on consensus_cache_delete_pending()
commit 920475f293a8a69dd846cd06249b4b699857a3d4
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Wed Apr 26 10:13:25 2017 -0400
New force-delete option on consensus_cache_delete_pending()
If we're out of file space in the storage directory, we'll need to
get rid of old files fast.
---
src/or/conscache.c | 16 +++++++++-------
src/or/conscache.h | 3 ++-
src/or/consdiffmgr.c | 2 +-
src/test/test_conscache.c | 2 +-
4 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/or/conscache.c b/src/or/conscache.c
index 2544f56..7760d13 100644
--- a/src/or/conscache.c
+++ b/src/or/conscache.c
@@ -95,7 +95,7 @@ consensus_cache_register_with_sandbox(consensus_cache_t *cache,
static void
consensus_cache_clear(consensus_cache_t *cache)
{
- consensus_cache_delete_pending(cache);
+ consensus_cache_delete_pending(cache, 0);
SMARTLIST_FOREACH_BEGIN(cache->entries, consensus_cache_entry_t *, ent) {
ent->in_cache = NULL;
@@ -401,17 +401,19 @@ consensus_cache_unmap_lazy(consensus_cache_t *cache, time_t cutoff)
/**
* Delete every element of <b>cache</b> has been marked with
- * consensus_cache_entry_mark_for_removal, and which is not in use except by
- * the cache.
+ * consensus_cache_entry_mark_for_removal. If <b>force</b> is false,
+ * retain those entries which are not in use except by the cache.
*/
void
-consensus_cache_delete_pending(consensus_cache_t *cache)
+consensus_cache_delete_pending(consensus_cache_t *cache, int force)
{
SMARTLIST_FOREACH_BEGIN(cache->entries, consensus_cache_entry_t *, ent) {
tor_assert_nonfatal(ent->in_cache == cache);
- if (ent->refcnt > 1 || BUG(ent->in_cache == NULL)) {
- /* Somebody is using this entry right now */
- continue;
+ if (! force) {
+ if (ent->refcnt > 1 || BUG(ent->in_cache == NULL)) {
+ /* Somebody is using this entry right now */
+ continue;
+ }
}
if (ent->can_remove == 0) {
/* Don't want to delete this. */
diff --git a/src/or/conscache.h b/src/or/conscache.h
index f3110e2..ea27733 100644
--- a/src/or/conscache.h
+++ b/src/or/conscache.h
@@ -17,7 +17,8 @@ struct sandbox_cfg_elem;
int consensus_cache_register_with_sandbox(consensus_cache_t *cache,
struct sandbox_cfg_elem **cfg);
void consensus_cache_unmap_lazy(consensus_cache_t *cache, time_t cutoff);
-void consensus_cache_delete_pending(consensus_cache_t *cache);
+void consensus_cache_delete_pending(consensus_cache_t *cache,
+ int force);
consensus_cache_entry_t *consensus_cache_add(consensus_cache_t *cache,
const config_line_t *labels,
const uint8_t *data,
diff --git a/src/or/consdiffmgr.c b/src/or/consdiffmgr.c
index fb09d21..1f3915f 100644
--- a/src/or/consdiffmgr.c
+++ b/src/or/consdiffmgr.c
@@ -614,7 +614,7 @@ consdiffmgr_cleanup(void)
smartlist_free(diffs);
// Actually remove files, if they're not used.
- consensus_cache_delete_pending(cdm_cache_get());
+ consensus_cache_delete_pending(cdm_cache_get(), 0);
return n_to_delete;
}
diff --git a/src/test/test_conscache.c b/src/test/test_conscache.c
index c316411..aee1ba8 100644
--- a/src/test/test_conscache.c
+++ b/src/test/test_conscache.c
@@ -203,7 +203,7 @@ test_conscache_cleanup(void *arg)
tt_assert(e_tmp == NULL); // not found because pending deletion.
/* Delete the pending-deletion items. */
- consensus_cache_delete_pending(cache);
+ consensus_cache_delete_pending(cache, 0);
{
smartlist_t *entries = smartlist_new();
consensus_cache_find_all(entries, cache, NULL, NULL);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits