bind9/lib/isc/include/isc
Ondřej Surý 50f357cb36
Refactor the dns_adb unit
The dns_adb unit has been refactored to be much simpler.  Following
changes have been made:

1. Simplify the ADB to always allow GLUE and hints

   There were only two places where dns_adb_createfind() was used - in
   the dns_resolver unit where hints and GLUE addresses were ok, and in
   the dns_zone where dns_adb_createfind() would be called without
   DNS_ADBFIND_HINTOK and DNS_ADBFIND_GLUEOK set.

   Simplify the logic by allowing hint and GLUE addresses when looking
   up the nameserver addresses to notify.  The difference is negligible
   and would cause a difference in the notified addresses only when
   there's mismatch between the parent and child addresses and we
   haven't cached the child addresses yet.

2. Drop the namebuckets and entrybuckets

   Formerly, the namebuckets and entrybuckets were used to reduced the
   lock contention when accessing the double-linked lists stored in each
   bucket.  In the previous refactoring, the custom hashtable for the
   buckets has been replaced with isc_ht/isc_hashmap, so only a single
   item (mostly, see below) would end up in each bucket.

   Removing the entrybuckets has been straightforward, the only matching
   was done on the isc_sockaddr_t member of the dns_adbentry.

   Removing the zonebuckets required GLUEOK and HINTOK bits to be
   removed because the find could match entries with-or-without the bits
   set, and creating a custom key that stores the
   DNS_ADBFIND_STARTATZONE in the first byte of the key, so we can do a
   straightforward lookup into the hashtable without traversing a list
   that contains items with different flags.

3. Remove unassociated entries from ADB database

   Previously, the adbentries could live in the ADB database even after
   unlinking them from dns_adbnames.  Such entries would show up as
   "Unassociated entries" in the ADB dump.  The benefit of keeping such
   entries is little - the chance that we link such entry to a adbname
   is small, and it's simpler to evict unlinked entries from the ADB
   cache (and the hashtable) than create second LRU cleaning mechanism.

   Unlinked ADB entries are now directly deleted from the hash
   table (hashmap) upon destruction.

4. Cleanup expired entries from the hash table

   When buckets were still in place, the code would keep the buckets
   always allocated and never shrink the hash table (hashmap).  With
   proper reference counting in place, we can delete the adbnames from
   the hash table and the LRU list.

5. Stop purging the names early when we hit the time limit

   Because the LRU list is now time ordered, we can stop purging the
   names when we find a first entry that doesn't fullfil our time-based
   eviction criteria because no further entry on the LRU list will meet
   the criteria.

Future work:

1. Lock contention

   In this commit, the focus was on correctness of the data structure,
   but in the future, the lock contention in the ADB database needs to
   be addressed.  Currently, we use simple mutex to lock the hash
   tables, because we almost always need to use a write lock for
   properly purging the hashtables.  The ADB database needs to be
   sharded (similar to the effect that buckets had in the past).  Each
   shard would contain own hashmap and own LRU list.

2. Time-based purging

   The ADB names and entries stay intact when there are no lookups.
   When we add separate shards, a timer needs to be added for time-based
   cleaning in case there's no traffic hashing to the inactive shard.

3. Revisit the 30 minutes limit

   The ADB cache is capped at 30 minutes.  This needs to be revisited,
   and at least the limit should be configurable (in both directions).
