khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 1 | syntax = "proto3"; |
| 2 | package v3electionpb; |
| 3 | |
| 4 | import "gogoproto/gogo.proto"; |
| 5 | import "etcd/etcdserver/etcdserverpb/rpc.proto"; |
| 6 | import "etcd/mvcc/mvccpb/kv.proto"; |
| 7 | |
| 8 | // for grpc-gateway |
| 9 | import "google/api/annotations.proto"; |
| 10 | |
| 11 | option (gogoproto.marshaler_all) = true; |
| 12 | option (gogoproto.unmarshaler_all) = true; |
| 13 | |
| 14 | // The election service exposes client-side election facilities as a gRPC interface. |
| 15 | service Election { |
| 16 | // Campaign waits to acquire leadership in an election, returning a LeaderKey |
| 17 | // representing the leadership if successful. The LeaderKey can then be used |
| 18 | // to issue new values on the election, transactionally guard API requests on |
| 19 | // leadership still being held, and resign from the election. |
| 20 | rpc Campaign(CampaignRequest) returns (CampaignResponse) { |
| 21 | option (google.api.http) = { |
| 22 | post: "/v3/election/campaign" |
| 23 | body: "*" |
| 24 | }; |
| 25 | } |
| 26 | // Proclaim updates the leader's posted value with a new value. |
| 27 | rpc Proclaim(ProclaimRequest) returns (ProclaimResponse) { |
| 28 | option (google.api.http) = { |
| 29 | post: "/v3/election/proclaim" |
| 30 | body: "*" |
| 31 | }; |
| 32 | } |
| 33 | // Leader returns the current election proclamation, if any. |
| 34 | rpc Leader(LeaderRequest) returns (LeaderResponse) { |
| 35 | option (google.api.http) = { |
| 36 | post: "/v3/election/leader" |
| 37 | body: "*" |
| 38 | }; |
| 39 | } |
| 40 | // Observe streams election proclamations in-order as made by the election's |
| 41 | // elected leaders. |
| 42 | rpc Observe(LeaderRequest) returns (stream LeaderResponse) { |
| 43 | option (google.api.http) = { |
| 44 | post: "/v3/election/observe" |
| 45 | body: "*" |
| 46 | }; |
| 47 | } |
| 48 | // Resign releases election leadership so other campaigners may acquire |
| 49 | // leadership on the election. |
| 50 | rpc Resign(ResignRequest) returns (ResignResponse) { |
| 51 | option (google.api.http) = { |
| 52 | post: "/v3/election/resign" |
| 53 | body: "*" |
| 54 | }; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | message CampaignRequest { |
| 59 | // name is the election's identifier for the campaign. |
| 60 | bytes name = 1; |
| 61 | // lease is the ID of the lease attached to leadership of the election. If the |
| 62 | // lease expires or is revoked before resigning leadership, then the |
| 63 | // leadership is transferred to the next campaigner, if any. |
| 64 | int64 lease = 2; |
| 65 | // value is the initial proclaimed value set when the campaigner wins the |
| 66 | // election. |
| 67 | bytes value = 3; |
| 68 | } |
| 69 | |
| 70 | message CampaignResponse { |
| 71 | etcdserverpb.ResponseHeader header = 1; |
| 72 | // leader describes the resources used for holding leadereship of the election. |
| 73 | LeaderKey leader = 2; |
| 74 | } |
| 75 | |
| 76 | message LeaderKey { |
| 77 | // name is the election identifier that correponds to the leadership key. |
| 78 | bytes name = 1; |
| 79 | // key is an opaque key representing the ownership of the election. If the key |
| 80 | // is deleted, then leadership is lost. |
| 81 | bytes key = 2; |
| 82 | // rev is the creation revision of the key. It can be used to test for ownership |
| 83 | // of an election during transactions by testing the key's creation revision |
| 84 | // matches rev. |
| 85 | int64 rev = 3; |
| 86 | // lease is the lease ID of the election leader. |
| 87 | int64 lease = 4; |
| 88 | } |
| 89 | |
| 90 | message LeaderRequest { |
| 91 | // name is the election identifier for the leadership information. |
| 92 | bytes name = 1; |
| 93 | } |
| 94 | |
| 95 | message LeaderResponse { |
| 96 | etcdserverpb.ResponseHeader header = 1; |
| 97 | // kv is the key-value pair representing the latest leader update. |
| 98 | mvccpb.KeyValue kv = 2; |
| 99 | } |
| 100 | |
| 101 | message ResignRequest { |
| 102 | // leader is the leadership to relinquish by resignation. |
| 103 | LeaderKey leader = 1; |
| 104 | } |
| 105 | |
| 106 | message ResignResponse { |
| 107 | etcdserverpb.ResponseHeader header = 1; |
| 108 | } |
| 109 | |
| 110 | message ProclaimRequest { |
| 111 | // leader is the leadership hold on the election. |
| 112 | LeaderKey leader = 1; |
| 113 | // value is an update meant to overwrite the leader's current value. |
| 114 | bytes value = 2; |
| 115 | } |
| 116 | |
| 117 | message ProclaimResponse { |
| 118 | etcdserverpb.ResponseHeader header = 1; |
| 119 | } |