Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file index_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339(* The MIT License
Copyright (c) 2019 Craig Ferguson <craig@tarides.com>
Thomas Gazagnaire <thomas@tarides.com>
Ioana Cristescu <ioana@tarides.com>
Clément Pascutto <clement@tarides.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. *)open!ImportmoduletypeKey=sigincludeData.Key(** @inline *)endmoduletypeValue=sigincludeData.Value(** @inline *)endmoduletypeS=sigtypet(** The type for indexes. *)typekey(** The type for keys. *)typevalue(** The type for values. *)typecache(** The type for caches of index instances. *)valempty_cache:unit->cache(** Construct a new empty cache of index instances. *)valv:?flush_callback:(unit->unit)->?cache:cache->?fresh:bool->?readonly:bool->?throttle:[`Overcommit_memory|`Block_writes]->?lru_size:int->log_size:int->string->t(** The constructor for indexes.
@param flush_callback
A function to be called before any new bindings are persisted to disk
(including both automatic flushing and explicit calls to {!flush} or
{!close}).
This can be used to ensure certain pre-conditions are met before
bindings are persisted to disk. (For instance, if the index bindings are
pointers into another data-structure [d], it may be necessary to flush
[d] first to avoid creating dangling pointers.)
@param cache used for instance sharing.
@param fresh whether an existing index should be overwritten.
@param read_only whether read-only mode is enabled for this index.
@param throttle
the strategy to use when the cache are full and and async in already in
progress. [Block_writes] (the default) blocks any new writes until the
merge is completed. [Overcommit_memory] does not block but continues to
fill the (already full) cache.
@param log_size the maximum number of bindings in the `log` IO.
@param lru_size
the maximum number of recently-read index bindings kept in memory.
Defaults to 30_000. *)valclear:t->unit(** [clear t] clears [t] so that there are no more bindings in it. *)valfind:t->key->value(** [find t k] is the binding of [k] in [t]. *)valmem:t->key->bool(** [mem t k] is [true] iff [k] is bound in [t]. *)valreplace:?overcommit:bool->t->key->value->unit(** [replace t k v] binds [k] to [v] in [t], replacing any existing binding of
[k].
If [overcommit] is true, the operation does not triger a merge, even if
the caches are full. By default [overcommit] is false. *)valfilter:t->(key*value->bool)->unit(** [filter t p] removes all the bindings (k, v) that do not satisfy [p]. This
operation is costly and blocking. *)valiter:(key->value->unit)->t->unit(** Iterates over the index bindings. Limitations:
- Order is not specified.
- In case of recent replacements of existing values (since the last
merge), this will hit both the new and old bindings.
- May not observe recent concurrent updates to the index by other
processes. *)valflush:?no_callback:unit->?with_fsync:bool->t->unit(** Flushes all internal buffers of the [IO] instances.
- Passing [~no_callback:()] disables calling the [flush_callback] passed
to {!v}.
- If [with_fsync] is [true], this also flushes the OS caches for each [IO]
instance. *)valclose:?immediately:unit->t->unit(** Closes all resources used by [t], flushing any internal buffers in the
instance.
If [immediately] is passed, this operation will abort any ongoing
background processes. This guarantees not to corrupt the store, but may
require additional work to be done on the next startup. *)valsync:t->unit(** [sync t] syncs a read-only index with the files on disk. Raises
{!RW_not_allowed} if called by a read-write index. *)valis_merging:t->bool(** [is_merging t] returns true if [t] is running a merge. Raises
{!RO_not_allowed} if called by a read-only index. *)valmerge:t->unit(** [merge t] forces a merge for [t].
If there is no merge running, this operation is non-blocking, i.e. it
returns immediately, with the merge running concurrently.
If a merge is running already, this operation blocks until the previous
merge is complete. It then launches a merge (which runs concurrently) and
returns. *)valtry_merge:t->unit(** [try_merge] is like {!merge} but is a no-op if the number of entries in
the write-ahead log is smaller than [log_size]. *)(** Offline [fsck]-like utility for checking the integrity of Index stores
built using this module. *)moduleChecks:sigincludeChecks.S(** @inline *)endendmodulePrivate_types=structtypemerge_stages=[`After|`After_clear|`After_first_entry|`Before](** Some operations that trigger a merge can have hooks inserted at the
following stages:
- [`Before]: immediately before merging (while holding the merge lock);
- [`After_clear]: immediately after clearing the log, at the end of a
merge;
- [`After_first_entry]: immediately after adding the first entry in the
merge file, if the data file contains at least one entry;
- [`After]: immediately after merging (while holding the merge lock). *)typemerge_result=[`Completed|`Aborted]endmoduletypePrivate=sigincludeStype'ahookincludemoduletypeofPrivate_types(** @inline *)type'aasync(** The type of asynchronous computation. *)valreplace':?hook:[`Mergeofmerge_stages]hook->?overcommit:bool->t->key->value->merge_resultasyncoption(** [replace' t k v] is like {!replace t k v} but returns a promise of a merge
result if the {!replace} call triggered one. *)valclose':hook:[`Abort_signalled]hook->?immediately:unit->t->unit(** [`Abort_signalled]: after the cancellation signal has been sent to any
concurrent merge operations, but {i before} blocking on those
cancellations having completed. *)valclear':hook:[`Abort_signalled|`IO_clear]hook->t->unitvaltry_merge_aux:?hook:merge_stageshook->?force:bool->t->merge_resultasync(** [try_merge_aux t] tries to merge [t]. If [force] is false (the default), a
merge is performed only if there is more entries in the write-ahead log
than the configured limits. If [force] is set, the merge is performed no
matter what. *)valawait:'aasync->('a,[`Async_exnofexn])result(** Wait for an asynchronous computation to finish. *)valreplace_with_timer:?sampling_interval:int->t->key->value->unit(** Time replace operations. The reported time is an average on an number of
consecutive operations, which can be specified by [sampling_interval]. If
[sampling_interval] is not set, no operation is timed. *)valsync':?hook:[`Before_offset_read|`After_offset_read|`Reload_log|`Reload_log_async]hook->t->unit(** Hooks:
- [`Before_offset_read]: before reading the generation number and the
offset.
- [`After_offset_read]: after reading the generation number and offset. *)vallog:t->(key*value)listoptionvallog_async:t->(key*value)listoptionendmoduletypeIndex=sig(* N.B. We use [sig ... end] redirections to avoid linking to the [_intf]
file in the generated docs. Once Odoc 2 is released, this can be
removed. *)moduleKey:sig(** The input of {!Make} for keys. *)moduletypeS=sigincludeKey(** @inline *)end(** String keys of a given fixed size in bytes. *)moduleString_fixed(L:sigvallength:intend):Swithtypet=stringendmoduleValue:sig(** The input of {!Make} for values. The same requirements as for {!Key}
apply. *)moduletypeS=sigincludeValue(** @inline *)end(** String values of a given fixed size in bytes. *)moduleString_fixed(L:sigvallength:intend):Swithtypet=stringend(** Platform dependencies required by {!Make}. *)modulePlatform=Platform(** Signatures and implementations of caches. {!Make} requires a cache in
order to provide instance sharing. *)moduleCache:sigincludemoduletypeofCache(** @inline *)end(** Index module signature. *)moduletypeS=sigincludeS(** @inline *)endexceptionRO_not_allowed(** The exception raised when a write operation is attempted on a read_only
index. *)exceptionRW_not_allowed(** The exception is raised when a sync operation is attempted on a read-write
index. *)exceptionClosed(** The exception raised when any operation is attempted on a closed index,
except for [close], which is idempotent. *)moduleMake(K:Key.S)(V:Value.S)(_:Platform.S)(C:Cache.S):Swithtypekey=K.tandtypevalue=V.t(** Run-time metric tracking for index instances. *)moduleStats:sigincludemoduletypeofStats(** @inline *)endmoduleChecks=Checks(** These modules should not be used. They are exposed purely for testing
purposes. *)modulePrivate:sigmoduleHook:sigtype'atvalv:('a->unit)->'atendmoduleSearch=SearchmoduleIo=IomoduleIo_array=Io_arraymoduleFan=FanmoduleData=DatamoduleLayout=LayoutmoduleLogs:sigvalsetup:?reporter:Logs.reporter->?style_renderer:Fmt.style_renderer->?level:Logs.level->(modulePlatform.CLOCK)->unitvalsetup_term:?reporter:Logs.reporter->(modulePlatform.CLOCK)->unitCmdliner.Term.tendmoduletypeS=Privatewithtype'ahook:='aHook.tmoduleMake(K:Key)(V:Value)(_:Platform.S)(C:Cache.S):Swithtypekey=K.tandtypevalue=V.tendend