Sign in

    moonbitstack/moonrpc/balance does not have a README file

    Attempts

    pub struct Attempts {
    // private fields
    }

    One call's retry state across its attempts.

    Attempts::made

    fn Attempts::made(self : Attempts) -> Int

    Attempts sent under the policy so far, the first being 1. Transparent retries are not counted.

    Attempts::new

    fn Attempts::new(retry? : Retry, throttle? : Throttle, limit? : Int) -> Attempts

    The state before the first attempt. Without retry the call is still retried transparently, as A6 asks of every call.

    Attempts::next

    fn Attempts::next(self : Attempts, status : Int, trailers : ArrayView[
    Header
    ], committed? : Bool, unprocessed? : Bool, roll? : Double) ->
    Span
    ?

    What to do after an attempt ended with status and trailers: None hands this result to the caller, Some(wait) sends another attempt after wait.

    committed is a call whose response headers arrived, which A6 never retries; unprocessed is one the server refused or a GOAWAY says it never handled, which is retried once at once without counting. roll draws the jitter, from [0, 1). The order of the checks is grpc-go's.

    ConnectionPool

    pub struct ConnectionPool {
    order : Array[String]
    subconns : Map[String, SubConn]
    policy : LbPolicy
    cursor : Int
    }

    A pool of sub-connections, one per resolved address (in resolver order), that picks a READY one per an LbPolicy.

    ConnectionPool::new

    fn ConnectionPool::new(addresses : Array[String], policy? : LbPolicy) -> ConnectionPool

    A pool over addresses (each a host:port), each sub-connection starting IDLE, choosing among the READY ones with policy (default PickFirst).

    ConnectionPool::pick

    fn ConnectionPool::pick(self : ConnectionPool) -> String?

    Pick a READY sub-connection's address for the next call, applying the LB policy over just the ready ones (← gRPC picker). None when no sub-connection is ready.

    ConnectionPool::ready_addresses

    fn ConnectionPool::ready_addresses(self : ConnectionPool) -> Array[String]

    The addresses of every READY sub-connection, in resolver order.

    ConnectionPool::subconn

    fn ConnectionPool::subconn(self : ConnectionPool, address : String) -> SubConn?

    The sub-connection for address, if the pool has one — the handle the Channel drives.

    ConnectivityState

    pub(all) enum ConnectivityState {
    Idle
    Connecting
    Ready
    TransientFailure
    Shutdown
    } derive(Eq,
    Debug
    )

    A sub-connection's connectivity state (← gRPC connectivity.State).

    ConnectivityState::equal

    ConnectivityState::not_equal

    fn ConnectivityState::not_equal(x : ConnectivityState, y : ConnectivityState) -> Bool

    DnsRecord

    pub(all) struct DnsRecord {
    name : String
    rtype : Int
    ttl : Int
    address : String
    } derive(Eq,
    Debug
    )

    One answer resource record, carrying the textual address for A/AAAA records (empty for other types).

    DnsRecord::equal

    fn DnsRecord::equal(DnsRecord, DnsRecord) -> Bool

    DnsRecord::not_equal

    fn DnsRecord::not_equal(x : DnsRecord, y : DnsRecord) -> Bool

    DnsResponse

    pub(all) struct DnsResponse {
    id : Int
    rcode : Int
    answers : Array[DnsRecord]
    } derive(Eq,
    Debug
    )

    A decoded DNS response: the transaction id echoed back, the response code (0 = NOERROR), and the answer records.

    DnsResponse::addresses

    fn DnsResponse::addresses(self : DnsResponse) -> Array[String]

    Every resolved A/AAAA address in the response, in record order.

    DnsResponse::equal

    fn DnsResponse::equal(DnsResponse, DnsResponse) -> Bool

    DnsResponse::not_equal

    fn DnsResponse::not_equal(x : DnsResponse, y : DnsResponse) -> Bool

    Hedging

    A method's hedging policy (A6 hedgingPolicy): attempts is maxAttempts, delay is hedgingDelay, codes is nonFatalStatusCodes.

    Hedging::commits

    fn Hedging::commits(self : Hedging, status : Int) -> Bool

    Whether an attempt ending with status settles the call: OK does, and so does any status outside codes. A non-fatal one sends the next attempt at once instead.

    Hedging::equal

    fn Hedging::equal(Hedging, Hedging) -> Bool

    Hedging::more

    fn Hedging::more(self : Hedging, started : Int, limit? : Int) -> Bool

    Whether another attempt may start when started have, under the policy and the client's limit.

    Hedging::new

    A policy by A6's field names.

    Hedging::not_equal

    fn Hedging::not_equal(x : Hedging, y : Hedging) -> Bool

    Hedging::to_repr

    LbPolicy

    pub(all) enum LbPolicy {
    PickFirst
    RoundRobin
    } derive(Eq,
    Debug
    )

    A client-side load-balancing policy (← gRPC loadBalancingConfig).

    LbPolicy::equal

    fn LbPolicy::equal(LbPolicy, LbPolicy) -> Bool

    LbPolicy::not_equal

    fn LbPolicy::not_equal(x : LbPolicy, y : LbPolicy) -> Bool

    LbPolicy::to_repr

    LoadBalancer

    pub struct LoadBalancer {
    addresses : Array[String]
    policy : LbPolicy
    cursor : Int
    }

    A load balancer over a resolver's addresses, applying an LbPolicy to choose the next one.

    LoadBalancer::new

    fn LoadBalancer::new(addresses : Array[String], policy? : LbPolicy) -> LoadBalancer

    A balancer over addresses (each a host:port) using policy (default PickFirst).

    LoadBalancer::pick

    fn LoadBalancer::pick(self : LoadBalancer) -> String?

    The address the next call should use, or None when the resolver produced none. PickFirst always returns the first address; RoundRobin returns each in turn, wrapping around.

    LoadBalancer::size

    fn LoadBalancer::size(self : LoadBalancer) -> Int

    The number of addresses the balancer is choosing among.

    Pushback

    pub(all) enum Pushback {
    Absent
    After(
    Span
    )
    Stop
    } derive(Eq,
    Debug
    )

    What the server said about trying again, in grpc-retry-pushback-ms.

    Pushback::equal

    fn Pushback::equal(Pushback, Pushback) -> Bool

    Pushback::not_equal

    fn Pushback::not_equal(x : Pushback, y : Pushback) -> Bool

    Pushback::read

    The pushback a reply's trailers carry.

    Pushback::to_repr

    Retry

    A method's retry policy (A6 retryPolicy). backoff carries maxAttempts as attempts, initialBackoff as base, maxBackoff as cap and backoffMultiplier as factor; codes is retryableStatusCodes.

    Retry::equal

    fn Retry::equal(Retry, Retry) -> Bool

    Retry::new

    fn Retry::new(attempts? : Int, base? :
    Span
    , cap? :
    Span
    , factor? : Double, codes? : Array[
    Status
    ]) -> Retry

    A policy by A6's field names, the jitter the preset's.

    Retry::not_equal

    fn Retry::not_equal(x : Retry, y : Retry) -> Bool

    Retry::to_repr

    SubConn

    pub struct SubConn {
    address : String
    state : ConnectivityState
    }

    One address the Channel dials, tracking its connectivity state.

    SubConn::connect

    fn SubConn::connect(self : SubConn) -> Unit

    Begin connecting (IDLE or TRANSIENT_FAILURE → CONNECTING). A no-op once SHUTDOWN or already connecting/ready.

    SubConn::is_ready

    fn SubConn::is_ready(self : SubConn) -> Bool

    Whether this sub-connection can carry RPCs right now.

    SubConn::new

    fn SubConn::new(address : String) -> SubConn

    A fresh sub-connection to address, starting IDLE.

    SubConn::on_connected

    fn SubConn::on_connected(self : SubConn) -> Unit

    The connection attempt succeeded (CONNECTING → READY).

    SubConn::on_failure

    fn SubConn::on_failure(self : SubConn) -> Unit

    A connection attempt or an established connection failed (→ TRANSIENT_FAILURE), unless shut down.

    SubConn::on_idle

    fn SubConn::on_idle(self : SubConn) -> Unit

    A READY connection went idle (READY → IDLE).

    SubConn::shutdown

    fn SubConn::shutdown(self : SubConn) -> Unit

    Shut the sub-connection down permanently (→ SHUTDOWN, a terminal state).

    Throttle

    pub struct Throttle {
    // private fields
    }

    The token count one server name shares across every call to it. A failure takes a token, a success gives back ratio, and at or below half the maximum no call is retried or hedged. Kept in thousandths of a token as gRPC core keeps it, so a ratio is read to three decimal places and nothing drifts.

    Throttle::allows

    fn Throttle::allows(self : Throttle) -> Bool

    Whether a retry or a further hedge may go out.

    Throttle::fail

    fn Throttle::fail(self : Throttle) -> Unit

    A call that failed with a retryable status, or that the server pushed back.

    Throttle::new

    fn Throttle::new(throttling : Throttling) -> Throttle

    A throttle starting full.

    Throttle::pass

    fn Throttle::pass(self : Throttle) -> Unit

    A call that succeeded.

    Throttle::tokens

    fn Throttle::tokens(self : Throttle) -> Double

    The tokens left.

    Throttling

    pub(all) struct Throttling {
    tokens : Int
    ratio : Double
    } derive(Eq,
    Debug
    )

    Retry throttling (A6 retryThrottling): tokens is maxTokens, ratio is tokenRatio. There is no preset, because a channel without one does not throttle.

    Throttling::equal

    fn Throttling::equal(Throttling, Throttling) -> Bool

    Throttling::new

    fn Throttling::new(tokens~ : Int, ratio~ : Double) -> Throttling

    Throttling by name.

    Throttling::not_equal

    fn Throttling::not_equal(x : Throttling, y : Throttling) -> Bool

    dns_decode_response

    fn dns_decode_response(msg : Bytes) -> DnsResponse

    Decode a DNS response: echoed id, response code, and every answer record (A/AAAA records carry their textual address). Questions are skipped; authority and additional sections are ignored.

    dns_encode_query

    fn dns_encode_query(id : Int, name : String, qtype : Int) -> Bytes

    Encode a standard recursion-desired query for name of type qtype (dns_type_a or dns_type_aaaa) in class IN, with transaction id id.

    dns_type_a

    let dns_type_a : Int

    The DNS record type for an IPv4 address.

    dns_type_aaaa

    let dns_type_aaaa : Int

    The DNS record type for an IPv6 address.

    hedging

    let hedging : Hedging

    A6's example policy: four attempts half a second apart, UNAVAILABLE, INTERNAL and ABORTED letting the others carry on.

    limit

    let limit : Int

    The most attempts a client makes whatever a policy asks for. A6 puts it on the client because a service config can arrive over DNS.

    retry

    let retry : Retry

    A6's example policy: four attempts, a hundred milliseconds doubling to a second with a fifth either way, retrying UNAVAILABLE.