checkpoint-fault-probe.dhover×143all
#!/usr/bin/env dub
/+ dub.sdl:
    name "recovery-checkpoint-fault-probe"
    targetPath "../../../build"
    dependency "sparkles:base" path="../../.."
    dependency "sparkles:recovery" path="../../.."
    dflags "-preview=in" "-preview=dip1000"
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
+/
/// Real worker-thread directory-sync failure followed by a new immutable retry generation.
module 
(module) checkpoint_fault_probe

Real worker-thread directory-sync failure followed by a new immutable retry generation.

checkpoint_fault_probe
;
import
(package) core
core
.
(module) core.thread

The thread module provides support for thread creation and management.

Source

core/thread/package.d

@copyrightCopyright Sean Kelly 2005 - 2012.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Walter Bright, Alex Rønne Petersen, Martin Nowak
thread
:
(class) core.thread.osthread.Thread

This class encapsulates all threading functionality for the D programming language. As thread manipulation is a required facility for garbage collection, all user threads should derive from this class, and instances of this class should never be explicitly deleted. A new thread may be created using either derivation or composition, as in the following example.

Thread
;
import
(package) core
core
.
(module) core.time

Module containing core time functionality, such as Duration (which represents a duration of time) or MonoTime (which represents a timestamp of the system's monotonic clock).

Various functions take a string (or strings) to represent a unit of time (e.g. convert!("days", "hours")(numDays)). The valid strings to use with such functions are "years", "months", "weeks", "days", "hours", "minutes", "seconds", "msecs" (milliseconds), "usecs" (microseconds), "hnsecs" (hecto-nanoseconds - i.e. 100 ns) or some subset thereof. There are a few functions that also allow "nsecs", but very little actually has precision greater than hnsecs.

Symbol Description
Types
Duration Represents a duration of time of weeks or less (kept internally as hnsecs). (e.g. 22 days or 700 seconds).
TickDuration DEPRECATED Represents a duration of time in system clock ticks, using the highest precision that the system provides.
MonoTime Represents a monotonic timestamp in system clock ticks, using the highest precision that the system provides.
Functions
convert Generic way of converting between two time units.
dur Allows constructing a Duration from the given time units with the given length.
weeks days hours

minutes seconds msecs

usecs hnsecs nsecs | Convenience aliases for dur. | | abs | Returns the absolute value of a duration. |

From Duration
From TickDuration
From units
To Duration
tickDuration.to, std,conv!Duration()
dur!"msecs"(5) or 5.msecs()

| To TickDuration | duration.to, std,conv!TickDuration() |

  • | TickDuration.from!"msecs"(msecs) |

| To units | duration.total!"days" | tickDuration.msecs | convert!("days", "msecs")(msecs) |

Source

core/time.d

@copyrightCopyright 2010 - 2012@licenseBoost License 1.0.@authorsJonathan M Davis and Kato Shoichi
time
:
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
, seconds;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(module) sparkles.base.expected

This module is implementing the Expected idiom.

See the $(LINK2 http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C, Andrei Alexandrescu’s talk (Systematic Error Handling in C++) and its slides.

Or more recent "Expect the Expected" by Andrei Alexandrescu for further background.

It is also inspired by C++'s proposed std::expected and Rust's Result.

Similar work is expectations by Paul Backus.

Main features

  • lightweight, no other external dependencies

  • works with pure, @safe, @nogc, nothrow, and immutable

  • provides methods: ok, err, consume, expect, expectErr, andThen, orElse, map, mapError, mapOrElse

  • type inference for ease of use with ok and err

  • allows to use same types for T and E

  • allows to define Expected without value (void for T) - can be disabled with custom Hook

  • provides facility to change the Expected behavior by custom Hook implementation using the Design by introspection paradigm.

  • can enforce result check (with a cost)

  • can behave like a normal Exception handled code by changing the used Hook implementation

  • range interface

Description

Actual Expected type is defined as Expected!(T, E, Hook), where:

  • T defines type of the success value

  • E defines type of the error

  • Hook defines behavior of the Expected

Default type for error is string, i.e. Expected!int is the same as Expected!(int, string).

Abort is used as a default hook.

Hooks

Expected has customizable behavior with the help of a third type parameter, Hook. Depending on what methods Hook defines, core operations on the Expected may be verified or completely redefined. If Hook defines no method at all and carries no state, there is no change in default behavior.

This module provides a few predefined hooks (below) that add useful behavior to Expected:

| Abort | Fails every incorrect operation with a call to assert(0). It is the default third parameter, i.e. Expected!short is the same as Expected!(short, string, Abort). | | Throw | Fails every incorrect operation by throwing an exception. | | AsException | With this hook implementation Expected behaves just like regular Exception handled code.

That means when function returns expected value, it returns instance of Expected with a success value. But when it tries to return error, Exception is thrown right away, i.e. Expected fails in constructor. | | RCAbort | Similar to Abort hook but uses reference counted payload instead which enables checking if the caller properly checked result of the Expected. |

The hook's members are looked up statically in a Design by Introspection manner and are all optional. The table below illustrates the members that a hook type may define and their influence over the behavior of the Checked type using it. In the table, hook is an alias for Hook if the type Hook does not introduce any state, or an object of type Hook otherwise.

  • Hook member

Semantics in Expected!(T, E, Hook)

    -
    - `enableDefaultConstructor`
        - If defined, `Expected` would have enabled or disabled default constructor
            based on it's `bool` value. Default constructor is disabled by default.
            `opAssign` for value and error types is generated if default constructor is enabled.

            -
            - `enableCopyConstructor`
                - If defined, `Expected` would have enabled or disabled copy constructor based
                    on it's `bool` value. It is enabled by default. When disabled, it enables automatic
                    check if the result was checked either for value or error.
                    When not checked it calls `hook.onUnchecked` if provided.

                    WARNING: As currently it's not possible to change internal state of `const`
                    or `immutable` object, automatic checking would't work on these. Hopefully with
                    `__mutable` proposal..

                    -
                    - `enableRefCountedPayload`
                        - Set `Expected` instances to use reference counted payload storage. It's usefull
                            when combined with `onUnchecked` to forcibly check that the result was checked for value
                            or error.

                            -
                            - `enableVoidValue`
                                - Defines if `Expected` supports `void` values. It's enabled by default so this
                                    hook can be used to disable it.

                                    -
                                    - `onAccessEmptyValue`
                                        - If value is accessed on unitialized `Expected` or `Expected` with error
                                            value, `hook.onAccessEmptyValue!E(err)` is called. If hook doesn't implement the
                                            handler, `T.init` is returned.

                                            -
                                            - `onAccessEmptyError`
                                                - If error is accessed on unitialized `Expected` or `Expected` with value,
                                                    `hook.onAccessEmptyError()` is called. If hook doesn't implement the handler,
                                                    `E.init` is returned.

                                                    -
                                                    - `onUnchecked`
                                                        - If the result of `Expected` isn't checked, `hook.onUnchecked()` is called to
                                                            handle the error. If hook doesn't implement the handler, assert is thrown.
                                                            Note that `hook.enableCopyConstructor` must be `false` or `hook.enableRefCountedPayload`
                                                            must be `true` for checks to work.

                                                            -
                                                            - `onValueSet`
                                                                - `hook.onValueSet!T(val)` function is called when success value is being set to
                                                                    `Expected`. It can be used for loging purposes, etc.

                                                                    -
                                                                    - `onErrorSet`
                                                                        - `hook.onErrorSet!E(err)` function is called when error value is being set to
                                                                            `Expected`. This hook function is used by `AsException` hook implementation
                                                                            to change `Expected` idiom to normal `Exception` handling behavior.

Vendored from tchaloupka/expected by Tomáš Chaloupka, at commit 0793e8b7dc06dd05b3fa3103e5a99bf0bfd5f638: release 0.4.1 plus the five commits upstream made after it, which no release tags:

  • e35db58c5b454aceffcc2f90fb6aa2a9e4e2e132 makes the advanced usage example work outside the module;

  • 60afab8725bb4c48542884174bb67a68548fe0a0 keeps the source hook in map/mapError and lets map return void;

  • 5f1f2083381fdfcfa22428541be98694087fcd30 makes isVoidValueEnabled read the member it checks;

  • 5ee6c2a531b3d66964795274b1bcbdbd9cb7294f allocates the reference-counted payload of a void Expected;

  • 0793e8b7dc06dd05b3fa3103e5a99bf0bfd5f638 tests that map to void keeps the source hook.

It stops before 0.5.0, which marks Expected @mustuse by making it an explicit template around the struct: that breaks matching Expected!(T, E, H) in is expressions, which Sparkles relies on, and turns every discarded result into an error.

Changed from upstream only where Sparkles' build flags require it: the module name (and the advanced example's imports of it), the ``expected. prefix on its test names, const for in on the extern(C) GC declarations (-preview=in rejects in there), and the Throw hook throwing an error object read through an inout accessor unqualified (base disallows deprecations). No other changes.

Why vendored: it is one module of about 2000 lines under Sparkles' own licence (BSL-1.0). As a dub package it put expected and, through its unittest configuration, silly (which Sparkles does not use) into nearly every one of the repository's 88 dub.selections.json files and into the Nix dub locks. The fixes upstream made after 0.4.1 are untagged, so dub could not take them. Owning the copy keeps it building under Sparkles' flags and conventions.

Examples

Basic usage

auto foo(int i) {
    if (i == 0) return err!int("oops");
    return ok(42 / i);
}

version (D_Exceptions)
{
    auto bar(int i) {
        if (i == 0) throw new Exception("err");
        return i-1;
    }
}

// basic checks
assert(foo(2));
assert(foo(2).hasValue);
assert(!foo(2).hasError);
assert(foo(2).value == 21);

assert(!foo(0));
assert(!foo(0).hasValue);
assert(foo(0).hasError);
assert(foo(0).error == "oops");

// void result
assert(ok()); // no error -> success
assert(!ok().hasError);
// assert(err("foo").hasValue); // doesn't have hasValue and value properties

version (D_Exceptions)
{
    // expected from throwing function
    assert(consume!bar(1) == 0);
    assert(consume!bar(0).error.msg == "err");
}

// orElse
assert(foo(2).orElse!(() => 0) == 21);
assert(foo(0).orElse(100) == 100);

// andThen
assert(foo(2).andThen(foo(6)) == 7);
assert(foo(0).andThen(foo(6)).error == "oops");

// map
assert(foo(2).map!(a => a*2).map!(a => a - 2) == 40);
assert(foo(0).map!(a => a*2).map!(a => a - 2).error == "oops");

// mapError
assert(foo(0).mapError!(e => "OOPS").error == "OOPS");
assert(foo(2).mapError!(e => "OOPS") == 21);

// mapOrElse
assert(foo(2).mapOrElse!(v => v*2, e => 0) == 42);
assert(foo(0).mapOrElse!(v => v*2, e => 0) == 0);

Advanced usage - behavior modification

import exp = sparkles.base.expected;
import sparkles.base.expected : orElse; // UFCS doesn't work with renamed imports
import std.exception : assertThrown;

// define our Expected type using Exception as Error values
// and Throw hook, which throws when empty value or error is accessed
template Expected(T)
{
    alias Expected = exp.Expected!(T, Exception, exp.Throw);
}

// create wrappers for simplified usage of our Expected
auto ok(T)(T val) { return exp.ok!(Exception, exp.Throw)(val); }
auto err(T)(Exception err) { return exp.err!(T, exp.Throw)(err); }

// use it as normal
assert(ok(42) == 42);
assert(err!int(new Exception("foo")).orElse(0) == 0);
assertThrown(ok(42).error);
assertThrown(err!int(new Exception("bar")).value);
@copyrightCopyright © 2019, Tomáš Chaloupka@authorsTomáš Chaloupka, with contributions from Kostiantyn Tokar, Jan Jurzitza, Beyar and Petar Kirov (the upstream history to the vendored commit)@licenseBSL-1.0
expected
:
(alias struct) checkpoint_fault_probe.Expected = sparkles.base.expected.Expected(T, E = string, Hook = Abort) if (!is(E == void) && (isVoidValueEnabled!Hook || !is(T == void)))

``Expected!(T, E) is a type that represents either success or failure.

Type T is used for success value. If T is void, then Expected can only hold error value and is considered a success when there is no error value.

Type E is used for error value. The default type for the error value is string.

Default behavior of Expected can be modified by the Hook template parameter.

@paramT represents type of the expected value@paramE represents type of the error value.@paramHook defines the Expected type behavior
Expected
,
(alias template) checkpoint_fault_probe.ok = sparkles.base.expected.ok(E = string, Hook = Abort, T)(auto ref T value)

Creates an Expected object from an expected value, with type inference.

ok
;
import
(package) sparkles
sparkles
.
(package) sparkles.recovery
recovery
.
(module) sparkles.recovery.archive

Numbered immutable generation files in a recovery archive.

A generation is one opaque payload under a canonical name: 20 decimal digits and the layout's suffix (00000000000000000007.session). An append never replaces a file: it is a create-only atomic write through the capability VFS that syncs the directory (VFO9), so an earlier generation stays readable until a newer one is durably acknowledged. Reads accept only a regular file, never through a link (VFO12). Pruning keeps the newest valid generations at or below an acknowledged cutoff and leaves damaged, unsupported, linked and newer entries alone. A retirement marker records that a generation was adopted elsewhere without touching its bytes.

archive
:
(alias) checkpoint_fault_probe.readGeneration = sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
;
import
(package) sparkles
sparkles
.
(package) sparkles.recovery
recovery
.
(module) sparkles.recovery.directory

Private, durable archive directories with process-shared ownership leases.

A LeasedDirectory is one archive: a private directory created under a base directory with a random name, synced up to a durable namespace root, and held with an exclusive flock for as long as its owner lives. Another process claims it only after the owner closes it or dies, so a crashed session's archive is recovered without two instances writing to it. Linux only, for now: elsewhere every call reports unavailable.

directory
:
(class) sparkles.recovery.directory.LeasedDirectory

One archive's directory lock. Keep this owner alive until its storage work has stopped, then close it explicitly. Other processes can claim an archive only after its owner closes or terminates. Creation and claim serialize against the base directory lock so a half-initialized archive cannot be claimed.

LeasedDirectory
;
import
(package) sparkles
sparkles
.
(package) sparkles.recovery
recovery
.
(module) sparkles.recovery.writer

Coalesced background checkpoints with separately acknowledged revisions.

A host observes its state on the application thread as immutable snapshots and hands the latest to a CheckpointWriter, which keeps one write running and one snapshot waiting. Each write encodes its snapshot on a worker and appends it as a fresh generation (sparkles.recovery.archive); a revision is acknowledged only once its generation is durable, and a failed or unconfirmed write is retried under a new generation, never over the old one.

A snapshot is a class with, found by introspection:

Member Meaning
ulong revision() const increases with each observation; never zero
Expected!string encode(ulong generation) const the payload, on a worker
writer
:
(alias class) checkpoint_fault_probe.CheckpointWriter = sparkles.recovery.writer.CheckpointWriter(Snapshot) if (isSnapshot!Snapshot)

One running write and one latest desired snapshot. The supplied directory's lease transfers to this writer, which closes it only after stopping its worker. File generations increase per attempt, including retries after an unconfirmed commit. Observation revisions identify captured application state separately.

CheckpointWriter
;
import
(package) std
std
.
(module) std.conv

A one-stop shop for converting values from one type to another.

Category Functions
Generic asOriginalType castFrom parse to toChars bitCast
Strings text wtext dtext writeText writeWText writeDText hexString
Numeric octal roundTo signed unsigned
Exceptions ConvException ConvOverflowException

Source

std/conv.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara
conv
:
(alias template) checkpoint_fault_probe.text = std.conv.text(T...)(T args) if (T.length > 0)

Convenience functions for converting one or more arguments of any type into text (the three character widths).

text
;
import
(package) std
std
.
(module) std.stdio
Category Symbols
File handles _popen File isFileHandle openNetwork stderr stdin stdout
Reading chunks lines readf readfln readln
Writing toFile write writef writefln writeln
Misc KeepTerminator LockType StdioException

Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio is publically imported when importing std.stdio.

There are three layers of I/O:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
stdio
:
(alias template) checkpoint_fault_probe.writeln = std.stdio.writeln(T...)(T args)

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
/// A snapshot whose payload is its text. final class
(class) checkpoint_fault_probe.TextSnapshot

A snapshot whose payload is its text.

TextSnapshot
{
(alias) object.string = string
string
(field) string checkpoint_fault_probe.TextSnapshot.text_
text_
;
ulong
(field) ulong checkpoint_fault_probe.TextSnapshot.revision_
revision_
;
this(
checkpoint_fault_probe.TextSnapshot checkpoint_fault_probe.TextSnapshot.this(string text, ulong revision) pure nothrow @safe
string
(parameter) string text
text
, ulong
(parameter) ulong revision
revision
) @safe pure nothrow {
(field) string checkpoint_fault_probe.TextSnapshot.text_
text_
=
(parameter) string text
text
;
(field) ulong checkpoint_fault_probe.TextSnapshot.revision_
revision_
=
(parameter) ulong revision
revision
; }
ulong
ulong checkpoint_fault_probe.TextSnapshot.revision() const pure nothrow @nogc @safe
revision
() const @safe pure nothrow @nogc =>
(field) ulong checkpoint_fault_probe.TextSnapshot.revision_
revision_
;
(struct) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort)

``Expected!(T, E) is a type that represents either success or failure.

Type T is used for success value. If T is void, then Expected can only hold error value and is considered a success when there is no error value.

Type E is used for error value. The default type for the error value is string.

Default behavior of Expected can be modified by the Hook template parameter.

@paramT represents type of the expected value@paramE represents type of the error value.@paramHook defines the Expected type behavior
Expected
!
(alias) object.string = string
string
sparkles.base.expected.Expected!(string, string, Abort) checkpoint_fault_probe.TextSnapshot.encode(ulong __param_0) const nothrow @safe
encode
(ulong) const @safe nothrow
{
(alias) object.string = string
string
(local variable) string payload
payload
=
(field) string checkpoint_fault_probe.TextSnapshot.text_
text_
;
return
sparkles.base.expected.Expected!(string, string, Abort) sparkles.base.expected.ok!(string, sparkles.base.expected.Abort, string)(ref string value) pure nothrow @nogc @safe

Creates an Expected object from an expected value, with type inference.

ok
(
(local variable) string payload
payload
);
} } int
int D main(string[] args) @system
main
(
(alias) object.string = string
string
[]
(parameter) string[] args
args
) @system
{ assert(
(parameter) string[] args
args
.
(field) ulong string[].length
length
== 2, "Pass a prepared private archive directory.");
auto
(local variable) sparkles.base.expected.Expected!(LeasedDirectory, DirectoryIssue, Abort) directory
directory
=
(class) sparkles.recovery.directory.LeasedDirectory

One archive's directory lock. Keep this owner alive until its storage work has stopped, then close it explicitly. Other processes can claim an archive only after its owner closes or terminates. Creation and claim serialize against the base directory lock so a half-initialized archive cannot be claimed.

LeasedDirectory
.
sparkles.base.expected.Expected!(LeasedDirectory, DirectoryIssue, Abort) sparkles.recovery.directory.LeasedDirectory.claim(string path) nothrow @safe

Claim an abandoned archive; an active archive returns a typed busy outcome.

claim
(
(parameter) string[] args
args
[1]);
assert(
(local variable) sparkles.base.expected.Expected!(LeasedDirectory, DirectoryIssue, Abort) directory
directory
.
bool sparkles.base.expected.Expected!(sparkles.recovery.directory.LeasedDirectory, sparkles.recovery.directory.DirectoryIssue, sparkles.base.expected.Abort).hasValue!()() const pure nothrow @nogc @property @safe

Checks if Expected has value

hasValue
);
auto
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
= new
(class) sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot)

