Skip to content

Commit

Permalink
Add new SEARCH_LOOKUP_HASH_COLLISIONS event
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Oct 18, 2024
1 parent 97ddf8b commit 790bb53
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ enum events {
RERESOLVE_HOSTNAMES_FORCE,
REIMPORT_ALIASCLIENTS,
PARSE_NEIGHBOR_CACHE,
SEARCH_LOOKUP_HASH_COLLISIONS,
EVENTS_MAX
} __attribute__ ((packed));

Expand Down
2 changes: 2 additions & 0 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
17 changes: 14 additions & 3 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 1 addition & 10 deletions src/lookup-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
}
2 changes: 1 addition & 1 deletion src/lookup-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 790bb53

Please sign in to comment.