#endif /* not NDEBUG */
const char *
-btrie_stats(const struct btrie *btrie)
+btrie_stats(const struct btrie *btrie, guint duplicates)
{
static char buf[128];
size_t n_nodes = btrie->n_lc_nodes + btrie->n_tbm_nodes;
, average_depth, (long unsigned)stats.max_depth);
#else
snprintf(buf, sizeof(buf),
- "ents=%lu tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu"
- ,(long unsigned)btrie->n_entries, (long unsigned)btrie->n_tbm_nodes,
+ "ents=%lu dup=%u tbm=%lu lc=%lu mem=%.0fk free=%lu waste=%lu",
+ (long unsigned)btrie->n_entries,
+ duplicates,
+ (long unsigned)btrie->n_tbm_nodes,
(long unsigned)btrie->n_lc_nodes, (double)btrie->alloc_total / 1024,
(long unsigned)alloc_free, (long unsigned)btrie->alloc_waste
);
rspamd_mempool_t *pool;
struct btrie *tree;
size_t size;
+ guint duplicates;
gboolean own_pool;
};
gsize masklen,
uintptr_t value)
{
+ static const guint max_duplicates = 32;
guint keybits = keylen * NBBY;
uintptr_t old;
gchar ip_str[INET6_ADDRSTRLEN + 1];
(gconstpointer)value);
if (ret != BTRIE_OKAY) {
- memset (ip_str, 0, sizeof (ip_str));
+ tree->duplicates++;
- if (keybits == 32) {
- msg_err_radix ("cannot insert %p, key: %s/%d, duplicate value",
- (gpointer)value,
- inet_ntop (AF_INET, key, ip_str, sizeof (ip_str) - 1),
- (gint)(keybits - masklen));
+ if (tree->duplicates == max_duplicates) {
+ msg_err_radix ("maximum duplicates limit reached: %d, "
+ "suppress further errors", max_duplicates);
}
- else if (keybits == 128) {
- msg_err_radix ("cannot insert %p, key: [%s]/%d, duplicate value",
- (gpointer)value,
- inet_ntop (AF_INET6, key, ip_str, sizeof (ip_str) - 1),
- (gint)(keybits - masklen));
- }
- else {
- msg_err_radix ("cannot insert %p with mask %z, key: %*xs, duplicate value",
- (gpointer)value, keybits - masklen, (int)keylen, key);
+ else if (tree->duplicates < max_duplicates) {
+ memset (ip_str, 0, sizeof (ip_str));
+
+ if (keybits == 32) {
+ msg_err_radix ("cannot insert %p, key: %s/%d, duplicate value",
+ (gpointer) value,
+ inet_ntop (AF_INET, key, ip_str, sizeof (ip_str) - 1),
+ (gint) (keybits - masklen));
+ } else if (keybits == 128) {
+ msg_err_radix ("cannot insert %p, key: [%s]/%d, duplicate value",
+ (gpointer) value,
+ inet_ntop (AF_INET6, key, ip_str, sizeof (ip_str) - 1),
+ (gint) (keybits - masklen));
+ } else {
+ msg_err_radix ("cannot insert %p with mask %z, key: %*xs, duplicate value",
+ (gpointer) value, keybits - masklen, (int) keylen, key);
+ }
}
}
else {
tree->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
tree->size = 0;
+ tree->duplicates = 0;
tree->tree = btrie_init (tree->pool);
tree->own_pool = TRUE;
tree = rspamd_mempool_alloc (pool, sizeof (*tree));
tree->pool = pool;
tree->size = 0;
+ tree->duplicates = 0;
tree->tree = btrie_init (tree->pool);
tree->own_pool = FALSE;
return NULL;
}
- return btrie_stats (tree->tree);
+ return btrie_stats (tree->tree, tree->duplicates);
}