2022-11-30 10:03:24 +01:00
..
aes.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
align.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
ascii.h Add a case-insensitive option directly to siphash 2-4 implementation 2022-10-04 10:32:40 +02:00
assertions.h Replace ISC_NORETURN with C11's noreturn 2022-03-25 08:33:43 +01:00
astack.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
async.h New event loop handling API 2022-08-25 12:24:29 +02:00
atomic.h REQUIRE should not have side effects 2022-07-05 12:22:55 -07:00
attributes.h Replace ISC_NORETURN with C11's noreturn 2022-03-25 08:33:43 +01:00
backtrace.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
barrier.h Improve reporting for barrier errors 2022-07-13 13:19:32 +02:00
base32.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
base64.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
bind9.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
buffer.h change ISC__BUFFER macros to inline functions 2022-09-26 23:49:27 -07:00
cmocka.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
commandline.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
condition.h Make the pthread_rwlock implementation header-only macros [2/2] 2022-11-02 10:34:10 +01:00
counter.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
crc64.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
deprecated.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
dir.h Update clang to version 14 2022-06-16 17:21:11 +02:00
endian.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
entropy.h Switch the CSPRNG function from RAND_bytes() to uv_random() 2022-09-26 15:13:11 +02:00
errno.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
error.h Include the function name when reporting unexpected errors 2022-10-17 13:43:59 +01:00
event.h Simplify the isc_event API 2022-08-25 12:24:25 +02:00
eventclass.h Remove the isc_app API 2022-08-26 09:09:25 +02:00
file.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
formatcheck.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
fsaccess.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
fuzz.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
glob.h Update clang to version 14 2022-06-16 17:21:11 +02:00
hash.h Turn isc_hash_bits32() into static online function 2022-04-01 23:04:24 +02:00
hashmap.h Add isc_hashmap API that implements Robin Hood hashing 2022-11-10 15:07:19 +01:00
heap.h Make isc_heap_create() and isc_heap_insert() return void 2022-03-08 11:19:34 +01:00
hex.h Consolidate some ASCII tables in isc/ascii and isc/hex 2022-09-12 12:18:57 +01:00
hmac.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
ht.h Make isc_ht optionally case insensitive 2022-03-28 15:02:18 -07:00
httpd.h Rewrite isc_httpd using picohttpparser and isc_url_parse 2022-10-14 11:26:54 +02:00
interfaceiter.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
iterated_hash.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
job.h isc_async_run() runs events in reverse order 2022-10-31 05:43:45 -07:00
lang.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
lex.h Change the return type of isc_lex_create() to void 2022-10-26 12:55:06 +02:00
list.h Replace (void *)-1 with ISC_LINK_TOMBSTONE 2022-10-18 11:36:15 +02:00
log.h Update clang to version 14 2022-06-16 17:21:11 +02:00
loop.h Convert isc_ratelimiter API to use on-loop timers 2022-09-21 14:25:33 -07:00
magic.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
managers.h Update netmgr, tasks, and applications to use isc_loopmgr 2022-08-26 09:09:24 +02:00
md.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
mem.h Replace isc_mem_*_aligned(..., alignment) with isc_mem_*x(..., flags) 2022-10-05 16:44:05 +02:00
meminfo.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
mutex.h Make the pthread_rwlock implementation header-only macros [2/2] 2022-11-02 10:34:10 +01:00
mutexblock.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
net.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
netaddr.h update dlz_minimal.h 2022-01-27 15:48:50 -08:00
netdb.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
netmgr.h Cleanup the asychronous code in the stream implementations 2022-09-22 14:51:15 +02:00
netscope.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
nonce.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
offset.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
once.h Improve reporting for pthread_once errors 2022-10-14 16:39:21 +02:00
os.h Use detected cache line size 2022-01-27 13:02:23 +01:00
parseint.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
portset.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
print.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
quota.h Update clang to version 14 2022-06-16 17:21:11 +02:00
radix.h Update clang to version 14 2022-06-16 17:21:11 +02:00
random.h Make isc_random_uniform() nearly divisionless 2022-04-22 16:40:37 +01:00
ratelimiter.h Refactor isc_ratelimiter API 2022-09-30 10:36:30 +02:00
refcount.h Refactor the dns_adb unit 2022-11-30 10:03:24 +01:00
regex.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
region.h Update clang to version 14 2022-06-16 17:21:11 +02:00
resource.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
result.h Add dns_rdata_checksvcb 2022-10-29 00:22:54 +11:00
rwlock.h Make the pthread_rwlock implementation header-only macros [2/2] 2022-11-02 10:34:10 +01:00
safe.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
serial.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
signal.h New event loop handling API 2022-08-25 12:24:29 +02:00
siphash.h Add a case-insensitive option directly to siphash 2-4 implementation 2022-10-04 10:32:40 +02:00
sockaddr.h update dlz_minimal.h 2022-01-27 15:48:50 -08:00
stat.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
stats.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
stdatomic.h Remove usage of deprecated ATOMIC_VAR_INIT() macro 2022-03-08 23:55:10 +01:00
stdio.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
stdtime.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
strerr.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
string.h Use strnstr implementation from FreeBSD if not provided by OS 2022-10-04 14:21:41 +11:00
symtab.h Update clang to version 14 2022-06-16 17:21:11 +02:00
syslog.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
task.h Update netmgr, tasks, and applications to use isc_loopmgr 2022-08-26 09:09:24 +02:00
thread.h Update clang to version 14 2022-06-16 17:21:11 +02:00
tid.h New event loop handling API 2022-08-25 12:24:29 +02:00
time.h Deduplicate time unit conversion factors 2022-11-25 13:23:36 +00:00
timer.h Add isc_timer_async_destroy() helper function 2022-09-21 14:25:33 -07:00
tls.h Use custom isc_mem based allocator for OpenSSL 2022-09-27 17:10:42 +02:00
tm.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
types.h Rewrite isc_httpd using picohttpparser and isc_url_parse 2022-10-14 11:26:54 +02:00
url.h Rewrite isc_httpd using picohttpparser and isc_url_parse 2022-10-14 11:26:54 +02:00
utf8.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
util.h Include the function name when reporting unexpected errors 2022-10-17 13:43:59 +01:00
uv.h De-duplicate some calls to strerror_r() 2022-10-17 11:58:26 +01:00
work.h New event loop handling API 2022-08-25 12:24:29 +02:00
xml.h Use custom isc_mem based allocator for libxml2 2022-09-27 17:10:42 +02:00