package irmin-pack
Irmin backend which stores values in a pack file
Install
Dune Dependency
Authors
Maintainers
Sources
irmin-3.3.1.tbz
sha256=535254ca443858bfc9e540535977fed63e9206d4b78c5cac0239d1e6657b5c78
sha512=fa18557fcf808121a0495de707c6f7bff4a69197b310480816648adafd4a659b5673a1f5bbf4574f517b7d93253735ef7798b0c365d87afac60675007ef19b54
doc/src/irmin-pack.unix/append_only_file.ml.html
Source file append_only_file.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
(* * Copyright (c) 2022-2022 Tarides <contact@tarides.com> * * 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 Import include Append_only_file_intf module Make (Io : Io.S) = struct module Io = Io type rw_perm = { buf : Buffer.t; auto_flush_threshold : int; auto_flush_callback : unit -> unit; } (** [rw_perm] contains the data necessary to operate in readwrite mode. *) type t = { io : Io.t; mutable persisted_end_offset : int63; dead_header_size : int63; rw_perm : rw_perm option; } let create_rw ~path ~overwrite ~auto_flush_threshold ~auto_flush_callback = let open Result_syntax in let+ io = Io.create ~path ~overwrite in let persisted_end_offset = Int63.zero in let buf = Buffer.create 0 in { io; persisted_end_offset; dead_header_size = Int63.zero; rw_perm = Some { buf; auto_flush_threshold; auto_flush_callback }; } let open_rw ~path ~end_offset ~dead_header_size ~auto_flush_threshold ~auto_flush_callback = let open Result_syntax in let+ io = Io.open_ ~path ~readonly:false in let persisted_end_offset = end_offset in let dead_header_size = Int63.of_int dead_header_size in let buf = Buffer.create 0 in { io; persisted_end_offset; dead_header_size; rw_perm = Some { buf; auto_flush_threshold; auto_flush_callback }; } let open_ro ~path ~end_offset ~dead_header_size = let open Result_syntax in let+ io = Io.open_ ~path ~readonly:true in let persisted_end_offset = end_offset in let dead_header_size = Int63.of_int dead_header_size in { io; persisted_end_offset; dead_header_size; rw_perm = None } let empty_buffer = function | { rw_perm = Some { buf; _ }; _ } when Buffer.length buf > 0 -> false | _ -> true let close t = if not @@ empty_buffer t then Error `Pending_flush else Io.close t.io let readonly t = Io.readonly t.io let path t = Io.path t.io let auto_flush_threshold = function | { rw_perm = None; _ } -> None | { rw_perm = Some rw_perm; _ } -> Some rw_perm.auto_flush_threshold let end_offset t = match t.rw_perm with | None -> t.persisted_end_offset | Some rw_perm -> let ( + ) = Int63.add in t.persisted_end_offset + (Buffer.length rw_perm.buf |> Int63.of_int) let refresh_end_offset t new_end_offset = match t.rw_perm with | Some _ -> Error `Rw_not_allowed | None -> t.persisted_end_offset <- new_end_offset; Ok () let flush t = match t.rw_perm with | None -> Error `Ro_not_allowed | Some rw_perm -> let open Result_syntax in let ( + ) = Int63.add in let s = Buffer.contents rw_perm.buf in let off = t.persisted_end_offset + t.dead_header_size in let+ () = Io.write_string t.io ~off s in t.persisted_end_offset <- t.persisted_end_offset + (String.length s |> Int63.of_int); (* [truncate] is semantically identical to [clear], except that [truncate] doesn't deallocate the internal buffer. We use [clear] in legacy_io. *) Buffer.truncate rw_perm.buf 0 let fsync t = Io.fsync t.io let read_exn t ~off ~len b = let ( + ) = Int63.add in let ( > ) a b = Int63.compare a b > 0 in let off' = off + Int63.of_int len in if off' > t.persisted_end_offset then raise (Errors_base.Pack_error `Read_out_of_bounds); let off = off + t.dead_header_size in Io.read_exn t.io ~off ~len b let read_to_string t ~off ~len = let ( + ) = Int63.add in let ( > ) a b = Int63.compare a b > 0 in let off' = off + Int63.of_int len in if off' > t.persisted_end_offset then Error `Read_out_of_bounds else let off = off + t.dead_header_size in Io.read_to_string t.io ~off ~len let append_exn t s = match t.rw_perm with | None -> raise Errors.RO_not_allowed | Some rw_perm -> assert (Buffer.length rw_perm.buf < rw_perm.auto_flush_threshold); Buffer.add_string rw_perm.buf s; if Buffer.length rw_perm.buf >= rw_perm.auto_flush_threshold then ( rw_perm.auto_flush_callback (); assert (empty_buffer t)) end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>