Why would a writer thread need to take a lock on a trie in order to avoid inconsi


#1

Why would a writer thread need to take a lock on a trie in order to avoid inconsistent reads? As stated in other parts of the question, consistency isn't very important for this application. Writers should have exclusive access over other writers, but it should be fine for reads to occur concurrently.


#2

First of all, lock need to be there on the node level, not the trie level.
Second, Write will not require access to lock, as write will performed by INCREMENT operator(Similar to Redis). if we need to update the frequency to particular value, then we need to access exclusive write lock.
I think you are right on handling concurrency with reader threads, write don’t need to take lock on the node as the inconsistency is allowed for the read.

In short write will not affect other writes because we will have increment operator, and will not affect read as the inconsistency is allowed. Hence No locking is required at all.