Skip to content

Commit 4de8242

Browse files
committed
Rename distributed.sync configuration to replicas
Also adds the "one" and "majority" options.
1 parent 04f64ef commit 4de8242

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

Diff for: config.example.toml

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ address = "127.0.0.1:8080"
1616
[distributed]
1717
# Address to listen on for peer connections.
1818
peer_address = "127.0.0.1:9001"
19-
# Type of synchronisation of the blobs between nodes, available methods:
20-
# - `full': all nodes store all blobs (default).
21-
sync = "full"
19+
# The amount of replicas of the blob stored, available options:
20+
# - `all': all nodes store all blobs (default). Highest availability, lowest
21+
# chance of data lost, but highest amount of storage used.
22+
# - `one': a single node stores a blob. Lowest availability, highest chance of
23+
# data lost, but lowest amount of storage used.
24+
# - `majority': (N/2)+1 nodes store a blob, where N is the total number of nodes
25+
# in the system. Medium availability, medium chance of data lost, medium
26+
# amount of storage used.
27+
replicas = "all"
2228
# Addresses of peers to connect to.
2329
# Note that these don't need to contain all addresses, a single address of the
2430
# entire group is enough as each will automatically share all known peers.

Diff for: src/bin/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn try_main() -> Result<(), ExitCode> {
6868
distributed_config.peer_address
6969
);
7070
info!("connecting to peers: {}", distributed_config.peers);
71-
info!("synchronisation method: {}", distributed_config.sync);
71+
info!("blob replication method: {}", distributed_config.replicas);
7272
}
7373

7474
runtime

Diff for: src/config.rs

+33-24
Original file line numberDiff line numberDiff line change
@@ -94,60 +94,69 @@ impl Default for Http {
9494
#[derive(Deserialize, Debug)]
9595
pub struct Distributed {
9696
pub peer_address: SocketAddr,
97-
pub sync: Sync,
97+
pub replicas: Replicas,
9898
pub peers: Peers,
9999
}
100100

101-
/// Type of synchronisation of the blobs between nodes.
101+
/// The amount of replicas of the blob stored.
102102
#[derive(Copy, Clone, Debug)]
103-
pub enum Sync {
104-
/// Full synchronisation: all nodes store all blobs (default).
105-
Full,
103+
pub enum Replicas {
104+
/// All nodes store all blobs (default).
105+
All,
106+
/// A single node stores a blob.
107+
One,
108+
/// `(N/2)+1` nodes store a blob, where `N` is the total number of nodes in
109+
/// the system.
110+
Majority,
106111
}
107112

108-
impl Default for Sync {
109-
fn default() -> Sync {
110-
Sync::Full
113+
impl Default for Replicas {
114+
fn default() -> Replicas {
115+
Replicas::All
111116
}
112117
}
113118

114-
impl fmt::Display for Sync {
119+
impl fmt::Display for Replicas {
115120
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
116121
match self {
117-
Sync::Full => f.write_str("full"),
122+
Replicas::All => f.write_str("all"),
123+
Replicas::One => f.write_str("one"),
124+
Replicas::Majority => f.write_str("majority"),
118125
}
119126
}
120127
}
121128

122-
/// Error returned by `FromStr` implementation for [`Sync`].
123-
pub struct ParseSyncErr(());
129+
/// Error returned by `FromStr` implementation for [`Replicas`].
130+
pub struct ParseReplicasErr(());
124131

125-
impl fmt::Display for ParseSyncErr {
132+
impl fmt::Display for ParseReplicasErr {
126133
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
127-
f.write_str("invalid synchronisation method")
134+
f.write_str("invalid replicas")
128135
}
129136
}
130137

131-
impl FromStr for Sync {
132-
type Err = ParseSyncErr;
138+
impl FromStr for Replicas {
139+
type Err = ParseReplicasErr;
133140

134141
fn from_str(s: &str) -> Result<Self, Self::Err> {
135142
match s {
136-
"full" => Ok(Sync::Full),
137-
_ => Err(ParseSyncErr(())),
143+
"all" => Ok(Replicas::All),
144+
"one" => Ok(Replicas::One),
145+
"majority" => Ok(Replicas::Majority),
146+
_ => Err(ParseReplicasErr(())),
138147
}
139148
}
140149
}
141150

142-
impl<'de> Deserialize<'de> for Sync {
151+
impl<'de> Deserialize<'de> for Replicas {
143152
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
144153
where
145154
D: Deserializer<'de>,
146155
{
147-
struct SyncVisitor;
156+
struct ReplicasVisitor;
148157

149-
impl<'de> Visitor<'de> for SyncVisitor {
150-
type Value = Sync;
158+
impl<'de> Visitor<'de> for ReplicasVisitor {
159+
type Value = Replicas;
151160

152161
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
153162
formatter.write_str("a string")
@@ -157,11 +166,11 @@ impl<'de> Deserialize<'de> for Sync {
157166
where
158167
E: Error,
159168
{
160-
Sync::from_str(s).map_err(Error::custom)
169+
Replicas::from_str(s).map_err(Error::custom)
161170
}
162171
}
163172

164-
deserializer.deserialize_str(SyncVisitor)
173+
deserializer.deserialize_str(ReplicasVisitor)
165174
}
166175
}
167176

0 commit comments

Comments
 (0)