Sign in

    moonbitstack/moonzero/etcd does not have a README file

    EtcdError

    pub suberror EtcdError {
    EtcdError(String)
    }

    An etcd gRPC call that returned a non-OK grpc-status.

    EtcdClient

    pub struct EtcdClient {
    channel :
    RpcChannel

    }

    An etcd v3 client bound to a gRPC channel (real etcd, or a mock server in tests).

    EtcdClient::delete_range

    fn EtcdClient::delete_range(self : EtcdClient, req : EtcdDeleteRangeRequest) -> EtcdDeleteRangeResponse raise

    KV.DeleteRange: delete the key or range in req (deregister).

    EtcdClient::lease_grant

    fn EtcdClient::lease_grant(self : EtcdClient, req : EtcdLeaseGrantRequest) -> EtcdLeaseGrantResponse raise

    Lease.LeaseGrant: obtain a lease with the requested TTL.

    EtcdClient::new

    An etcd client over channel.

    EtcdClient::put

    fn EtcdClient::put(self : EtcdClient, req : EtcdPutRequest) -> EtcdPutResponse raise

    KV.Put: store the key/value (optionally under a lease) in req.

    EtcdClient::range

    fn EtcdClient::range(self : EtcdClient, req : EtcdRangeRequest) -> EtcdRangeResponse raise

    KV.Range: read the key or prefix range in req.

    EtcdClient::watch

    fn EtcdClient::watch(self : EtcdClient, req : EtcdWatchRequest) -> Array[EtcdWatchResponse] raise

    Watch.Watch: open a watch with req and read the stream of responses the server produces (etcd's Watch is a bidi stream; this drives the common open-then-observe direction over the server-streaming path). Each WatchResponse carries the batch of change events since the last one.

    EtcdDeleteRangeRequest

    pub(all) struct EtcdDeleteRangeRequest {
    key : Bytes
    range_end : Bytes
    prev_kv : Bool
    } derive(Eq)

    A DeleteRangeRequest: delete the key at key, or the half-open range [key, range_end); prev_kv asks the server to return the deleted key/values. A discovery client sends this to deregister an instance.

    EtcdDeleteRangeRequest::decode

    Decode a DeleteRangeRequest.

    EtcdDeleteRangeRequest::encode

    Encode a DeleteRangeRequest (key=1, range_end=2, prev_kv=3).

    EtcdDeleteRangeRequest::equal

    EtcdDeleteRangeRequest::not_equal

    EtcdDeleteRangeResponse

    pub(all) struct EtcdDeleteRangeResponse {
    deleted : Int64
    prev_kvs : Array[EtcdKeyValue]
    } derive(Eq)

    A DeleteRangeResponse: the number of keys deleted and, when prev_kv was requested, the prev_kvs that were removed.

    EtcdDeleteRangeResponse::decode

    Decode a DeleteRangeResponse.

    EtcdDeleteRangeResponse::encode

    Encode a DeleteRangeResponse (deleted=2, prev_kvs=3 repeated).

    EtcdDeleteRangeResponse::equal

    EtcdDeleteRangeResponse::not_equal

    EtcdDiscovery

    pub struct EtcdDiscovery {
    client : EtcdClient
    prefix : String
    }

    An etcd-backed service registry / resolver. Instances of one service live under <prefix><service>/, so a Range over that prefix returns them all.

    EtcdDiscovery::deregister

    fn EtcdDiscovery::deregister(self : EtcdDiscovery, service : String) -> Unit raise

    Remove every instance of service (deregister the whole service prefix).

    EtcdDiscovery::new

    fn EtcdDiscovery::new(client : EtcdClient, prefix? : String) -> EtcdDiscovery

    An etcd discovery bound to client; keys live under prefix (default "moonzero/", mirroring go-zero's configurable discovery key root).

    EtcdDiscovery::register

    fn EtcdDiscovery::register(self : EtcdDiscovery, service : String, endpoint :
    Endpoint
    , ttl? : Int64) -> Int64 raise

    Register endpoint for service under a fresh lease living ttl seconds, and return the granted lease id (renew it with the client's keep-alive to stay registered). The instance key is <prefix><service>/<lease-id> and its value is the host:port dial string, so a resolver reads the endpoints straight back.

    EtcdDiscovery::resolve

    Resolve service to its live endpoints: Range the service prefix and parse each value as a host:port endpoint. Malformed values are skipped.

    EtcdDiscovery::resolver

    This etcd discovery as a Resolve interface value, so the balancer and the load-balanced channel written against Resolve run against real etcd unchanged. A resolve error surfaces as an empty endpoint set (the balancer's no-instance case), matching how the in-memory resolver behaves for an unknown service.

    EtcdEvent

    pub(all) struct EtcdEvent {
    event_type : EtcdEventType
    kv : EtcdKeyValue
    } derive(Eq)

    A watch Event (mvccpb.Event): a change to one key, carrying the resulting KeyValue (for a delete, the key with cleared metadata). This is what a discovery watcher folds into add/remove of a service instance.

    EtcdEvent::decode

    Decode an Event.

    EtcdEvent::encode

    fn EtcdEvent::encode(self : EtcdEvent) -> Bytes

    Encode an Event (type=1, kv=2). PUT (0) is the proto3 default and omitted.

    EtcdEvent::equal

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

    EtcdEvent::not_equal

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

    EtcdEventType

    pub(all) enum EtcdEventType {
    Put
    Delete
    } derive(Eq)

    The kind of change a watch Event reports (mvccpb.Event.EventType): a key was Put (created or updated) or Deleted.

    EtcdEventType::equal

    EtcdEventType::from_int

    fn EtcdEventType::from_int(n : Int) -> EtcdEventType

    The event type for a protobuf enum number; unknown numbers read as Put.

    EtcdEventType::not_equal

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

    EtcdEventType::to_int

    fn EtcdEventType::to_int(self : EtcdEventType) -> Int

    The protobuf enum number of an event type (PUT = 0, DELETE = 1).

    EtcdKeyValue

    pub(all) struct EtcdKeyValue {
    key : Bytes
    create_revision : Int64
    mod_revision : Int64
    version : Int64
    value : Bytes
    lease : Int64
    } derive(Eq)

    An etcd KeyValue (mvccpb.KeyValue): a key, its value, the create/mod revisions and version that track its history, and the lease it is attached to.

    EtcdKeyValue::decode

    Decode a KeyValue from protobuf wire bytes; unknown fields are skipped.

    EtcdKeyValue::empty

    fn EtcdKeyValue::empty() -> EtcdKeyValue

    The empty key/value with all-zero metadata.

    EtcdKeyValue::encode

    fn EtcdKeyValue::encode(self : EtcdKeyValue) -> Bytes

    Encode a KeyValue to its protobuf wire bytes (field numbers per etcd mvccpb.proto: key=1, create_revision=2, mod_revision=3, version=4, value=5, lease=6). Proto3 default (empty / zero) fields are omitted.

    EtcdKeyValue::equal

    EtcdKeyValue::not_equal

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

    EtcdLeaseGrantRequest

    pub(all) struct EtcdLeaseGrantRequest {
    ttl : Int64
    id : Int64
    } derive(Eq)

    A LeaseGrantRequest: ask etcd for a lease living ttl seconds (id 0 lets the server assign one). A registered service key attaches to the lease and vanishes when the lease expires — go-zero's instance liveness mechanism.

    EtcdLeaseGrantRequest::decode

    Decode a LeaseGrantRequest.

    EtcdLeaseGrantRequest::encode

    fn EtcdLeaseGrantRequest::encode(self : EtcdLeaseGrantRequest) -> Bytes

    Encode a LeaseGrantRequest (TTL=1, ID=2).

    EtcdLeaseGrantRequest::equal

    EtcdLeaseGrantRequest::not_equal

    EtcdLeaseGrantResponse

    pub(all) struct EtcdLeaseGrantResponse {
    id : Int64
    ttl : Int64
    error : String
    } derive(Eq)

    A LeaseGrantResponse: the granted lease id, its actual ttl, and an error string when the grant failed.

    EtcdLeaseGrantResponse::decode

    Decode a LeaseGrantResponse.

    EtcdLeaseGrantResponse::encode

    Encode a LeaseGrantResponse (ID=2, TTL=3, error=4).

    EtcdLeaseGrantResponse::equal

    EtcdLeaseGrantResponse::not_equal

    EtcdLeaseKeepAliveRequest

    pub(all) struct EtcdLeaseKeepAliveRequest {
    id : Int64
    } derive(Eq)

    A LeaseKeepAliveRequest: renew lease id before it expires. A discovery client streams these to keep its instance registered.

    EtcdLeaseKeepAliveRequest::decode

    Decode a LeaseKeepAliveRequest.

    EtcdLeaseKeepAliveRequest::encode

    Encode a LeaseKeepAliveRequest (ID=1).

    EtcdLeaseKeepAliveRequest::equal

    EtcdLeaseKeepAliveRequest::not_equal

    EtcdLeaseKeepAliveResponse

    pub(all) struct EtcdLeaseKeepAliveResponse {
    id : Int64
    ttl : Int64
    } derive(Eq)

    A LeaseKeepAliveResponse: the renewed lease id and its remaining ttl (0 = the lease has expired).

    EtcdLeaseKeepAliveResponse::decode

    Decode a LeaseKeepAliveResponse.

    EtcdLeaseKeepAliveResponse::encode

    Encode a LeaseKeepAliveResponse (ID=2, TTL=3).

    EtcdLeaseKeepAliveResponse::equal

    EtcdLeaseKeepAliveResponse::not_equal

    EtcdPutRequest

    pub(all) struct EtcdPutRequest {
    key : Bytes
    value : Bytes
    lease : Int64
    } derive(Eq)

    A PutRequest: store value at key, optionally under lease.

    EtcdPutRequest::decode

    Decode a PutRequest.

    EtcdPutRequest::encode

    fn EtcdPutRequest::encode(self : EtcdPutRequest) -> Bytes

    Encode a PutRequest (key=1, value=2, lease=3).

    EtcdPutRequest::equal

    EtcdPutRequest::not_equal

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

    EtcdPutResponse

    pub(all) struct EtcdPutResponse {
    prev_kv : EtcdKeyValue
    } derive(Eq)

    A PutResponse: when prev_kv was requested on the PutRequest, the key/value that the put replaced (its key is empty when there was none).

    EtcdPutResponse::decode

    Decode a PutResponse.

    EtcdPutResponse::encode

    fn EtcdPutResponse::encode(self : EtcdPutResponse) -> Bytes

    Encode a PutResponse (prev_kv=2); an absent previous value (empty key) is omitted.

    EtcdPutResponse::equal

    EtcdPutResponse::not_equal

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

    EtcdRangeRequest

    pub(all) struct EtcdRangeRequest {
    key : Bytes
    range_end : Bytes
    limit : Int64
    } derive(Eq)

    A RangeRequest (etcdserverpb): read the key at key, or the half-open range [key, range_end) when range_end is set, up to limit results (0 = no limit).

    EtcdRangeRequest::decode

    Decode a RangeRequest.

    EtcdRangeRequest::encode

    fn EtcdRangeRequest::encode(self : EtcdRangeRequest) -> Bytes

    Encode a RangeRequest (key=1, range_end=2, limit=3).

    EtcdRangeRequest::equal

    EtcdRangeRequest::not_equal

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

    EtcdRangeResponse

    pub(all) struct EtcdRangeResponse {
    kvs : Array[EtcdKeyValue]
    count : Int64
    } derive(Eq)

    A RangeResponse: the matched key/values and the total count in the range (which may exceed the returned kvs when a limit capped them).

    EtcdRangeResponse::decode

    Decode a RangeResponse; each kvs entry is a nested KeyValue message.

    EtcdRangeResponse::encode

    fn EtcdRangeResponse::encode(self : EtcdRangeResponse) -> Bytes

    Encode a RangeResponse (kvs=2 repeated, count=4).

    EtcdRangeResponse::equal

    EtcdRangeResponse::not_equal

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

    EtcdWatchCancelRequest

    pub(all) struct EtcdWatchCancelRequest {
    watch_id : Int64
    } derive(Eq)

    A WatchCancelRequest: stop the watch stream identified by watch_id.

    EtcdWatchCancelRequest::decode

    Decode a WatchCancelRequest.

    EtcdWatchCancelRequest::encode

    Encode a WatchCancelRequest (watch_id=1).

    EtcdWatchCancelRequest::equal

    EtcdWatchCancelRequest::not_equal

    EtcdWatchCreateRequest

    pub(all) struct EtcdWatchCreateRequest {
    key : Bytes
    range_end : Bytes
    start_revision : Int64
    } derive(Eq)

    A WatchCreateRequest: subscribe to changes on key, or on the half-open range [key, range_end), from start_revision (0 = current). A discovery watcher opens one over the service's key prefix.

    EtcdWatchCreateRequest::decode

    Decode a WatchCreateRequest.

    EtcdWatchCreateRequest::encode

    Encode a WatchCreateRequest (key=1, range_end=2, start_revision=3).

    EtcdWatchCreateRequest::equal

    EtcdWatchCreateRequest::not_equal

    EtcdWatchRequest

    pub(all) enum EtcdWatchRequest {
    Create(EtcdWatchCreateRequest)
    Cancel(EtcdWatchCancelRequest)
    } derive(Eq)

    A WatchRequest, the request_union oneof of the bidi Watch stream: either a Create to open a watch or a Cancel to close one.

    EtcdWatchRequest::decode

    Decode a WatchRequest; the last-set oneof arm wins, defaulting to an empty Create.

    EtcdWatchRequest::encode

    fn EtcdWatchRequest::encode(self : EtcdWatchRequest) -> Bytes

    Encode a WatchRequest (create_request=1, cancel_request=2).

    EtcdWatchRequest::equal

    EtcdWatchRequest::not_equal

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

    EtcdWatchResponse

    pub(all) struct EtcdWatchResponse {
    watch_id : Int64
    created : Bool
    canceled : Bool
    events : Array[EtcdEvent]
    } derive(Eq)

    A WatchResponse: the server-assigned watch_id, the created / canceled lifecycle flags, and the batch of change events since the last response. A discovery watcher folds each event into add/remove of a service instance.

    EtcdWatchResponse::decode

    Decode a WatchResponse.

    EtcdWatchResponse::encode

    fn EtcdWatchResponse::encode(self : EtcdWatchResponse) -> Bytes

    Encode a WatchResponse (watch_id=2, created=3, canceled=4, events=11 repeated).

    EtcdWatchResponse::equal

    EtcdWatchResponse::not_equal

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

    etcd_prefix_end

    fn etcd_prefix_end(prefix : Bytes) -> Bytes

    The etcd range-end for a prefix scan: the prefix with its last byte incremented, which is the smallest key greater than every key sharing the prefix (etcd's getPrefix). An all-0xff tail scans to the end of the keyspace (\x00).

    etcd_service_prefix

    fn etcd_service_prefix(prefix : String, service : String) -> String

    The key prefix a service's instances live under: <prefix><service>/. Exposed so the native gRPC-socket path builds the exact same keys as the in-process driver.