One running write and one latest desired snapshot. The supplied directory's lease transfers to this writer, which closes it only after stopping its worker. File generations increase per attempt, including retries after an unconfirmed commit. Observation revisions identify captured application state separately.

CheckpointWriter
!
(class) checkpoint_fault_probe.TextSnapshot

A snapshot whose payload is its text.

TextSnapshot
(
(local variable) sparkles.base.expected.Expected!(LeasedDirectory, DirectoryIssue, Abort) directory
directory
.
inout(sparkles.recovery.directory.LeasedDirectory) sparkles.base.expected.Expected!(sparkles.recovery.directory.LeasedDirectory, sparkles.recovery.directory.DirectoryIssue, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
);
scope (exit)
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).shutdown() nothrow @safe

Drain accepted writes and publish receipts before releasing the lease. Newer unsubmitted snapshots still require flush before orderly closure.

shutdown
();
const
(local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clock
clock
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The current time of the system's monotonic clock. This has no relation to the wall clock time, as the wall clock time can be adjusted (e.g. by NTP), whereas the monotonic clock always moves forward. The source of the monotonic time is system-specific.

On Windows, QueryPerformanceCounter is used. On Mac OS X, mach_absolute_time is used, while on other POSIX systems, clock_gettime is used.

Warning: On some systems, the monotonic clock may stop counting when the computer goes to sleep or hibernates. So, the monotonic clock may indicate less time than has actually passed if that occurs. This is known to happen on Mac OS X. It has not been tested whether it occurs on either Windows or Linux.

currTime
;
void
void checkpoint_fault_probe.main.drain() nothrow @system
drain
() @system
{ const
(local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) deadline
deadline
=
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The current time of the system's monotonic clock. This has no relation to the wall clock time, as the wall clock time can be adjusted (e.g. by NTP), whereas the monotonic clock always moves forward. The source of the monotonic time is system-specific.

On Windows, QueryPerformanceCounter is used. On Mac OS X, mach_absolute_time is used, while on other POSIX systems, clock_gettime is used.

Warning: On some systems, the monotonic clock may stop counting when the computer goes to sleep or hibernates. So, the monotonic clock may indicate less time than has actually passed if that occurs. This is known to happen on Mac OS X. It has not been tested whether it occurs on either Windows or Linux.

currTime
+ 5.seconds;
while (
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).busy() const pure nothrow @nogc @safe

Whether a write is running.

busy
&&
(struct) core.time.MonoTimeImpl!(ClockType.normal)
MonoTime
.
core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trusted

The current time of the system's monotonic clock. This has no relation to the wall clock time, as the wall clock time can be adjusted (e.g. by NTP), whereas the monotonic clock always moves forward. The source of the monotonic time is system-specific.

On Windows, QueryPerformanceCounter is used. On Mac OS X, mach_absolute_time is used, while on other POSIX systems, clock_gettime is used.

Warning: On some systems, the monotonic clock may stop counting when the computer goes to sleep or hibernates. So, the monotonic clock may indicate less time than has actually passed if that occurs. This is known to happen on Mac OS X. It has not been tested whether it occurs on either Windows or Linux.

currTime
<
int core.time.MonoTimeImpl!(ClockType.normal).opCmp(core.time.MonoTimeImpl!(ClockType.normal) rhs) const pure nothrow @nogc @safe

Compares this MonoTime with the given MonoTime.

@returns| this &lt; rhs | &lt; 0 | | this == rhs | 0 | | this &gt; rhs | &gt; 0 |
deadline
)
{
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).poll(core.time.MonoTimeImpl!(ClockType.normal) now = currTime()) nothrow @safe

Drain worker receipts, then submit the latest due state without encoding on this thread.

poll
(
(local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clock
clock
);
(class) core.thread.osthread.Thread

This class encapsulates all threading functionality for the D programming language. As thread manipulation is a required facility for garbage collection, all user threads should derive from this class, and instances of this class should never be explicitly deleted. A new thread may be created using either derivation or composition, as in the following example.

Thread
.
void core.thread.osthread.Thread.yield() nothrow @nogc

Forces a context switch to occur away from the calling thread.

yield
();
} assert(!
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).busy() const pure nothrow @nogc @safe

Whether a write is running.

busy
, "The worker did not complete.");
}
(alias) object.string = string
string
(local variable) string contents
contents
;
foreach (
(local variable) ulong revision
revision
; 1UL .. 5UL)
{
(local variable) string contents
contents
~=
string std.conv.text!ulong(ulong __param_0) pure nothrow @safe

Convenience functions for converting one or more arguments of any type into text (the three character widths).

text
(
(local variable) ulong revision
revision
);
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).request(checkpoint_fault_probe.TextSnapshot snapshot, core.time.MonoTimeImpl!(ClockType.normal) now = currTime()) nothrow @safe

Retain the latest immutable state; continuous input never postpones its existing deadline.

request
(new
(class) checkpoint_fault_probe.TextSnapshot

A snapshot whose payload is its text.

TextSnapshot
(
(local variable) string contents
contents
,
(local variable) ulong revision
revision
),
(local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clock
clock
);
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).flush(core.time.MonoTimeImpl!(ClockType.normal) now = currTime()) nothrow @safe

Request immediate completion of current state, including a later snapshot behind a running write.

flush
(
(local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clock
clock
);
void checkpoint_fault_probe.main.drain() nothrow @system
drain
();
if (
(local variable) ulong revision
revision
< 4) assert(!
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).pending() const pure nothrow @nogc @safe

Whether a requested revision is not yet durable.

pending
&&
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
ulong sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).durableRevision() const pure nothrow @nogc @safe

The newest revision whose generation is durable.

durableRevision
==
(local variable) ulong revision
revision
);
} assert(
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).pending() const pure nothrow @nogc @safe

Whether a requested revision is not yet durable.

pending
&&
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
string sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).error() const pure nothrow @nogc @safe

The latest failure, until a write succeeds.

error
.
(field) ulong string.length
length
&&
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
ulong sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).durableRevision() const pure nothrow @nogc @safe

The newest revision whose generation is durable.

durableRevision
== 3);
assert(
sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
(
(parameter) string[] args
args
[1], 4).
inout(string) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
== "1234", "the unconfirmed generation is kept");
assert(
sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
(
(parameter) string[] args
args
[1], 3).
inout(string) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
== "123");
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).flush(core.time.MonoTimeImpl!(ClockType.normal) now = currTime()) nothrow @safe

Request immediate completion of current state, including a later snapshot behind a running write.

flush
(
(local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clock
clock
);
void checkpoint_fault_probe.main.drain() nothrow @system
drain
();
assert(!
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).pending() const pure nothrow @nogc @safe

Whether a requested revision is not yet durable.

pending
&&
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
ulong sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).durableRevision() const pure nothrow @nogc @safe

The newest revision whose generation is durable.

durableRevision
== 4 &&
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
ulong sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).durableGeneration() const pure nothrow @nogc @safe

That generation.

durableGeneration
== 5);
assert(!
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writer
writer
.
string sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).error() const pure nothrow @nogc @safe

The latest failure, until a write succeeds.

error
.
(field) ulong string.length
length
);
assert(
sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
(
(parameter) string[] args
args
[1], 5).
inout(string) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
== "1234");
assert(
sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
(
(parameter) string[] args
args
[1], 4).
bool sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).hasValue!()() const pure nothrow @nogc @property @safe

Checks if Expected has value

hasValue
);
void std.stdio.writeln!string(string __param_0) @safe

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("unconfirmed generation retained; retry used generation 5; revision 4 acknowledged");
return 0; }