Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

irmin-pack: initial integration of lower into store api #2188

Merged
merged 6 commits into from
Feb 20, 2023

Conversation

metanivek
Copy link
Member

@metanivek metanivek commented Feb 10, 2023

This PR does a few things to integrate the lower module into the higher level store code:

  • creates the lower root path if needed
  • loads the lower when opening/creating a store, if a lower is configured
  • creates an empty volume when creating a store, if a lower is configured
  • adds an add_volume function to the store api
  • adds a few tests to exercise the above

There are some TODOs for subsequent PRs:

  • to properly support fresh, we need to recursively delete the lower root's volumes
  • should we return an error when add_volume is called and no lower exists?
  • there is a placeholder for a future test when we have proper control file writing for volumes

(Note: this PR is based on #2184 so skip the first couple of commits if reviewing before it is merged)

@codecov-commenter
Copy link

Codecov Report

Merging #2188 (49adc03) into main (e68f6a7) will increase coverage by 0.04%.
The diff coverage is 77.96%.

❗ Current head 49adc03 differs from pull request most recent head 817dfd7. Consider uploading reports for the commit 817dfd7 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #2188      +/-   ##
==========================================
+ Coverage   68.09%   68.13%   +0.04%     
==========================================
  Files         135      135              
  Lines       16222    16294      +72     
==========================================
+ Hits        11046    11102      +56     
- Misses       5176     5192      +16     
Impacted Files Coverage Δ
src/irmin-pack/unix/errors.ml 28.88% <ø> (ø)
src/irmin-pack/unix/io_errors.ml 58.33% <ø> (ø)
src/irmin-pack/version.ml 44.82% <20.00%> (+0.38%) ⬆️
src/irmin-pack/unix/store.ml 63.81% <50.00%> (+0.42%) ⬆️
src/irmin-pack/unix/file_manager.ml 82.89% <70.00%> (-1.23%) ⬇️
src/irmin-pack/unix/control_file.ml 91.52% <91.80%> (+1.20%) ⬆️
src/irmin-pack/unix/control_file_intf.ml 95.45% <100.00%> (-4.55%) ⬇️
src/irmin-fs/unix/irmin_fs_unix.ml 67.74% <0.00%> (-0.65%) ⬇️
src/irmin-test/store.ml 94.89% <0.00%> (-0.06%) ⬇️
... and 1 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@adatario adatario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! It's nice seeing how the ideas are falling into place.

Interface changes look good, general logic also. Don't have a strong opinion on new error types, maybe somebody with more experience dealing with errors can provide their opinion.

Two minor comments.

src/irmin-pack/unix/file_manager.ml Outdated Show resolved Hide resolved
src/irmin-pack/unix/file_manager.ml Show resolved Hide resolved
Copy link
Member

@Firobe Firobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@metanivek
Copy link
Member Author

@adatario just a few thoughts on errors...

This is the first time I'm adding several new errors to our existing setup. For now, I'm trying to follow prior conventions, but I too am wondering what the best approach is. I think there is some balance between specificity and general, between an error for each case and Msg of string 😄, so welcome any and all feedback/thoughts!

To my knowledge, none of these errors leak outside of irmin-pack since we either raise them as exceptions (Errs.raise_if_error, Errs.raise_error) or map them to some generic Msg of string (in Gc). This means we have room to change them how we see fit since there little to no external "API" that could break by doing so.

Here are two guiding principles when I'm thinking about errors:

  1. Errors help us document meaningfully different error scenarios -- they are a communication tool for us as we work on the code
  2. Errors contain information to help pinpoint and debug an issue if it is printed by a client of irmin-pack (like octez) -- they are a communication tool for us as we debug issues

@@ -786,6 +835,11 @@ struct
pl.chunk_start_idx pl.chunk_num];
Control.set_payload t.control pl

let add_volume t =
match t.lower with
| None -> Ok () (* TODO: throw exception? *)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any opinions on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok not throw an exception and just continue irmin-pack'ing along.

I'd suggest adding a docstring in the File_manager interface specifying that if there is no lower setup than the add_volume call is a nop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add a log message indicating that add_volume was called without a lower being conigured.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest adding a docstring in the File_manager interface specifying that if there is no lower setup than the add_volume call is a nop.

