estraier / tkrzw

a set of implementations of DBM
Apache License 2.0
164 stars 20 forks source link

QA: Dynamic buckets number #15

Closed tieugene closed 3 years ago

tieugene commented 3 years ago

The number of hash buckets is set when the database is created

Is there a possibility to increase buckets number on-the-fly?

estraier commented 3 years ago

Calling the Rebuild method does the job. It reconstructs the whole database at the current thread while accepting search/update operations at other threads.

estraier commented 3 years ago

BTW, If you mean algorithms like dynamic hashing, the answer is no. Tkrzw is optimized for multi-threading. However implementing dynamic hashing without blocking the entire database is hard. Based on my experience, static hashing and rebuilding the database concurrently is more practical.

Of course, single thread applications can rebuild the database if the operation can block for a while. The API includes ShouldBeRebuilt method, which tells you whether the database should be rebuilt, by considering the load factor of the hash table. https://dbmx.net/tkrzw/api/classtkrzw_1_1DBM.html#a353a1c425c3a47c872eff15f84134abc

while (true) { dbm.Set(...); // Do your job step by step if (dbm.ShouldBeRebuilt()) { // Rebuild the DB if necessary dbm.Rebuild(); } }

tieugene commented 3 years ago

Ok, I understand - "no by design"