#!/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_probeReal worker-thread directory-sync failure followed by a new immutable retry generation.
checkpoint_fault_probe;
import (package) corecore.(module) core.threadThe thread module provides support for thread creation and management.
Source
core/thread/package.d
thread : (class) core.thread.osthread.ThreadThis 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) corecore.(module) core.timeModule 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
time : (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime, seconds;
import (package) sparklessparkles.(package) sparkles.basebase.(module) sparkles.base.expectedThis 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);
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.
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) sparklessparkles.(package) sparkles.recoveryrecovery.(module) sparkles.recovery.archiveNumbered 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 @safeThe payload of generation, read only from a regular file.
readGeneration;
import (package) sparklessparkles.(package) sparkles.recoveryrecovery.(module) sparkles.recovery.directoryPrivate, 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.LeasedDirectoryOne 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) sparklessparkles.(package) sparkles.recoveryrecovery.(module) sparkles.recovery.writerCoalesced 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) stdstd.(module) std.convA 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
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) stdstd.(module) std.stdioCategory 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:
The lowest layer is the operating system layer. The two main schemes are Windows and Posix.
C's stdio.h which unifies the two operating system schemes.
std.stdio, this module, unifies the various stdio.h implementations into
a high level package for D programs.
Source
std/stdio.d
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);
}
}
writeln;
/// A snapshot whose payload is its text.
final class (class) checkpoint_fault_probe.TextSnapshotA snapshot whose payload is its text.
TextSnapshot
{
(alias) object.string = stringstring (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 @safestring (parameter) string texttext, ulong (parameter) ulong revisionrevision) @safe pure nothrow { (field) string checkpoint_fault_probe.TextSnapshot.text_text_ = (parameter) string texttext; (field) ulong checkpoint_fault_probe.TextSnapshot.revision_revision_ = (parameter) ulong revisionrevision; }
ulong ulong checkpoint_fault_probe.TextSnapshot.revision() const pure nothrow @nogc @saferevision() 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.
Expected!(alias) object.string = stringstring sparkles.base.expected.Expected!(string, string, Abort) checkpoint_fault_probe.TextSnapshot.encode(ulong __param_0) const nothrow @safeencode(ulong) const @safe nothrow
{
(alias) object.string = stringstring (local variable) string payloadpayload = (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 @safeCreates an Expected object from an expected value, with type inference.
ok((local variable) string payloadpayload);
}
}
int int D main(string[] args) @systemmain((alias) object.string = stringstring[] (parameter) string[] argsargs) @system
{
assert((parameter) string[] argsargs.(field) ulong string[].lengthlength == 2, "Pass a prepared private archive directory.");
auto (local variable) sparkles.base.expected.Expected!(LeasedDirectory, DirectoryIssue, Abort) directorydirectory = (class) sparkles.recovery.directory.LeasedDirectoryOne 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 @safeClaim an abandoned archive; an active archive returns a typed busy outcome.
claim((parameter) string[] argsargs[1]);
assert((local variable) sparkles.base.expected.Expected!(LeasedDirectory, DirectoryIssue, Abort) directorydirectory.bool sparkles.base.expected.Expected!(sparkles.recovery.directory.LeasedDirectory, sparkles.recovery.directory.DirectoryIssue, sparkles.base.expected.Abort).hasValue!()() const pure nothrow @nogc @property @safeChecks if Expected has value
hasValue);
auto (local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter = 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.TextSnapshotA snapshot whose payload is its text.
TextSnapshot((local variable) sparkles.base.expected.Expected!(LeasedDirectory, DirectoryIssue, Abort) directorydirectory.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 @safeReturns 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) writerwriter.void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).shutdown() nothrow @safeDrain 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)) clockclock = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe 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 @systemdrain() @system
{
const (local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) deadlinedeadline = (struct) core.time.MonoTimeImpl!(ClockType.normal)MonoTime.core.time.MonoTimeImpl!(ClockType.normal) core.time.MonoTimeImpl!(ClockType.normal).currTime() nothrow @nogc @property @trustedThe 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) writerwriter.bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).busy() const pure nothrow @nogc @safeWhether 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 @trustedThe 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 @safeCompares this MonoTime with the given MonoTime.
deadline)
{
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).poll(core.time.MonoTimeImpl!(ClockType.normal) now = currTime()) nothrow @safeDrain worker receipts, then submit the latest due state without encoding on this thread.
poll((local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clockclock);
(class) core.thread.osthread.ThreadThis 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 @nogcForces a context switch to occur away from the calling thread.
yield();
}
assert(!(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).busy() const pure nothrow @nogc @safeWhether a write is running.
busy, "The worker did not complete.");
}
(alias) object.string = stringstring (local variable) string contentscontents;
foreach ((local variable) ulong revisionrevision; 1UL .. 5UL)
{
(local variable) string contentscontents ~= string std.conv.text!ulong(ulong __param_0) pure nothrow @safeConvenience functions for converting one or more arguments
of any type into text (the three character widths).
text((local variable) ulong revisionrevision);
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).request(checkpoint_fault_probe.TextSnapshot snapshot, core.time.MonoTimeImpl!(ClockType.normal) now = currTime()) nothrow @safeRetain the latest immutable state; continuous input never postpones its existing deadline.
request(new (class) checkpoint_fault_probe.TextSnapshotA snapshot whose payload is its text.
TextSnapshot((local variable) string contentscontents, (local variable) ulong revisionrevision), (local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clockclock);
(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).flush(core.time.MonoTimeImpl!(ClockType.normal) now = currTime()) nothrow @safeRequest immediate completion of current state, including a later snapshot behind a running write.
flush((local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clockclock);
void checkpoint_fault_probe.main.drain() nothrow @systemdrain();
if ((local variable) ulong revisionrevision < 4) assert(!(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).pending() const pure nothrow @nogc @safeWhether a requested revision is not yet durable.
pending && (local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.ulong sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).durableRevision() const pure nothrow @nogc @safeThe newest revision whose generation is durable.
durableRevision == (local variable) ulong revisionrevision);
}
assert((local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).pending() const pure nothrow @nogc @safeWhether a requested revision is not yet durable.
pending && (local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.string sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).error() const pure nothrow @nogc @safeThe latest failure, until a write succeeds.
error.(field) ulong string.lengthlength && (local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.ulong sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).durableRevision() const pure nothrow @nogc @safeThe 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 @safeThe payload of generation, read only from a regular file.
readGeneration((parameter) string[] argsargs[1], 4).inout(string) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safeReturns 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 @safeThe payload of generation, read only from a regular file.
readGeneration((parameter) string[] argsargs[1], 3).inout(string) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safeReturns 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) writerwriter.void sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).flush(core.time.MonoTimeImpl!(ClockType.normal) now = currTime()) nothrow @safeRequest immediate completion of current state, including a later snapshot behind a running write.
flush((local variable) const(core.time.MonoTimeImpl!(ClockType.normal)) clockclock);
void checkpoint_fault_probe.main.drain() nothrow @systemdrain();
assert(!(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.bool sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).pending() const pure nothrow @nogc @safeWhether a requested revision is not yet durable.
pending && (local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.ulong sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).durableRevision() const pure nothrow @nogc @safeThe newest revision whose generation is durable.
durableRevision == 4 && (local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.ulong sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).durableGeneration() const pure nothrow @nogc @safeThat generation.
durableGeneration == 5);
assert(!(local variable) sparkles.recovery.writer.CheckpointWriter!(TextSnapshot) writerwriter.string sparkles.recovery.writer.CheckpointWriter!(checkpoint_fault_probe.TextSnapshot).error() const pure nothrow @nogc @safeThe latest failure, until a write succeeds.
error.(field) ulong string.lengthlength);
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 @safeThe payload of generation, read only from a regular file.
readGeneration((parameter) string[] argsargs[1], 5).inout(string) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safeReturns 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 @safeThe payload of generation, read only from a regular file.
readGeneration((parameter) string[] argsargs[1], 4).bool sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).hasValue!()() const pure nothrow @nogc @property @safeChecks if Expected has value
hasValue);
void std.stdio.writeln!string(string __param_0) @safeEquivalent 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);
}
}
writeln("unconfirmed generation retained; retry used generation 5; revision 4 acknowledged");
return 0;
}