ch7: actionkv v2.0 does not resolve the problem in actionkv v1.0
Section 7.7.11 points out a problem of actionkv v1 is that it has long start up time and describes a way to shorten it by storing the index itself on the database. But actionkv v2 still reads all of the database file and rebuilds the index. Thus the problem of actionkv v1 is not resolved. Considring the discussion of this section, I think it should be resolved.
Hey folks, I've just been through Chapter 7 and I think @yamoridon is correct. If we look at the source here, the lib.rs implementation still rebuilds the index when we call load. Here is how the source looks like:
Load call site
https://github.com/rust-in-action/code/blob/19c4349758b57bdb233e186746bfec03ad9ea88d/ch7/ch7-actionkv2/src/akv_disk.rs#L44
Inserting in the index
https://github.com/rust-in-action/code/blob/19c4349758b57bdb233e186746bfec03ad9ea88d/ch7/ch7-actionkv2/src/lib.rs#L100
I was wondering how @timClicks would approach this part. Appreciate any feedback on that.
I wondered when this would be pointed out. At one point I did implement a fix for this, but I believe that I pulled it out to simplify the v2 code example.
@timClicks do you accept PRs to fix this type of issues? I would be happy to help.
Why does the store_index_on_disk removing the self.index ? a.index = std::collections::HashMap::new(); I dont get it
- i think a less confusing approach to demonstrating the utility of de/serialization would be to store the index (as a kind of cache) in a separate file (this would utilize the the material from section 7.2.) appending the index (for each modification) to the database file itself is wasteful.
- to demonstrate some more work around
HashMapsin this section, maybe extending theActionKV#loadmethod to prune the index of empty value entries (as created the by the "delete" command) could serve as a case study.
- i think a less confusing approach to demonstrating the utility of de/serialization would be to store the index (as a kind of cache) in a separate file (this would utilize the the material from section 7.2.) appending the index (for each modification) to the database file itself is wasteful.
- to demonstrate some more work around
HashMapsin this section, maybe extending theActionKV#loadmethod to prune the index of empty value entries (as created the by the "delete" command) could serve as a case study.
That is exactly the way I did it. I made index and data files and index is rebuilded from index file