From 06873da19779bce71f8b79a36baefdc0b9c82511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Fri, 10 Nov 2017 20:30:29 +0100 Subject: [PATCH] Distributed_db: add an argument `timeout` to 'prefetch`. --- src/node/shell/distributed_db.ml | 9 +++++++-- src/node/shell/distributed_db.mli | 6 +++++- src/node/shell/distributed_db_functors.ml | 10 ++++++++-- src/node/shell/distributed_db_functors.mli | 7 ++++++- src/node/shell/state.ml | 7 ++++--- src/node/shell/state.mli | 6 ++++-- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/node/shell/distributed_db.ml b/src/node/shell/distributed_db.ml index 9a313c757..608ea48c7 100644 --- a/src/node/shell/distributed_db.ml +++ b/src/node/shell/distributed_db.ml @@ -883,7 +883,11 @@ module type DISTRIBUTED_DB = sig val read_opt: t -> key -> value option Lwt.t val read_exn: t -> key -> value Lwt.t val watch: t -> (key * value) Lwt_stream.t * Watcher.stopper - val prefetch: t -> ?peer:P2p.Peer_id.t -> key -> param -> unit + val prefetch: + t -> + ?peer:P2p.Peer_id.t -> + ?timeout:float -> + key -> param -> unit val fetch: t -> ?peer:P2p.Peer_id.t -> @@ -909,7 +913,8 @@ module Make let read t k = Table.read (Kind.proj t) k let read_opt t k = Table.read_opt (Kind.proj t) k let read_exn t k = Table.read_exn (Kind.proj t) k - let prefetch t ?peer k p = Table.prefetch (Kind.proj t) ?peer k p + let prefetch t ?peer ?timeout k p = + Table.prefetch (Kind.proj t) ?peer ?timeout k p let fetch t ?peer ?timeout k p = Table.fetch (Kind.proj t) ?peer ?timeout k p let clear_or_cancel t k = Table.clear_or_cancel (Kind.proj t) k diff --git a/src/node/shell/distributed_db.mli b/src/node/shell/distributed_db.mli index 5adf9ed85..be986c79b 100644 --- a/src/node/shell/distributed_db.mli +++ b/src/node/shell/distributed_db.mli @@ -86,7 +86,11 @@ module type DISTRIBUTED_DB = sig val read_opt: t -> key -> value option Lwt.t val read_exn: t -> key -> value Lwt.t val watch: t -> (key * value) Lwt_stream.t * Watcher.stopper - val prefetch: t -> ?peer:P2p.Peer_id.t -> key -> param -> unit + val prefetch: + t -> + ?peer:P2p.Peer_id.t -> + ?timeout:float -> + key -> param -> unit val fetch: t -> ?peer:P2p.Peer_id.t -> diff --git a/src/node/shell/distributed_db_functors.ml b/src/node/shell/distributed_db_functors.ml index e09656800..429b58e68 100644 --- a/src/node/shell/distributed_db_functors.ml +++ b/src/node/shell/distributed_db_functors.ml @@ -26,7 +26,12 @@ module type DISTRIBUTED_DB = sig val read_opt: t -> key -> value option Lwt.t val read_exn: t -> key -> value Lwt.t - val prefetch: t -> ?peer:P2p.Peer_id.t -> key -> param -> unit + val prefetch: + t -> + ?peer:P2p.Peer_id.t -> + ?timeout:float -> + key -> param -> unit + val fetch: t -> ?peer:P2p.Peer_id.t -> @@ -207,7 +212,8 @@ end = struct wrap s k ?timeout (Lwt.waiter_of_wakener data.wakener) | Found v -> return v - let prefetch s ?peer k param = Lwt.ignore_result (fetch s ?peer k param) + let prefetch s ?peer ?timeout k param = + try ignore (fetch s ?peer ?timeout k param) with _ -> () let notify s p k v = match Memory_table.find s.memory k with diff --git a/src/node/shell/distributed_db_functors.mli b/src/node/shell/distributed_db_functors.mli index 75813cd3d..16407349b 100644 --- a/src/node/shell/distributed_db_functors.mli +++ b/src/node/shell/distributed_db_functors.mli @@ -24,7 +24,12 @@ module type DISTRIBUTED_DB = sig val read_opt: t -> key -> value option Lwt.t val read_exn: t -> key -> value Lwt.t - val prefetch: t -> ?peer:P2p.Peer_id.t -> key -> param -> unit + val prefetch: + t -> + ?peer:P2p.Peer_id.t -> + ?timeout:float -> + key -> param -> unit + val fetch: t -> ?peer:P2p.Peer_id.t -> diff --git a/src/node/shell/state.ml b/src/node/shell/state.ml index 5a3ed16d8..009cede76 100644 --- a/src/node/shell/state.ml +++ b/src/node/shell/state.ml @@ -617,6 +617,8 @@ module Registred_protocol = struct val complete_b58prefix : Context.t -> string -> string list Lwt.t end + type t = (module T) + let build_v1 hash = let (module F) = Tezos_protocol_compiler.Registerer.get_exn hash in let module Name = struct @@ -637,7 +639,8 @@ module Registred_protocol = struct VersionTable.create 20 let mem hash = - VersionTable.mem versions hash || Tezos_protocol_compiler.Registerer.mem hash + VersionTable.mem versions hash || + Tezos_protocol_compiler.Registerer.mem hash let get_exn hash = try VersionTable.find versions hash @@ -678,8 +681,6 @@ module Register_embedded_protocol let complete_b58prefix = Env.Context.complete end : Registred_protocol.T) - - end let read diff --git a/src/node/shell/state.mli b/src/node/shell/state.mli index e5b113bd4..a491bce37 100644 --- a/src/node/shell/state.mli +++ b/src/node/shell/state.mli @@ -202,10 +202,12 @@ module Registred_protocol : sig val complete_b58prefix : Context.t -> string -> string list Lwt.t end + type t = (module T) + val mem: Protocol_hash.t -> bool - val get: Protocol_hash.t -> (module T) option - val get_exn: Protocol_hash.t -> (module T) + val get: Protocol_hash.t -> t option + val get_exn: Protocol_hash.t -> t end