diff --git a/src/enums.h b/src/enums.h index 4f724746b..72404b4ce 100644 --- a/src/enums.h +++ b/src/enums.h @@ -164,6 +164,7 @@ enum events { RERESOLVE_HOSTNAMES_FORCE, REIMPORT_ALIASCLIENTS, PARSE_NEIGHBOR_CACHE, + SEARCH_LOOKUP_HASH_COLLISIONS, EVENTS_MAX } __attribute__ ((packed)); diff --git a/src/events.c b/src/events.c index ac0c778a2..77ee1a1c4 100644 --- a/src/events.c +++ b/src/events.c @@ -98,6 +98,8 @@ static const char *eventtext(const enum events event) return "PARSE_NEIGHBOR_CACHE"; case RESOLVE_NEW_HOSTNAMES: return "RESOLVE_NEW_HOSTNAMES"; + case SEARCH_LOOKUP_HASH_COLLISIONS: + return "SEARCH_LOOKUP_HASH_COLLISIONS"; case EVENTS_MAX: // fall through default: return "UNKNOWN"; diff --git a/src/gc.c b/src/gc.c index a310d4ecc..59dacd3e2 100644 --- a/src/gc.c +++ b/src/gc.c @@ -34,6 +34,8 @@ #include "config/inotify.h" // lookup_remove() #include "lookup-table.h" +// get_and_clear_event() +#include "events.h" // Resource checking interval // default: 300 seconds @@ -474,9 +476,6 @@ void runGC(const time_t now, time_t *lastGCrun, const bool flush) if(!flush) unlock_shm(); - if(config.debug.gc.v.b) - lookup_find_hash_collisions(flush); - // After storing data in the database for the next time, // we should scan for old entries, which will then be deleted // to free up pages in the database and prevent it from growing @@ -587,6 +586,18 @@ void *GC_thread(void *val) reset_qps(now); unlock_shm(); + // Intermediate cancellation-point + if(killed) + break; + + // Check if we need to search for hash collisions + if(get_and_clear_event(SEARCH_LOOKUP_HASH_COLLISIONS)) + { + lock_shm(); + lookup_find_hash_collisions(); + unlock_shm(); + } + // Intermediate cancellation-point if(killed) break; diff --git a/src/lookup-table.c b/src/lookup-table.c index 1c6a7347b..230da0322 100644 --- a/src/lookup-table.c +++ b/src/lookup-table.c @@ -441,16 +441,10 @@ static void lookup_find_hash_collisions_table(const enum memory_type type) /** * @brief Searches for hash collisions in various lookup tables. * - * @param has_lock Whether the shared memory lock is already held. - * If the lock is not held, it will be acquired and released by this function. - * * @return void */ -void lookup_find_hash_collisions(const bool has_lock) +void lookup_find_hash_collisions(void) { - if(!has_lock) - lock_shm(); - // Search for hash collisions in the clients lookup table lookup_find_hash_collisions_table(CLIENTS_LOOKUP); @@ -459,7 +453,4 @@ void lookup_find_hash_collisions(const bool has_lock) // Search for hash collisions in the DNS cache lookup table lookup_find_hash_collisions_table(DNS_CACHE_LOOKUP); - - if(!has_lock) - unlock_shm(); } \ No newline at end of file diff --git a/src/lookup-table.h b/src/lookup-table.h index 659a3a290..cb9df6346 100644 --- a/src/lookup-table.h +++ b/src/lookup-table.h @@ -47,6 +47,6 @@ bool lookup_remove(const enum memory_type type, const unsigned int id, const uin bool lookup_find_id(const enum memory_type type, const uint32_t hash, const struct lookup_data *lookup_data, unsigned int *matchingID, bool (*cmp_func)(const struct lookup_table *entry, const struct lookup_data *lookup_data)); -void lookup_find_hash_collisions(const bool has_lock); +void lookup_find_hash_collisions(void); #endif //LOOKUP_TABLE_H diff --git a/src/signals.c b/src/signals.c index 01e21246f..d02c81ef3 100644 --- a/src/signals.c +++ b/src/signals.c @@ -327,7 +327,7 @@ static void SIGRT_handler(int signum, siginfo_t *si, void *unused) else if(rtsig == 7) { // Search for hash collisions in the lookup tables - lookup_find_hash_collisions(); + set_event(SEARCH_LOOKUP_HASH_COLLISIONS); } // SIGRT32: Used internally by valgrind, do not use