Correction: this should go in the store_intf.mli.

Copy link
Member Author

@metanivek metanivek Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for weighing in!

Usually I would agree that making this a no-op would be okay, but after thinking about this some more, I think it might be best to return an error to provide a clear signal to a client that something is likely wrong. It seems not ideal if a client calls this and thinks the operation succeeds but in reality they have not configured their store correctly. This would also be symmetrical with a call to GC failing when it is given the Archive action but no lower exists (not implemented yet but is the expected outcome).

I'll leave this as-is for the PR but follow up in a subsequent PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, especially since the function can already return an Error!

Comment on lines +535 to +536
(* TODO: if [volume_num] is 0, we need to migrate
(or return error if [no_migrate = true]) *)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up @art-w @Firobe I think this is a spot that will trigger migration.

@adatario
Copy link
Contributor

@adatario just a few thoughts on errors...

Thanks! That makes sense.

@metanivek metanivek merged commit 84dcea5 into mirage:main Feb 20, 2023
@metanivek metanivek deleted the load_lower branch February 20, 2023 18:46
Firobe added a commit that referenced this pull request Feb 20, 2023
Firobe added a commit that referenced this pull request Feb 20, 2023
metanivek added a commit to metanivek/opam-repository that referenced this pull request Apr 21, 2023
…min-pack, irmin-pack-tools, irmin-mirage, irmin-mirage-graphql, irmin-mirage-git, irmin-http, irmin-graphql, irmin-git, irmin-fs, irmin-containers, irmin-cli, irmin-chunk and irmin-bench (3.7.0)

CHANGES:

### Added

- **irmin**
  - Add `Conf.pp` and `Conf.equal` to print and compare configuration values
    (mirage/irmin#2227, @samoht)
  - Add a `clear` optional arguments to all function that adds a new commit:
    `Commit.v`, `set`, `set_tree`, `remove`, `test_and_set`,
    `test_and_set_tree`, `test_set_and_get`, `test_set_and_get_tree`, `merge`,
    `merge_tree` and `with_tree`. This new argument allows to control whether
    the tree caches are cleared up after objects are exported to disk during
    the commit. (mirage/irmin#2225, @samoht)

- **irmin-pack**
  - Add configuration option, `lower_root`, to specify a path for archiving data
    during a GC. (mirage/irmin#2177, @metanivek)
  - Add `is_split_allowed` to check if a store allows split. (mirage/irmin#2175, @metanivek)
  - Add `add_volume` to allow creating new empty volume in lower layer. (mirage/irmin#2188,
    @metanivek)
  - Add a `behaviour` function to the GC to check wether the GC will archive or
    delete data. (mirage/irmin#2190, @Firobe)
  - Add a migration on `open_rw` to move the data to the `lower_root` if
    the configuration was enabled (mirage/irmin#2205, @art-w)

### Changed

- **irmin**
  - Expose type equality for `Schema.Info` to avoid defining the `info` function
    multiple times when using similar stores (mirage/irmin#2189, mirage/irmin#2193, @samoht)
- **irmin-pack**
  - GC now changes its behaviour depending on the presence of a lower layer.
    (mirage/irmin#2190, @Firobe)
  - Split now raises an exception if it is not allowed. It is not allowed on
    stores that do not allow GC. (mirage/irmin#2175, @metanivek)
  - GC now supports stores imported V1/V2 stores, in presence of a lower layer
    only. (mirage/irmin#2190, @art-w, @Firobe)
  - Upgrade on-disk format to version 5. (mirage/irmin#2184, @metanivek)
  - Archive to lower volume does not copy orphaned commits. (mirage/irmin#2215, @art-w)

### Fixed
- **irmin-pack**
  - Unhandled exceptions in GC worker process are now reported as a failure
    (mirage/irmin#2163, @metanivek)
  - Fix the silent mode for the integrity checks. (mirage/irmin#2179, @icristescu)
  - Fix file descriptor leak caused by `mmap`. (mirage/irmin#2232, @art-w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants