This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// QuorumSystem describes a read-write quorum system. | |
type QuorumSystem struct { | |
// reads describes the read-quorum. | |
reads Expr | |
// writes describes the write-quorum. | |
writes Expr | |
// nameToNode keeps track the name of a node to a GetNodeByName. | |
nameToNode nameToNode | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ExprOperator that wraps the Add and Multiply methods needed to build a quorum from a set of Node. | |
type ExprOperator interface { | |
// Add method aggregate a Node to an Expr with a logical Or (a ∨ b) | |
// returns the resulting Or operation. | |
Add(expr Expr) Or | |
// Multiply method aggregate a Node to an Expr with a logical And (a ∧ b) | |
// returns the resulting And operation. | |
Multiply(expr Expr) And | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(nodes: List[Node[T]], | |
read_fraction: Optional[Distribution] = None, | |
write_fraction: Optional[Distribution] = None, | |
optimize: str = LOAD, | |
resilience: int = 0, | |
load_limit: Optional[float] = None, | |
network_limit: Optional[float] = None, | |
latency_limit: Optional[datetime.timedelta] = None, | |
f: int = 0, | |
timeout: datetime.timedelta = datetime.timedelta(seconds=0)) \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/d83a811a905a51fc13ebc00ddac036d559463380/quoracle/quorum_system.py#L276 | |
""" | |
def _f_resilient_quorums(self, | |
f: int, | |
xs: List[T], | |
e: Expr) -> Iterator[Set[T]]: | |
""" | |
Consider a set X of elements in xs. We say X is f-resilient if, despite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/master/quoracle/quorum_system.py#L639 | |
""" | |
class Strategy(Generic[T]): | |
# ... | |
def load(self, | |
read_fraction: Optional[Distribution] = None, | |
write_fraction: Optional[Distribution] = None) -> float: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/master/quoracle/quorum_system.py#L622 | |
""" | |
class Strategy(Generic[T]): | |
# ... | |
def quorum_system(self) -> QuorumSystem[T]: | |
return self.qs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/main/quoracle/quorum_system.py#L596 | |
""" | |
class Strategy(Generic[T]): | |
def __init__(self, | |
qs: QuorumSystem[T], | |
sigma_r: Dict[FrozenSet[T], float], | |
sigma_w: Dict[FrozenSet[T], float]) -> None: | |
self.qs = qs | |
self.sigma_r = sigma_r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/d83a811a905a51fc13ebc00ddac036d559463380/quoracle/quorum_system.py#L509 | |
""" | |
def latency() -> pulp.LpAffineExpression: | |
reads = fr * sum( | |
v * self._read_quorum_latency(quorum).total_seconds() | |
for (rq, v) in zip(read_quorums, read_quorum_vars) | |
for quorum in [{self.node(x) for x in rq}] | |
) | |
writes = (1 - fr) * sum( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/master/quoracle/quorum_system.py#L498 | |
""" | |
def network() -> pulp.LpAffineExpression: | |
reads = fr * sum( | |
v * len(rq) | |
for (rq, v) in zip(read_quorums, read_quorum_vars) | |
) | |
writes = (1 - fr) * sum( | |
v * len(wq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Original code available at: https://github.com/mwhittaker/quoracle/blob/main/quoracle/quorum_system.py#L541 | |
''' | |
#... | |
def load(problem: pulp.LpProblem, | |
read_fraction: Dict[float, float]) -> pulp.LpAffineExpression: | |
return sum(p * fr_load(problem, fr) | |
for (fr, p) in read_fraction.items()) |