todc-net
Algorithms for message-passing (HTTP) distributed systems.
Examples
In the following example, we create a single instance of the register that
will expose read and write operations as HTTP requests to /register
. For
this example, our register will hold a type String
.
We can use hyper
to run a local instance of the register as follows:
use SocketAddr;
use ;
use ;
use ;
use http1;
use ;
use TokioIo;
use TcpListener;
use AtomicRegister;
// The contents of the register
type Contents = String;
// The main router for our server
async
async
Interacting with a Register
Although this register isn't fault-tolerant yet, we can still try it out. See
the runnable example at todc-net/examples/atomic-register-hyper
.
Adding Fault Tolerance with Multiple Instances
To make our register fault tolerant, we need to add more instances. Suppose that
we want 3
instances, so that even if one instance fails the register will
continue to be available.
If we have configured our infrastructure so that for each i
in [1, 2, 3]
the
server hosting instance i
will be available at https://my-register-{i}.com
, and
we have exposed i
as an environmental variable INSTANCE_ORDINAL
, then we
can instantiate the AtomicRegister
as follows:
use env;
// Replacement for `let register = AtomicRegister::default();`
let instance_ordinal: u32 = var.unwrap.parse.unwrap;
let neighbor_urls: =
.filter
.map
.collect;
let register: = new;
Interacting with a Fault Tolerant Register
To interact with a fault-tolerant register backed by multiple instances, see
the runnable example at
todc-net/examples/atomic-register-docker-minikube
.
Development
Some tests make use of turmoil to simulate latency and failures within a network. To run tests that require this feature, do:
cargo test --features turmoil --test MODULE