Data-Shared

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


  Data::Shared->open_readonly($dir, strict => 1)
    Freeze the store in the producing process first. The 21 families with
    "new_readonly" (the "freeze" entries in Data::Shared::Registry,
    including "hashmap" and "bloomfilter") require frozen files; a live file
    aborts replay with the leaf's error under "failed to replay manifest".
    Other leaves use their normal constructor. The generic mutating verbs
    ("set", "delete", "incr", "push", "pop"), every root lifecycle write
    ("mount", "unmount", "freeze_all", "unlink_all") and native "unlink",
    "destroy" and "freeze" through "shared_call" croak on any read-only
    root. A handle taken with "handle" is the leaf itself and carries no
    root flag: every native method on it, those three included, keeps
    whatever permissions that leaf's own file gives it.

    "strict => 1", off by default, requires "new_readonly" or immutability
    (PerfectHash) throughout the declared tree, including lazy composite
    leaves. Unsupported backends are rejected before any handle is opened.
    Raw handles expose the backend's API; filesystem permissions govern
    direct writes.

  $root->mount($name, $spec, @ctor_args)
    Mounts a structure under $name (which may itself contain "/", for nested
    namespaces; longest-prefix wins). $spec may be:

    *   a short spec: 'hashmap', 'hashmap:ii', 'buffer:i64', 'queue:int',
        'sync:semaphore', 'sortedset:strings', etc. Short specs accept mixed
        case and resolve to lowercase. See Data::Shared::Registry for the
        full inventory.

    *   a full class name: 'Data::HashMap::Shared::SS'.

    *   a hashref: "{ spec => 'hashmap:ss', args => [...] }" or with an
        explicit "ctor" (for "new_weighted"/"new_decayed" style
        constructors, also available as 'reservoir:weighted' /
        'topk:decayed').

    *   an already-constructed handle (transient; not written to the
        manifest).

    *   a coderef factory called as "$factory->($root, $name)" (transient).

    *   a composite spec (arrayref or hashref with "child"): see "DEEP PATHS
        (COMPOSITES)".

    Returns the native handle (for a composite mount, a Data::Shared::Node
    for the mount). "$root->handle($path)" also returns it, and any native
    method can always be reached that way or via "shared_call".

    Configuration arrays and hashes are copied before construction. Cycles
    are rejected; a constructor argument JSON has no form for at all -- a
    code reference, or an object that is not a JSON::PP boolean -- makes the
    mount transient rather than refusing it. Failed mount publication
    restores the previous namespace and removes backing paths created by
    that attempt. Existing files are retained. Factories manage their own
    external side effects. Nested mount mutations inside a factory are
    rejected, and so is reopening the same root: the factory runs while its
    caller holds the manifest lock, which no second root in the same process
    can acquire. Use the $root it is given.

    Mount arguments must survive manifest replay, so a value JSON would
    record as something else is refused at mount time instead: "Inf", "NaN"
    and lone surrogates, a stringified "Inf" or "NaN" number included; a
    plain string such as 'Inf' is kept. Strings are recorded as bytes; a
    character string (perl's UTF8 flag on) is encoded to UTF-8 first,
    uniformly from U+0080 up, so "\xe9" after "utf8::upgrade" and the plain
    byte "\xe9" name two different files.

    Special cases: "perfecthash" is an immutable build-then-load structure,
    so a 'perfecthash' spec takes either a built file path or a "{ build_int
    => \@keys, path => $file }" / "build_str" hashref. A build spec creates
    a missing file once; an existing file is loaded without rebuilding. To
    supply one some other way, pass the factory or the loaded handle as the
    spec, as for any other type. "sortedset:strings" takes "mount('names',
    'sortedset:strings', { max => 100_000 })"; "set"/"keys" backing paths
    are auto-filled for file-backed roots. Explicit backing paths must be
    absolute. Derived paths follow the root's directory spelling and are
    relative exactly when that directory is.

    Backing paths already owned by another mount are rejected before
    construction, including aliases produced by filename sanitization (e.g.
    "a/b" and "a__b") and string SortedSet sidecars. Mount the same native
    handle under another name to share it intentionally; an "unmount" that
    would unlink storage another mount still names is refused, so retire the
    aliases first.

  $root->unmount($name), $root->mounts, $root->mount_info($name)
    Lifecycle and introspection for mounts. Names are canonicalized as
    "mount" canonicalizes them, so "/a/" and "a" name one mount. "unmount"
    returns 1 when it removed a mount and 0 when there was none;
    "mount_info" returns "undef" for an absent name, and otherwise a hashref
    of "name", "class", "key", "dist", "path_class", "file", "transient" and
    "composite". "mount_names" is a synonym for "mounts"; "available_types"
    (class or root method) lists the 39 short spec names and "registry"
    returns the Data::Shared::Registry table itself.

    "unmount" retains storage in a manifest ledger; remounting the same name
    adopts it. To reclaim it while serving other mounts, remount it with the
    same spec and "unmount($name, unlink => 1)". "unlink_all" also reclaims
    retained storage from any process, but removes the whole store. Each
    retained store costs a manifest entry; use "unlink => 1" when rotating
    fresh names.

    "unmount($name, unlink => 1)" publishes the removal and retires storage
    under the same directory lock. Native "unlink" and "destroy" through
    "shared_call" at a mount do the same. See "SHARING A ROOT" for what
    other processes observe.

  $root->dir, $root->readonly, $root->manifest_path
    Accessors: the root's directory, whether it was opened read-only, and
    the path of its manifest. The directory and the manifest path are both
    "undef" for an anonymous root.

  $root->sync_all, $root->freeze_all, $root->unlink_all, $root->stats, $root->frozen
    "sync_all", "freeze_all" and "unlink_all" visit supported handles in
    mount order. Sync and freeze include a composite's parent, child index
    and every registered child, open or not. "freeze_all" counts newly
    sealed handles; 0 means nothing was left to seal.

    "stats" returns a hashref keyed by mount name, containing native stats
    or "{ class => ref $handle }". Composite stats include child and open
    counts and stats for cached children only; evicted children are absent.
    Stats fields are backend-specific. eg/monitoring.pl walks registered



( run in 0.918 second using v1.01-cache-2.11-cpan-60884a8df76 )