2017-02-24 20:17:53 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
module type DISTRIBUTED_DB = sig
|
2017-03-28 15:31:41 +04:00
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
type t
|
|
|
|
type key
|
|
|
|
type value
|
2017-03-28 15:31:41 +04:00
|
|
|
type param
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
val known: t -> key -> bool Lwt.t
|
2017-04-19 23:46:10 +04:00
|
|
|
|
|
|
|
type error += Missing_data of key
|
|
|
|
val read: t -> key -> value tzresult Lwt.t
|
|
|
|
val read_opt: t -> key -> value option Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
val read_exn: t -> key -> value Lwt.t
|
2017-03-28 15:31:41 +04:00
|
|
|
|
|
|
|
val prefetch: t -> ?peer:P2p.Peer_id.t -> key -> param -> unit
|
|
|
|
val fetch: t -> ?peer:P2p.Peer_id.t -> key -> param -> value Lwt.t
|
|
|
|
|
2017-11-06 18:23:06 +04:00
|
|
|
val clear_or_cancel: t -> key -> unit
|
2017-02-24 20:17:53 +04:00
|
|
|
val inject: t -> key -> value -> bool Lwt.t
|
|
|
|
val watch: t -> (key * value) Lwt_stream.t * Watcher.stopper
|
2017-03-28 15:31:41 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module type DISK_TABLE = sig
|
|
|
|
type store
|
|
|
|
type key
|
|
|
|
type value
|
|
|
|
val known: store -> key -> bool Lwt.t
|
|
|
|
val read: store -> key -> value tzresult Lwt.t
|
|
|
|
val read_opt: store -> key -> value option Lwt.t
|
|
|
|
val read_exn: store -> key -> value Lwt.t
|
|
|
|
end
|
|
|
|
|
|
|
|
module type MEMORY_TABLE = sig
|
|
|
|
(* A subtype of Hashtbl.S *)
|
|
|
|
type 'a t
|
|
|
|
type key
|
|
|
|
val create: int -> 'a t
|
|
|
|
val find: 'a t -> key -> 'a
|
|
|
|
val add: 'a t -> key -> 'a -> unit
|
|
|
|
val replace: 'a t -> key -> 'a -> unit
|
|
|
|
val remove: 'a t -> key -> unit
|
|
|
|
val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
|
2017-02-24 20:17:53 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module type SCHEDULER_EVENTS = sig
|
|
|
|
type t
|
|
|
|
type key
|
|
|
|
val request: t -> P2p.Peer_id.t option -> key -> unit
|
|
|
|
val notify: t -> P2p.Peer_id.t -> key -> unit
|
2017-11-06 18:23:06 +04:00
|
|
|
val notify_cancelation: t -> key -> unit
|
2017-02-24 20:17:53 +04:00
|
|
|
val notify_unrequested: t -> P2p.Peer_id.t -> key -> unit
|
|
|
|
val notify_duplicate: t -> P2p.Peer_id.t -> key -> unit
|
2017-03-28 15:31:41 +04:00
|
|
|
val notify_invalid: t -> P2p.Peer_id.t -> key -> unit
|
|
|
|
end
|
|
|
|
|
|
|
|
module type PRECHECK = sig
|
|
|
|
type key
|
|
|
|
type param
|
2017-04-19 23:46:10 +04:00
|
|
|
type notified_value
|
2017-03-28 15:31:41 +04:00
|
|
|
type value
|
2017-04-19 23:46:10 +04:00
|
|
|
val precheck: key -> param -> notified_value -> value option
|
2017-02-24 20:17:53 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Make_table
|
2017-07-21 18:16:39 +04:00
|
|
|
(Hash : sig
|
|
|
|
type t
|
|
|
|
val name : string
|
|
|
|
val encoding : t Data_encoding.t
|
|
|
|
val pp : Format.formatter -> t -> unit
|
|
|
|
end)
|
2017-03-28 15:31:41 +04:00
|
|
|
(Disk_table : DISK_TABLE with type key := Hash.t)
|
|
|
|
(Memory_table : MEMORY_TABLE with type key := Hash.t)
|
|
|
|
(Scheduler : SCHEDULER_EVENTS with type key := Hash.t)
|
|
|
|
(Precheck : PRECHECK with type key := Hash.t
|
|
|
|
and type value := Disk_table.value) : sig
|
2017-02-24 20:17:53 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
include DISTRIBUTED_DB with type key = Hash.t
|
|
|
|
and type value = Disk_table.value
|
|
|
|
and type param = Precheck.param
|
2017-02-24 20:17:53 +04:00
|
|
|
val create:
|
|
|
|
?global_input:(key * value) Watcher.input ->
|
|
|
|
Scheduler.t -> Disk_table.store -> t
|
2017-04-19 23:46:10 +04:00
|
|
|
val notify: t -> P2p.Peer_id.t -> key -> Precheck.notified_value -> unit Lwt.t
|
2017-02-24 20:17:53 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module type REQUEST = sig
|
|
|
|
type key
|
|
|
|
type param
|
|
|
|
val active : param -> P2p.Peer_id.Set.t
|
|
|
|
val send : param -> P2p.Peer_id.t -> key list -> unit
|
|
|
|
end
|
|
|
|
|
|
|
|
module Make_request_scheduler
|
2017-09-29 20:43:13 +04:00
|
|
|
(Hash : sig
|
|
|
|
type t
|
|
|
|
val name : string
|
|
|
|
val encoding : t Data_encoding.t
|
|
|
|
val pp : Format.formatter -> t -> unit
|
|
|
|
end)
|
2017-03-28 15:31:41 +04:00
|
|
|
(Table : MEMORY_TABLE with type key := Hash.t)
|
2017-02-24 20:17:53 +04:00
|
|
|
(Request : REQUEST with type key := Hash.t) : sig
|
|
|
|
|
|
|
|
type t
|
|
|
|
val create: Request.param -> t
|
|
|
|
val shutdown: t -> unit Lwt.t
|
|
|
|
include SCHEDULER_EVENTS with type t := t and type key := Hash.t
|
|
|
|
|
|
|
|
end
|