123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137(*
* 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.
*)openImportmoduletypeS=sig(** Abstraction for a chunked suffix. It is functionally equivalent to
{!Append_only_file} but with a chunked implementation that is
parameterized by
- [start_idx] for {!create_rw} to know the starting file name, and
- [start_idx] and [chunk_num] for the open functions to know the starting
file name and how many files there are. *)moduleIo:Io.SmoduleErrs:Io_errors.SmoduleAo:Append_only_file.Stypettypecreate_error=Io.create_errortypeopen_error=[Io.open_error|`Closed|`Invalid_argument|`Inconsistent_store|`Read_out_of_bounds]typeadd_new_error=[open_error|Io.close_error|`Pending_flush|`File_existsofstring|`Multiple_empty_chunks]valcreate_rw:root:string->start_idx:int->overwrite:bool->auto_flush_threshold:int->auto_flush_procedure:Ao.auto_flush_procedure->(t,[>create_error])resultvalopen_rw:root:string->appendable_chunk_poff:int63->start_idx:int->chunk_num:int->dead_header_size:int->auto_flush_threshold:int->auto_flush_procedure:Ao.auto_flush_procedure->(t,[>open_error])resultvalopen_ro:root:string->appendable_chunk_poff:int63->dead_header_size:int->start_idx:int->chunk_num:int->(t,[>open_error])resultvaladd_chunk:auto_flush_threshold:int->auto_flush_procedure:Ao.auto_flush_procedure->t->(unit,[>add_new_error])resultvalstart_idx:t->intvalchunk_num:t->intvalclose:t->(unit,[>Io.close_error|`Pending_flush])resultvalempty_buffer:t->boolvalflush:t->(unit,[>Io.write_error])resultvalfsync:t->(unit,[>Io.write_error])resultvalappendable_chunk_poff:t->int63(** [appendable_chunk_poff t] is the number of bytes of the chunk file that is
currently appendable. It does not perform IO.
{3 RW mode}
It also counts the bytes not flushed yet.
{3 RO mode}
This information originates from the latest reload of the control file.
Calling [refresh_appendable_chunk_poff t] updates [appendable_chunk_poff]. *)valrefresh_appendable_chunk_poff:t->int63->(unit,[>`Rw_not_allowed])result(** Ingest the new end offset of the appendable chunk file. Typically happens
in RO mode when the control file has been re-read.
{3 RW mode}
Always returns [Error `Rw_not_allowed]. *)valend_soff:t->int63(** [end_soff t] is the end offset for the chunked suffix. The valid range of
offsets is 0 <= off < end_soff. Therefore, [end_soff] also represents the
length of the chunked suffix. *)valread_exn:t->off:int63->len:int->bytes->unitvalappend_exn:t->string->unitvalreadonly:t->boolvalauto_flush_threshold:t->intoptionvalfold_chunks:(acc:'a->idx:int->start_suffix_off:int63->end_suffix_off:int63->is_appendable:bool->'a)->'a->t->'aendmoduletypeSigs=sigmoduletypeS=SmoduleMake(Io:Io.S)(Errs:Io_errors.SwithmoduleIo=Io):SwithmoduleIo=IoandmoduleErrs=Errsend