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-(client|server): remove server-side state, simplify batch api, and cleanups #2272

Merged
merged 7 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions examples/client_batch.ml

This file was deleted.

11 changes: 2 additions & 9 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
push
custom_graphql
custom_storage
fold
client_batch
server)
fold)
(libraries
astring
cohttp
Expand All @@ -22,8 +20,6 @@
irmin-graphql.unix
irmin-pack.unix
irmin-watcher
irmin-server.unix
irmin-client.unix
websocket-lwt-unix
conduit-lwt-unix
lwt
Expand All @@ -44,10 +40,7 @@
custom_merge.exe
custom_graphql.exe
fold.exe
gc.exe
custom_storage.exe
client_batch.exe
server.exe))
custom_storage.exe))

(alias
(name runtest)
Expand Down
72 changes: 72 additions & 0 deletions examples/server/client.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
(*
* Copyright (c) 2023 Tarides <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

open Lwt.Syntax

module Client =
Irmin_client_unix.Make_codec (Irmin_server.Conn.Codec.Bin) (Config.Store)

module Info = Irmin_client_unix.Info (Client.Info)

let info msg = Info.v ~author:"tester" msg

let main () =
let* client = Client.connect Config.uri in
let* main = Client.main client in
let* () =
Client.set_exn ~info:(info "set testing") main [ "testing" ] "testing"
in
let* () =
Client.set_exn ~info:(info "set remove") main [ "remove" ] "remove"
in
let* () = Client.remove_exn ~info:(info "remove remove") main [ "remove" ] in
let batch =
Client.Batch.(
v ()
|> add_value [ "a"; "b"; "c" ] "123"
|> add_value [ "foo" ] "bar"
|> remove [ "testing" ])
in
let* c = Client.Batch.apply ~info:(info "apply batch") ~path:[] main batch in
Logs.info (fun l ->
l "Applied batch -> commit %a" Irmin.Type.(pp Client.commit_key_t) c);

let* abc = Client.get main [ "a"; "b"; "c" ] in
assert (String.equal abc "123");

let* foo = Client.get main [ "foo" ] in
assert (foo = "bar");

let* testing = Client.find main [ "testing" ] in
assert (Option.is_none testing);

let* remove = Client.mem main [ "remove" ] in
assert (remove = false);

let* commit = Client.Commit.of_key client c in
let tree = Client.Commit.tree (Option.get commit) in
let* concrete = Client.Tree.to_concrete tree in

Logs.info (fun l -> l "%a" Irmin.Type.(pp Client.Tree.concrete_t) concrete);

Lwt.return_unit

let () =
Fmt_tty.setup_std_outputs ();
Logs.(set_level @@ Some Debug);
Irmin.Export_for_backends.Logging.reporter (module Mtime_clock)
|> Logs.set_reporter;
Lwt_main.run @@ main ()
19 changes: 19 additions & 0 deletions examples/server/config.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(*
* Copyright (c) 2023 Tarides <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

module Store = Irmin_mem.KV.Make (Irmin.Contents.String)

let uri = Uri.of_string "tcp://localhost:4242"
12 changes: 12 additions & 0 deletions examples/server/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(executables
(names client server)
(libraries
irmin
irmin-client.unix
irmin-server.unix
irmin-git.unix
irmin-pack.unix
logs
unix
fmt.tty
hex))
25 changes: 10 additions & 15 deletions examples/server.ml → examples/server/server.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(*
* Copyright (c) 2018-2022 Tarides <[email protected]>
* Copyright (c) 2023 Tarides <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
Expand All @@ -15,26 +15,21 @@
*)

open Lwt.Syntax
module Store = Irmin_mem.KV.Make (Irmin.Contents.String)
module Server = Irmin_server_unix.Make (Store)

let info () = Irmin.Info.Default.empty

let init () =
let* repo = Store.Repo.v (Irmin_mem.config ()) in
let* main = Store.main repo in
let+ () = Store.set_exn ~info main [ "foo" ] "bar" in
()
module Server =
Irmin_server_unix.Make_ext (Irmin_server.Conn.Codec.Bin) (Config.Store)

let main () =
let uri = Uri.of_string Sys.argv.(1) in
let config = Irmin_mem.config () in
let dashboard = `TCP (`Port 1234) in
let uri = Config.uri in
let* server = Server.v ~uri ~dashboard config in
let () = Format.printf "Listening on %a@." Uri.pp uri in
Logs.debug (fun l -> l "Listening on %a@." Uri.pp uri);
Server.serve server

let () =
Lwt_main.run
@@ let* () = init () in
main ()
Fmt_tty.setup_std_outputs ();
Logs.(set_level @@ Some Debug);
Irmin.Export_for_backends.Logging.reporter (module Mtime_clock)
|> Logs.set_reporter;
Lwt_main.run @@ main ()
Loading
Loading