mirage / irmin

Irmin is a distributed database that follows the same design principles as Git
https://irmin.org
ISC License
1.83k stars 154 forks source link

invalid checksum when using irmin-pack #2269

Open joprice opened 1 year ago

joprice commented 1 year ago

I have a small test of irmin using the git backend, which works perfectly on its own. I wanted to experiment with irmin-pack and added it as a dependency, and found that the original git backend example started to fail with an invalid checksum error.

let make ~token ~url =
  let open Lwt_result.Syntax in
  let* repo = Store.Repo.v config |> Lwt_result.ok in
  let* store = Store.main repo |> Lwt_result.ok in
  let headers =
    let e = Cohttp.Header.of_list [] in
    Cohttp.Header.add_authorization e (`Basic ("oauth2", token))
  in
  let* remote = Store.remote ~headers url |> Lwt_result.ok in
  let+ _status =
    Lwt_result.ok
    @@
    Sync.pull_exn store remote `Set
    |> Lwt_result.map_error (fun e -> Fmt.to_to_string Sync.pp_pull_error e)

Fatal error: exception Invalid_argument("Sync.pull_exn: object <0000000e>: Invalid checksum (expect:2ed549da, has:0000)")
Raised at Lwt.Miscellaneous.poll in file "src/core/lwt.ml", line 3123, characters 20-29
Called from Lwt_main.run.run_loop in file "src/unix/lwt_main.ml", line 27, characters 10-20
Called from Lwt_main.run in file "src/unix/lwt_main.ml", line 106, characters 8-13
Re-raised at Lwt_main.run in file "src/unix/lwt_main.ml", line 112, characters 4-13
Called from Dune__exe__Main.sync_repo in file "server/main.ml", line 76, characters 2-20```
metanivek commented 1 year ago

Thanks for the report. Is the setup that you have an irmin-git remote store that you are trying to sync to an irmin-pack local store? I tried to modify the existing sync example to have this sort of setup but get the following:

# dune exec examples/irmin-pack/git_sync.exe
Fatal error: exception Invalid_argument("Sync.pull_exn: fetch operation is not available")
Raised at Lwt.Miscellaneous.poll in file "src/core/lwt.ml", line 3077, characters 20-29
Called from Lwt_main.run.run_loop in file "src/unix/lwt_main.ml", line 31, characters 10-20
Called from Lwt_main.run in file "src/unix/lwt_main.ml", line 118, characters 8-13
Re-raised at Lwt_main.run in file "src/unix/lwt_main.ml", line 124, characters 4-13
Called from Dune__exe__Git_sync in file "examples/irmin-pack/git_sync.ml", line 82, characters 9-31

You can see my hacked together example in this gist: https://gist.github.com/metanivek/2e59fe6971d5ce2ab1d42fc9eaf23ca7

Could you share a full example that compiles and fails? That would make it easier to see what is happening.

Off the top of my head, I'm not sure this sort of cross backend syncing will work (and as the above output indicates, irmin-pack does not currently implement remote syncing -- see this line), but I'm happy to look more into this for you.