danielealbano / cachegrand

cachegrand - a modern data ingestion, processing and serving platform built for today's hardware
BSD 3-Clause "New" or "Revised" License
975 stars 34 forks source link

Implement hashtable op iter #158

Closed danielealbano closed 2 years ago

danielealbano commented 2 years ago

This PR implements a new internal operation for the hashtable that allows to iterate over the available keys and values to simplify the code that disposes the keys and the values at the shutdown but will be used as well for frontend commands that require iteration over the keys and the values.

Specifically the storage_db_free has been refactored to be more readable and splitted in logical units, one of these take advantage of the new operation to iterate over the hashtable and dispose all the entry indexes, and hashtable_mcmp_data_free uses the new function to cleanup the keys at the shutdown.

The usage pattern is really simple, the function taks the hashtable and a bucket index as pointer which value has initially be set to 0, after each invocation, if the function doesn't return null, bucket_index has to be increased otherwise the current element will be found again.

    hashtable_bucket_index_t bucket_index = 0;
    for(
            void *data = hashtable_mcmp_op_iter(db->hashtable, &bucket_index);
            data;
            ++bucket_index && (data = hashtable_mcmp_op_iter(db->hashtable, &bucket_index))) {
        storage_db_entry_index_free(db, data);
    }

The PR contains also some general style cleanups, the tests for the new command and a minor bugfix in a test for the spinlocks.

codecov[bot] commented 2 years ago

Codecov Report

Merging #158 (280807a) into main (0f2d5f7) will increase coverage by 0.24%. The diff coverage is 91.89%.

@@            Coverage Diff             @@
##             main     #158      +/-   ##
==========================================
+ Coverage   77.49%   77.74%   +0.24%     
==========================================
  Files          92       93       +1     
  Lines        6163     6186      +23     
==========================================
+ Hits         4776     4809      +33     
+ Misses       1387     1377      -10     
Impacted Files Coverage Δ
...ta_structures/hashtable/mcmp/hashtable_op_delete.c 100.00% <ø> (ø)
src/storage/db/storage_db.c 43.71% <77.77%> (-0.51%) :arrow_down:
src/data_structures/hashtable/mcmp/hashtable.c 84.00% <100.00%> (ø)
...rc/data_structures/hashtable/mcmp/hashtable_data.c 82.69% <100.00%> (+8.40%) :arrow_up:
...data_structures/hashtable/mcmp/hashtable_op_iter.c 100.00% <100.00%> (ø)
.../data_structures/hashtable/mcmp/hashtable_op_set.c 100.00% <100.00%> (ø)
...uctures/hashtable/mcmp/hashtable_support_op_arch.c 93.77% <100.00%> (+1.54%) :arrow_up:
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0f2d5f7...280807a. Read the comment docs.