code icon indicating copy to clipboard operation
code copied to clipboard

ch7: actionkv v2.0 does not resolve the problem in actionkv v1.0

Open yamoridon opened this issue 3 years ago • 6 comments

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.

yamoridon avatar Aug 17 '22 09:08 yamoridon

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.

brunojppb avatar Jan 28 '23 15:01 brunojppb

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 avatar Jan 30 '23 08:01 timClicks

@timClicks do you accept PRs to fix this type of issues? I would be happy to help.

anBertoli avatar Feb 16 '23 18:02 anBertoli

Why does the store_index_on_disk removing the self.index ? a.index = std::collections::HashMap::new(); I dont get it

ladislaff93 avatar Nov 07 '23 18:11 ladislaff93

  • 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 HashMaps in this section, maybe extending the ActionKV#load method to prune the index of empty value entries (as created the by the "delete" command) could serve as a case study.

xitep avatar Dec 15 '23 14:12 xitep

  • 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 HashMaps in this section, maybe extending the ActionKV#load method 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

ladislaff93 avatar Apr 04 '24 19:04 ladislaff93